From 163e6239649dc6e03d6409f5971ac0f3017448c6 Mon Sep 17 00:00:00 2001 From: HENRY Florian Date: Wed, 7 Aug 2024 03:08:04 +0200 Subject: [PATCH 1/7] FIX: on change ref for bank account attachement are lost (#30529) * FIX: on change ref for bank account attachement are lost * FIX: on change ref for bank account attachement are lost * FIX: on change ref for bank account attachement are lost * Update card.php --------- Co-authored-by: Laurent Destailleur --- htdocs/compta/bank/card.php | 2 +- htdocs/compta/bank/class/account.class.php | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index a923f3a0829..102e6c5f697 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -80,7 +80,6 @@ if (GETPOST("id", 'int') || GETPOST("ref")) { $result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '', $fieldid); - /* * Actions */ @@ -222,6 +221,7 @@ if (empty($reshook)) { $object = new Account($db); $object->fetch(GETPOST("id", 'int')); + $object->oldref = $object->ref; $object->ref = dol_string_nospecial(trim(GETPOST('ref', 'alpha'))); $object->label = trim(GETPOST("label", 'alphanohtml')); $object->courant = GETPOST("type"); diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index dcf13e72e3b..bea28d9775b 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -266,6 +266,11 @@ class Account extends CommonObject */ public $ics_transfer; + /** + * @var string The previous ref in case of rename on update to rename attachment folders + */ + public $oldref; + /** @@ -897,6 +902,28 @@ class Account extends CommonObject } } + if (!$error && !empty($this->oldref) && $this->oldref !== $this->ref) { + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'bank/".$this->db->escape($this->ref)."'"; + $sql .= " WHERE filepath = 'bank/".$this->db->escape($this->oldref)."' and src_object_type='bank_account' and entity = ".((int) $conf->entity); + $resql = $this->db->query($sql); + if (!$resql) { + $error++; + $this->error = $this->db->lasterror(); + } + + // We rename directory in order not to lose the attachments + $oldref = dol_sanitizeFileName($this->oldref); + $newref = dol_sanitizeFileName($this->ref); + $dirsource = $conf->bank->dir_output.'/'.$oldref; + $dirdest = $conf->bank->dir_output.'/'.$newref; + if (file_exists($dirsource)) { + dol_syslog(get_class($this)."::update rename dir ".$dirsource." into ".$dirdest, LOG_DEBUG); + if (@rename($dirsource, $dirdest)) { + dol_syslog("Rename ok", LOG_DEBUG); + } + } + } + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('BANKACCOUNT_MODIFY', $user); From b235fa4f5ba03c9e4b8621cd157a629ca312fdd8 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 10 Aug 2024 23:07:51 +0200 Subject: [PATCH 2/7] FIX compatibility with MULTICOMPANY_TRANSVERSE_MODE (#30599) --- htdocs/core/multicompany_page.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/htdocs/core/multicompany_page.php b/htdocs/core/multicompany_page.php index dbd937a83cd..c4c9f8c7b0d 100644 --- a/htdocs/core/multicompany_page.php +++ b/htdocs/core/multicompany_page.php @@ -96,6 +96,10 @@ if (!isModEnabled('multicompany')) { $langs->load("admin"); $bookmarkList .= '
'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("MultiCompany")).''; $bookmarkList .= '

'; +} elseif (!empty($user->entity) && !getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) { // Should not be accessible if the option to centralize users on the main entity is not activated + $langs->load("errors"); + $bookmarkList .= '
'.$langs->trans("ErrorForbidden").''; + $bookmarkList .= '

'; } else { // Instantiate hooks of thirdparty module $hookmanager->initHooks(array('multicompany')); @@ -106,11 +110,15 @@ if (!isModEnabled('multicompany')) { if (is_object($mc)) { - $listofentities = $mc->getEntitiesList($user->login, false, true); + $listofentities = $mc->getEntitiesList(true, false, true); } $multicompanyList .= ''; - $searchForm .= ''; - - // Execute hook printBookmarks $parameters = array('multicompany'=>$multicompanyList); $reshook = $hookmanager->executeHooks('printMultiCompanyEntities', $parameters); // Note that $action and $object may have been modified by some hooks @@ -143,19 +137,18 @@ if (!isModEnabled('multicompany')) { } else { $multicompanyList = $hookmanager->resPrint; } - - - print "\n"; - print "\n"; - print '
'; - print ''; - print '
'."\n"; - print $multicompanyList; - print '
'."\n"; - print '
'; - print "\n\n"; } +print "\n"; +print "\n"; +print '
'; +print ''; +print '
'."\n"; +print $multicompanyList; +print '
'."\n"; +print '
'; +print "\n\n"; + print ''; print ''."\n";