From d7fad50f4ae634ed048148fdda96ea171fb72c8d Mon Sep 17 00:00:00 2001 From: evarisk-micka Date: Mon, 16 Oct 2023 16:13:32 +0200 Subject: [PATCH] #3407 [PP/FP] fix: fetch_lines for clone and DU send mail last document --- class/firepermit.class.php | 4 +--- class/preventionplan.class.php | 4 +--- .../digiriskstandard_riskassessmentdocument.php | 14 ++++++++------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/class/firepermit.class.php b/class/firepermit.class.php index f89252242..ae5e819f1 100644 --- a/class/firepermit.class.php +++ b/class/firepermit.class.php @@ -151,6 +151,7 @@ public function createFromClone(User $user, int $fromID, array $options): int // Load source object $object->fetch($fromID); + $firepermitdets = $object->lines; // Load signatory and ressources form source object $signatories = $signatory->fetchSignatory('', $fromID, $object->element); @@ -224,9 +225,6 @@ public function createFromClone(User $user, int $fromID, array $options): int } if (!empty($options['firepermit_risk'])) { - $firepermitdet = new PreventionPlanLine($this->db); - $firepermitdets = $firepermitdet->fetchAll('', '', 0, 0, ['fk_firepermit' => $fromID]); - if (is_array($firepermitdets) && !empty($firepermitdets)) { foreach ($firepermitdets as $line) { $line->ref = $refFirePermitDetMod->getNextValue($line); diff --git a/class/preventionplan.class.php b/class/preventionplan.class.php index dca75909e..6a83518c1 100644 --- a/class/preventionplan.class.php +++ b/class/preventionplan.class.php @@ -154,6 +154,7 @@ public function createFromClone(User $user, int $fromID, array $options): int // Load source object $object->fetch($fromID); + $preventionplandets = $object->lines; // Load signatory and ressources form source object $signatories = $signatory->fetchSignatory('', $fromID, $object->element); @@ -227,9 +228,6 @@ public function createFromClone(User $user, int $fromID, array $options): int } if (!empty($options['preventionplan_risk'])) { - $preventionplandet = new PreventionPlanLine($this->db); - $preventionplandets = $preventionplandet->fetchAll('', '', 0, 0, ['fk_preventionplan' => $fromID]); - if (is_array($preventionplandets) && !empty($preventionplandets)) { foreach ($preventionplandets as $line) { $line->ref = $refPreventionPlanDetMod->getNextValue($line); diff --git a/view/digiriskstandard/digiriskstandard_riskassessmentdocument.php b/view/digiriskstandard/digiriskstandard_riskassessmentdocument.php index 1a2a5cfa1..222f22e56 100644 --- a/view/digiriskstandard/digiriskstandard_riskassessmentdocument.php +++ b/view/digiriskstandard/digiriskstandard_riskassessmentdocument.php @@ -469,12 +469,14 @@ $object->fetch_projet(); - if (!in_array($object->element, array('societe', 'user', 'member'))) { - include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - $fileparams = dol_dir_list($diroutput, 'files', 0, ''); - $lastFileKey = is_array($fileparams) && !empty($fileparams) ? count($fileparams) - 2 : 0; - $filevalue[0] = $fileparams[$lastFileKey]['fullname'] ?? 0; - } + if (!in_array($object->element, array('societe', 'user', 'member'))) { + include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; + $fileparams = dol_dir_list($diroutput, 'files', 0, '', [], 'date', 'SORT_DESC'); + preg_match('#_(.*)_#U', $fileparams[0]['name'], $lastRef); + foreach ($fileparams as $fileparam) { + preg_match('/' . $lastRef[0] . '/', $fileparam['name']) ? $filevalue[] = $fileparam['fullname'] : 0; + } + } // Define output language $outputlangs = $langs;