From 45136de6645b1fa61ee6cc396e026164dcdff728 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 30 Aug 2017 11:26:48 +0200 Subject: [PATCH 1/3] Fix: documents dir not rename and delete --- htdocs/resource/class/dolresource.class.php | 290 +++++++++++--------- 1 file changed, 167 insertions(+), 123 deletions(-) diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index 6e418e2e649..1b1f4f7fd0b 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -43,6 +43,8 @@ class Dolresource extends CommonObject var $type_label; var $tms=''; + var $oldcopy; + /** * Constructor * @@ -230,85 +232,108 @@ class Dolresource extends CommonObject * @param int $notrigger 0=launch triggers after, 1=disable triggers * @return int <0 if KO, >0 if OK */ - function update($user=null, $notrigger=0) - { - global $conf, $langs, $hookmanager; - $error=0; + function update($user=null, $notrigger=0) + { + global $conf, $langs, $hookmanager; + $error=0; - // Clean parameters - if (isset($this->ref)) $this->ref=trim($this->ref); - if (isset($this->fk_code_type_resource)) $this->fk_code_type_resource=trim($this->fk_code_type_resource); - if (isset($this->description)) $this->description=trim($this->description); + // Clean parameters + if (isset($this->ref)) $this->ref=trim($this->ref); + if (isset($this->fk_code_type_resource)) $this->fk_code_type_resource=trim($this->fk_code_type_resource); + if (isset($this->description)) $this->description=trim($this->description); - // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; - $sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").","; - $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").","; - $sql.= " fk_code_type_resource=".(isset($this->fk_code_type_resource)?"'".$this->db->escape($this->fk_code_type_resource)."'":"null").","; - $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').""; - $sql.= " WHERE rowid=".$this->id; + if (empty($this->oldcopy)) + { + $org=new self($this->db); + $org->fetch($this->id); + $this->oldcopy=$org; + } - $this->db->begin(); + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").","; + $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").","; + $sql.= " fk_code_type_resource=".(isset($this->fk_code_type_resource)?"'".$this->db->escape($this->fk_code_type_resource)."'":"null").","; + $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').""; + $sql.= " WHERE rowid=".$this->id; - dol_syslog(get_class($this)."::update", LOG_DEBUG); - $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + $this->db->begin(); - if (! $error) - { - if (! $notrigger) - { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. + dol_syslog(get_class($this)."::update", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - //// Call triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('RESOURCE_MODIFY',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - //// End call triggers - } - } - if (! $error) - { - $action='update'; + if (! $error) + { + if (! $notrigger) + { + // Call trigger + $result=$this->call_trigger('RESOURCE_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + } - // Actions on extra fields (by external module or standard code) - // TODO le hook fait double emploi avec le trigger !! - $hookmanager->initHooks(array('actioncommdao')); - $parameters=array('actcomm'=>$this->id); - $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - if (empty($reshook)) - { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $result=$this->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } - } - else if ($reshook < 0) $error++; - } + if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) + { + // We remove directory + if (! empty($conf->resource->dir_output)) + { + $olddir = $conf->resource->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref); + $newdir = $conf->resource->dir_output . "/" . dol_sanitizeFileName($this->ref); + if (file_exists($olddir)) + { + $res = @rename($olddir, $newdir); + if (! $res) + { + $langs->load("errors"); + $this->error=$langs->trans('ErrorFailToRenameDir',$olddir,$newdir); + $error++; + } + } + } + } - // Commit or rollback - if ($error) - { - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } - $this->db->rollback(); - return -1*$error; - } - else - { - $this->db->commit(); - return 1; - } - } + if (! $error) + { + $action='update'; + + // Actions on extra fields (by external module or standard code) + // TODO le hook fait double emploi avec le trigger !! + $hookmanager->initHooks(array('actioncommdao')); + $parameters=array('actcomm'=>$this->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + else if ($reshook < 0) $error++; + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } /** * Load object in memory from database @@ -375,65 +400,84 @@ class Dolresource extends CommonObject * @param int $notrigger Disable all triggers * @return int >0 if OK, <0 if KO */ - function delete($rowid, $notrigger=0) - { - global $user,$langs,$conf; + function delete($rowid, $notrigger=0) + { + global $user,$langs,$conf; - $error=0; + $error=0; - $this->db->begin(); + $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " WHERE rowid =".$rowid; + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql.= " WHERE rowid =".$rowid; - dol_syslog(get_class($this), LOG_DEBUG); - if ($this->db->query($sql)) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; - $sql.= " WHERE element_type='resource' AND resource_id =".$this->db->escape($rowid); - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql=$this->db->query($sql); - if (!$resql) - { - $this->error=$this->db->lasterror(); - $error++; - } - } - else - { - $this->error=$this->db->lasterror(); - $error++; - } + dol_syslog(get_class($this), LOG_DEBUG); + if ($this->db->query($sql)) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; + $sql.= " WHERE element_type='resource' AND resource_id =".$this->db->escape($rowid); + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) + { + $this->error=$this->db->lasterror(); + $error++; + } + } + else + { + $this->error=$this->db->lasterror(); + $error++; + } - // Removed extrafields - if (! $error) { - $result=$this->deleteExtraFields(); - if ($result < 0) - { - $error++; - dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR); - } - } + // Removed extrafields + if (! $error) { + $result=$this->deleteExtraFields(); + if ($result < 0) + { + $error++; + dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR); + } + } - if (! $notrigger) - { - // Call trigger - $result=$this->call_trigger('RESOURCE_DELETE',$user); - if ($result < 0) $error++; - // End call triggers - } + if (! $notrigger) + { + // Call trigger + $result=$this->call_trigger('RESOURCE_DELETE',$user); + if ($result < 0) $error++; + // End call triggers + } - if (! $error) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -1; - } - } + if (! $error) + { + // We remove directory + $ref = dol_sanitizeFileName($this->ref); + if (! empty($conf->resource->dir_output)) + { + $dir = $conf->resource->dir_output . "/" . dol_sanitizeFileName($this->ref); + if (file_exists($dir)) + { + $res=@dol_delete_dir_recursive($dir); + if (! $res) + { + $this->errors[] = 'ErrorFailToDeleteDir'; + $error++; + } + } + } + } + + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } /** * Load resource objects into $this->lines From ac08dec2c356c0b1fe9a528b5f0290c54a0f4368 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 1 Sep 2017 15:20:29 +0200 Subject: [PATCH 2/3] Avoid warnings --- htdocs/compta/bank/index.php | 42 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/htdocs/compta/bank/index.php b/htdocs/compta/bank/index.php index 5f6e30016d4..3625d32cff7 100644 --- a/htdocs/compta/bank/index.php +++ b/htdocs/compta/bank/index.php @@ -57,7 +57,7 @@ $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -127,9 +127,9 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP $search_number=''; $search_statut=''; } - - - + + + /* * View */ @@ -299,9 +299,9 @@ if (! empty($arrayfields['toreconcile']['checked'])) print_liste_field_titr // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach($extrafields->attribute_label as $key => $val) + foreach($extrafields->attribute_label as $key => $val) { - if (! empty($arrayfields["ef.".$key]['checked'])) + if (! empty($arrayfields["ef.".$key]['checked'])) { $align=$extrafields->getAlignFlag($key); print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); @@ -435,7 +435,7 @@ $var=true; foreach ($accounts as $key=>$type) { if ($i >= $limit) break; - + $found++; $acc = new Account($db); @@ -452,7 +452,7 @@ foreach ($accounts as $key=>$type) { $lastcurrencycode=$acc->currency_code; } - + print ''; // Ref @@ -461,14 +461,14 @@ foreach ($accounts as $key=>$type) print ''.$acc->getNomUrl(1).''; if (! $i) $totalarray['nbfield']++; } - + // Label if (! empty($arrayfields['b.label']['checked'])) { print ''.$acc->label.''; if (! $i) $totalarray['nbfield']++; } - + // Account type if (! empty($arrayfields['accountype']['checked'])) { @@ -477,14 +477,14 @@ foreach ($accounts as $key=>$type) print ''; if (! $i) $totalarray['nbfield']++; } - + // Number if (! empty($arrayfields['b.number']['checked'])) { print ''.$acc->number.''; if (! $i) $totalarray['nbfield']++; } - + // Account number if (! empty($arrayfields['b.account_number']['checked'])) { @@ -492,7 +492,7 @@ foreach ($accounts as $key=>$type) print ''.length_accountg($acc->account_number).''; if (! $i) $totalarray['nbfield']++; } - + // Accountancy journal if (! empty($arrayfields['b.accountancy_journal']['checked'])) { @@ -500,7 +500,7 @@ foreach ($accounts as $key=>$type) print ''.length_accountg($acc->accountancy_journal).''; if (! $i) $totalarray['nbfield']++; } - + // Transactions to reconcile if (! empty($arrayfields['toreconcile']['checked'])) { @@ -519,13 +519,13 @@ foreach ($accounts as $key=>$type) print ''; if (! $i) $totalarray['nbfield']++; } - + // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach($extrafields->attribute_label as $key => $val) + foreach($extrafields->attribute_label as $key => $val) { - if (! empty($arrayfields["ef.".$key]['checked'])) + if (! empty($arrayfields["ef.".$key]['checked'])) { print 'getAlignFlag($key); @@ -558,14 +558,14 @@ foreach ($accounts as $key=>$type) print ''; if (! $i) $totalarray['nbfield']++; } - + // Statut if (! empty($arrayfields['b.clos']['checked'])) { print ''.$acc->getLibStatut(5).''; if (! $i) $totalarray['nbfield']++; } - + // Balance if (! empty($arrayfields['balance']['checked'])) { @@ -576,7 +576,7 @@ foreach ($accounts as $key=>$type) if (! $i) $totalarray['totalbalancefield']=$totalarray['nbfield']; $totalarray['totalbalance'] += $solde; } - + // Action column print ''; if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined @@ -587,7 +587,7 @@ foreach ($accounts as $key=>$type) } print ''; if (! $i) $totalarray['nbfield']++; - + print ''; $total[$acc->currency_code] += $solde; From f92129dcdb667eccb88f0657f912a31d061299a1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Sep 2017 00:55:49 +0200 Subject: [PATCH 3/3] Fix packager to avoid symlinks into custom --- build/makepack-dolibarr.pl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl index fdd14fcf5a2..a6f052efa82 100755 --- a/build/makepack-dolibarr.pl +++ b/build/makepack-dolibarr.pl @@ -594,7 +594,9 @@ if ($nboftargetok) { print "Remove subdir of custom dir\n"; print "find $BUILDROOT/$PROJECT/htdocs/custom/* -type d -exec rm -fr {} \\;\n"; - $ret=`find $BUILDROOT/$PROJECT/htdocs/custom/* -type d -exec rm -fr {} \\; >/dev/null 2>&1`; # For custom we want to keep dir + $ret=`find $BUILDROOT/$PROJECT/htdocs/custom/* -type d -exec rm -fr {} \\; >/dev/null 2>&1`; # For custom we want to keep files only + print "find $BUILDROOT/$PROJECT/htdocs/custom/* -type l -exec rm -fr {} \\;\n"; + $ret=`find $BUILDROOT/$PROJECT/htdocs/custom/* -type l -exec rm -fr {} \\; >/dev/null 2>&1`; # For custom we want to keep files only } # Build package for each target