From 25842b3295e49a474950bf6fa4c22f17208924da Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Thu, 2 Jul 2015 16:03:24 +0200 Subject: [PATCH 1/6] NEW add hook in send mail --- htdocs/core/class/CMailFile.class.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index ef6d27b59b1..65bdd28e3ee 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -366,13 +366,26 @@ class CMailFile */ function sendfile() { - global $conf; + global $conf,$db; $errorlevel=error_reporting(); error_reporting($errorlevel ^ E_WARNING); // Desactive warnings $res=false; + dol_include_once('/core/class/hookmanager.class.php'); + $hookmanager=new HookManager($db); + $hookmanager->initHooks(array('maildao')); + $reshook=$hookmanager->executeHooks('doactions',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (!empty($reshook)) + { + + $this->error="Error in hook maildao doactions ".$reshook; + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); + + return $reshook; + } + if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) { // Action according to choosed sending method From 1277596242a9317c29bf2b0967db32a247c96516 Mon Sep 17 00:00:00 2001 From: Alexis ALGOUD Date: Mon, 6 Jul 2015 00:51:17 +0200 Subject: [PATCH 2/6] Mode hook in $conf->global->MAIN_DISABLE_ALL_MAILS --- htdocs/core/class/CMailFile.class.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 65bdd28e3ee..2c58848fe4f 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -373,21 +373,22 @@ class CMailFile $res=false; - dol_include_once('/core/class/hookmanager.class.php'); - $hookmanager=new HookManager($db); - $hookmanager->initHooks(array('maildao')); - $reshook=$hookmanager->executeHooks('doactions',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - if (!empty($reshook)) - { - - $this->error="Error in hook maildao doactions ".$reshook; - dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); - - return $reshook; - } - if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) { + + dol_include_once('/core/class/hookmanager.class.php'); + $hookmanager=new HookManager($db); + $hookmanager->initHooks(array('maildao')); + $reshook=$hookmanager->executeHooks('doactions',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (!empty($reshook)) + { + + $this->error="Error in hook maildao doactions ".$reshook; + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); + + return $reshook; + } + // Action according to choosed sending method if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') { From 6b54180678e3e7b397a19ba19a3781c0c029267e Mon Sep 17 00:00:00 2001 From: All-3kcis Date: Wed, 8 Jul 2015 16:04:21 +0200 Subject: [PATCH 3/6] Fix #3158 can't change date in invoices --- htdocs/core/class/html.form.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index bad965192e5..19e313607ea 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3537,7 +3537,7 @@ class Form $ret.=''; $ret.=''; $ret.=''; $ret.=''; $ret.='
'; - $ret.=$this->select_date($selected,$htmlname,$displayhour,$displaymin,1,'form'.$htmlname); + $ret.=$this->select_date($selected,$htmlname,$displayhour,$displaymin,1,'form'.$htmlname,1,0,1); $ret.='
'; From 0b9ed9a25c458ede07f9f396bc214ba228d4a351 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 10 Jul 2015 09:37:05 +0200 Subject: [PATCH 4/6] Fix PSR2. We must not have spaces after ( --- dev/skeletons/skeleton_class.class.php | 103 ++++++++++++------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/dev/skeletons/skeleton_class.class.php b/dev/skeletons/skeleton_class.class.php index 21c1beda9a1..eef777a03ca 100644 --- a/dev/skeletons/skeleton_class.class.php +++ b/dev/skeletons/skeleton_class.class.php @@ -86,10 +86,9 @@ class Skeleton_Class extends CommonObject * * @param DoliDb $db Database handler */ - public function __construct( DoliDB $db ) + public function __construct(DoliDB $db) { $this->db = $db; - return 1; } @@ -101,18 +100,18 @@ class Skeleton_Class extends CommonObject * * @return int <0 if KO, Id of created object if OK */ - public function create( User $user, $notrigger = false ) + public function create(User $user, $notrigger = false) { - dol_syslog( __METHOD__, LOG_DEBUG ); + dol_syslog(__METHOD__, LOG_DEBUG); $error = 0; // Clean parameters - if (isset( $this->prop1 )) { - $this->prop1 = trim( $this->prop1 ); + if (isset($this->prop1)) { + $this->prop1 = trim($this->prop1); } - if (isset( $this->prop2 )) { - $this->prop2 = trim( $this->prop2 ); + if (isset($this->prop2)) { + $this->prop2 = trim($this->prop2); } //... @@ -132,15 +131,15 @@ class Skeleton_Class extends CommonObject $this->db->begin(); - $resql = $this->db->query( $sql ); + $resql = $this->db->query($sql); if (!$resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog( __METHOD__ . ' ' . join( ',', $this->errors ), LOG_ERR ); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } if (!$error) { - $this->id = $this->db->last_insert_id( MAIN_DB_PREFIX . $this->table_element ); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you @@ -173,9 +172,9 @@ class Skeleton_Class extends CommonObject * * @return int <0 if KO, 0 if not found, >0 if OK */ - public function fetch( $id, $ref = null ) + public function fetch($id, $ref = null) { - dol_syslog( __METHOD__, LOG_DEBUG ); + dol_syslog(__METHOD__, LOG_DEBUG); $sql = 'SELECT'; $sql .= ' t.rowid,'; @@ -189,18 +188,18 @@ class Skeleton_Class extends CommonObject $sql .= ' WHERE t.rowid = ' . $id; } - $resql = $this->db->query( $sql ); + $resql = $this->db->query($sql); if ($resql) { - $numrows = $this->db->num_rows( $resql ); + $numrows = $this->db->num_rows($resql); if ($numrows) { - $obj = $this->db->fetch_object( $resql ); + $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; $this->prop1 = $obj->field1; $this->prop2 = $obj->field2; //... } - $this->db->free( $resql ); + $this->db->free($resql); if ($numrows) { return 1; @@ -209,7 +208,7 @@ class Skeleton_Class extends CommonObject } } else { $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog( __METHOD__ . ' ' . join( ',', $this->errors ), LOG_ERR ); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); return - 1; } @@ -226,9 +225,9 @@ class Skeleton_Class extends CommonObject * * @return int <0 if KO, >0 if OK */ - public function fetchAll( $sortorder, $sortfield, $limit, $offset, array $filter = array() ) + public function fetchAll($sortorder, $sortfield, $limit, $offset, array $filter = array()) { - dol_syslog( __METHOD__, LOG_DEBUG ); + dol_syslog(__METHOD__, LOG_DEBUG); $sql = 'SELECT'; $sql .= ' t.rowid,'; @@ -239,23 +238,23 @@ class Skeleton_Class extends CommonObject // Manage filter $sqlwhere = array(); - if (count( $filter ) > 0) { + if (count($filter) > 0) { foreach ($filter as $key => $value) { - $sqlwhere [] = ' AND ' . $key . ' LIKE \'%' . $this->db->escape( $value ) . '%\''; + $sqlwhere [] = ' AND ' . $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; } } - if (count( $sqlwhere ) > 0) { - $sql .= ' WHERE ' . implode( ' AND ', $sqlwhere ); + if (count($sqlwhere) > 0) { + $sql .= ' WHERE ' . implode(' AND ', $sqlwhere); } - $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder . ' ' . $this->db->plimit( $limit + 1, $offset ); + $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder . ' ' . $this->db->plimit($limit + 1, $offset); $this->lines = array(); - $resql = $this->db->query( $sql ); + $resql = $this->db->query($sql); if ($resql) { - $num = $this->db->num_rows( $resql ); + $num = $this->db->num_rows($resql); - while ($obj = $this->db->fetch_object( $resql )) { + while ($obj = $this->db->fetch_object($resql)) { $line = new Skeleton_ClassLine(); $line->id = $obj->rowid; @@ -265,12 +264,12 @@ class Skeleton_Class extends CommonObject $this->lines[] = $line; //... } - $this->db->free( $resql ); + $this->db->free($resql); return $num; } else { $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog( __METHOD__ . ' ' . join( ',', $this->errors ), LOG_ERR ); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); return - 1; } @@ -284,18 +283,18 @@ class Skeleton_Class extends CommonObject * * @return int <0 if KO, >0 if OK */ - public function update( User $user, $notrigger = false ) + public function update(User $user, $notrigger = false) { $error = 0; - dol_syslog( __METHOD__, LOG_DEBUG ); + dol_syslog(__METHOD__, LOG_DEBUG); // Clean parameters - if (isset( $this->prop1 )) { - $this->prop1 = trim( $this->prop1 ); + if (isset($this->prop1)) { + $this->prop1 = trim($this->prop1); } - if (isset( $this->prop2 )) { - $this->prop2 = trim( $this->prop2 ); + if (isset($this->prop2)) { + $this->prop2 = trim($this->prop2); } //... @@ -304,13 +303,13 @@ class Skeleton_Class extends CommonObject // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; - if (isset( $this->field1 )) { - $sql .= ' field1=\'' . $this->db->escape( $this->field1 ) . '\','; + if (isset($this->field1)) { + $sql .= ' field1=\'' . $this->db->escape($this->field1) . '\','; } else { $sql .= ' field1=null' . ','; } - if (isset( $this->field2 )) { - $sql .= ' field2=\'' . $this->db->escape( $this->field2 ) . '\''; + if (isset($this->field2)) { + $sql .= ' field2=\'' . $this->db->escape($this->field2) . '\''; } else { $sql .= ' field2=null'; } @@ -319,11 +318,11 @@ class Skeleton_Class extends CommonObject $this->db->begin(); - $resql = $this->db->query( $sql ); + $resql = $this->db->query($sql); if (!$resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog( __METHOD__ . ' ' . join( ',', $this->errors ), LOG_ERR ); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } if (!$error && !$notrigger) { @@ -356,9 +355,9 @@ class Skeleton_Class extends CommonObject * * @return int <0 if KO, >0 if OK */ - public function delete( User $user, $notrigger = false ) + public function delete(User $user, $notrigger = false) { - dol_syslog( __METHOD__, LOG_DEBUG ); + dol_syslog(__METHOD__, LOG_DEBUG); $error = 0; @@ -380,11 +379,11 @@ class Skeleton_Class extends CommonObject $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; $sql .= ' WHERE rowid=' . $this->id; - $resql = $this->db->query( $sql ); + $resql = $this->db->query($sql); if (!$resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog( __METHOD__ . ' ' . join( ',', $this->errors ), LOG_ERR ); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } @@ -407,18 +406,18 @@ class Skeleton_Class extends CommonObject * * @return int New id of clone */ - public function createFromClone( $fromid ) + public function createFromClone($fromid) { - dol_syslog( __METHOD__, LOG_DEBUG ); + dol_syslog(__METHOD__, LOG_DEBUG); global $user; $error = 0; - $object = new Skeleton_Class( $this->db ); + $object = new Skeleton_Class($this->db); $this->db->begin(); // Load source object - $object->fetch( $fromid ); + $object->fetch($fromid); // Reset object $object->id = 0; @@ -426,13 +425,13 @@ class Skeleton_Class extends CommonObject // ... // Create clone - $result = $object->create( $user ); + $result = $object->create($user); // Other options if ($result < 0) { $error ++; $this->errors = $object->errors; - dol_syslog( __METHOD__ . ' ' . join( ',', $this->errors ), LOG_ERR ); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } // End From 688562a816dba37f312075195c901a0b32680a7a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 10 Jul 2015 09:40:18 +0200 Subject: [PATCH 5/6] Fix regression: We can't yet set method __construct of DolibarrModules abstract because this break compatibility with a lot of external module and generate FATAL errors after migration. Because PHP is not yet able to manage try catch on FATAL error, we can't catch such error. Using bstract on constructor is so postponed. --- htdocs/core/lib/admin.lib.php | 12 ++++++------ htdocs/core/modules/DolibarrModules.class.php | 7 +++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 05204885c9c..2eb0fbb77ba 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -837,13 +837,13 @@ function unActivateModule($value, $requiredby=1) } else { - // TODO Cannot instantiate abstract class - //$genericMod = new DolibarrModul($db); - //$genericMod->name=preg_replace('/^mod/i','',$modName); - //$genericMod->rights_class=strtolower(preg_replace('/^mod/i','',$modName)); - //$genericMod->const_name='MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i','',$modName)); + // TODO Replace this afte DolibarrModules is moved as abstract class with a try catch to show module is bugged + $genericMod = new DolibarrModules($db); + $genericMod->name=preg_replace('/^mod/i','',$modName); + $genericMod->rights_class=strtolower(preg_replace('/^mod/i','',$modName)); + $genericMod->const_name='MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i','',$modName)); dol_syslog("modules::unActivateModule Failed to find module file, we use generic function with name " . $modName); - //$genericMod->_remove(); + $genericMod->_remove(); } // Desactivation des modules qui dependent de lui diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index eee8dd50287..e759bf9454a 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -199,8 +199,11 @@ abstract class DolibarrModules * * @param DoliDB $db Database handler */ - abstract public function __construct($db); - + //public function __construct($db); + // We should but can't set this as abstract because this will make dolibarr hang + // after migration due to old module not implementing. We must wait PHP is able to make + // a try catch on Fatal error to manage this correctly. + /** * Enables a module. * Inserts all informations into database From f4cc1f647c4a74683479020cac555eadbd52bcde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 10 Jul 2015 15:20:41 +0200 Subject: [PATCH 6/6] Fix #3183 Make sure FormOther class is included. --- htdocs/core/lib/usergroups.lib.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/core/lib/usergroups.lib.php b/htdocs/core/lib/usergroups.lib.php index 3dceff31009..5dc17962e14 100644 --- a/htdocs/core/lib/usergroups.lib.php +++ b/htdocs/core/lib/usergroups.lib.php @@ -257,6 +257,8 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) global $conf,$langs,$db; global $bc; + require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; + $formother = new FormOther($db); //$dirthemes=array(empty($conf->global->MAIN_FORCETHEMEDIR)?'/theme':$conf->global->MAIN_FORCETHEMEDIR.'/theme');