Merge branch '18.0' of git@github.com:Dolibarr/dolibarr.git into 19.0

This commit is contained in:
Laurent Destailleur 2024-08-12 21:42:42 +02:00
commit 7023061cd8
3 changed files with 29 additions and 2 deletions

View File

@ -82,7 +82,6 @@ if (GETPOST("id", 'int') || GETPOST("ref")) {
$result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '', $fieldid);
/*
* Actions
*/
@ -238,6 +237,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");

View File

@ -278,6 +278,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;
/**
* 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
@ -921,6 +926,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);

View File

@ -2609,7 +2609,7 @@ class Product extends CommonObject
$this->fk_default_bom = $obj->fk_default_bom;
$this->duration = $obj->duration;
$this->duration_value = $obj->duration ? substr($obj->duration, 0, dol_strlen($obj->duration) - 1) : null;
$this->duration_value = $obj->duration ? (int) (substr($obj->duration, 0, dol_strlen($obj->duration) - 1)) : 0;
$this->duration_unit = $obj->duration ? substr($obj->duration, -1) : null;
$this->canvas = $obj->canvas;
$this->net_measure = $obj->net_measure;