Skip to content

Commit

Permalink
Merge branch '17.0' of [email protected]:Dolibarr/dolibarr.git into 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Aug 12, 2024
2 parents 0295c43 + 163e623 commit 892d9cc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion htdocs/compta/bank/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@

$result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '', $fieldid);


/*
* Actions
*/
Expand Down Expand Up @@ -236,6 +235,7 @@
$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");
Expand Down
27 changes: 27 additions & 0 deletions htdocs/compta/bank/class/account.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,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;



/**
Expand Down Expand Up @@ -920,6 +925,28 @@ public function update(User $user, $notrigger = 0)
}
}

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);
Expand Down

0 comments on commit 892d9cc

Please sign in to comment.