From 2967c2357e003927337b367636ab5c6e841bfb09 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 20 Mar 2012 11:59:18 +0100 Subject: [PATCH 01/27] Fix: compatibility with multicompany --- htdocs/categories/categorie.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php index 1a159d03257..7304b441e25 100644 --- a/htdocs/categories/categorie.php +++ b/htdocs/categories/categorie.php @@ -65,6 +65,7 @@ if ($id || $ref) $elementtype = 'societe'; $objecttype = 'societe&categorie'; $objectid = isset($id)?$id:(isset($socid)?$socid:''); + $dbtablename = '&societe'; $fieldid = 'rowid'; } if ($type == 3) { From 82cff13b66d0680ea351fbda29276fe5ccfad757 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 20 Mar 2012 12:26:02 +0100 Subject: [PATCH 02/27] Fix: missing type of category --- htdocs/categories/categorie.php | 20 +++++++++++--------- htdocs/categories/index.php | 17 +++++++++-------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php index 7304b441e25..e6d334965c4 100644 --- a/htdocs/categories/categorie.php +++ b/htdocs/categories/categorie.php @@ -1,7 +1,7 @@ * Copyright (C) 2005 Brice Davoleau - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2006-2011 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2010 Juanjo Menent @@ -38,6 +38,8 @@ $ref = GETPOST('ref'); $type = GETPOST('type'); $mesg = GETPOST('mesg'); +$removecat = GETPOST('removecat','int'); + $dbtablename = ''; @@ -87,7 +89,7 @@ $result = restrictedArea($user,$objecttype,$objectid,$dbtablename,'','',$fieldid */ //Suppression d'un objet d'une categorie -if ($_REQUEST["removecat"]) +if ($removecat > 0) { if ($type==0 && ($user->rights->produit->creer || $user->rights->service->creer)) { @@ -113,7 +115,7 @@ if ($_REQUEST["removecat"]) $result = $object->fetch($objectid); } $cat = new Categorie($db); - $result=$cat->fetch($_REQUEST["removecat"]); + $result=$cat->fetch($removecat); $result=$cat->del_type($object,$elementtype); } @@ -270,11 +272,11 @@ if ($socid) dol_htmloutput_mesg($mesg); - if ($soc->client) formCategory($db,$soc,2); + if ($soc->client) formCategory($db,$soc,2,$socid); if ($soc->client && $soc->fournisseur) print '

'; - if ($soc->fournisseur) formCategory($db,$soc,1); + if ($soc->fournisseur) formCategory($db,$soc,1,$socid); } else if ($id || $ref) { @@ -424,7 +426,7 @@ else if ($id || $ref) * @param int $typeid Type of category (0, 1, 2, 3) * @return int 0 */ -function formCategory($db,$object,$typeid) +function formCategory($db,$object,$typeid,$socid=0) { global $user,$langs,$form,$bc; @@ -499,7 +501,7 @@ function formCategory($db,$object,$typeid) if ($typeid == 3) $permission=$user->rights->adherent->creer; if ($permission) { - print ""; + print ""; print img_delete($langs->trans("DeleteFromCat")).' '; print $langs->trans("DeleteFromCat").""; } @@ -530,7 +532,7 @@ function formCategory($db,$object,$typeid) return 0; } -$db->close(); llxFooter(); -?> +$db->close(); +?> \ No newline at end of file diff --git a/htdocs/categories/index.php b/htdocs/categories/index.php index 8dc601e996f..de8d727c657 100644 --- a/htdocs/categories/index.php +++ b/htdocs/categories/index.php @@ -3,7 +3,7 @@ * Copyright (C) 2005 Eric Seigne * Copyright (C) 2006-2011 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,12 +29,13 @@ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/treeview.lib.php"); -$type=(GETPOST('type') ? GETPOST('type') : 0); - -if (!$user->rights->categorie->lire) accessforbidden(); - $langs->load("categories"); +if (! $user->rights->categorie->lire) accessforbidden(); + +$id=GETPOST('id','int'); +$type=(GETPOST('type') ? GETPOST('type') : 0); + /* * View @@ -88,9 +89,9 @@ print ''; /* * Categories found */ -if($_POST['catname'] || $_REQUEST['id']) +if($_POST['catname'] || $id > 0) { - $cats = $categstatic->rechercher($_REQUEST['id'],$_POST['catname'],$_POST['type']); + $cats = $categstatic->rechercher($id,$_POST['catname'],$type); print ''; print ''; @@ -309,7 +310,7 @@ if ($nbofentries == 0) print "
'.$langs->trans("FoundCats").'
"; -$db->close(); llxFooter(); +$db->close(); ?> From 46909442165ef11b3f9b2da45f04b458584e08f1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 20 Mar 2012 12:46:57 +0100 Subject: [PATCH 03/27] checkstyle --- htdocs/commande/class/commande.class.php | 2 +- htdocs/core/class/ldap.class.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 0f80894cb2b..8c4a8b6f06e 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2111,7 +2111,7 @@ class Commande extends CommonObject * @param double $pu Prix unitaire * @param double $qty Quantity * @param double $remise_percent Pourcentage de remise de la ligne - * @param double $tva_tx Taux TVA + * @param double $txtva Taux TVA * @param double $txlocaltax1 Local tax 1 rate * @param double $txlocaltax2 Local tax 2 rate * @param string $price_base_type HT or TTC diff --git a/htdocs/core/class/ldap.class.php b/htdocs/core/class/ldap.class.php index 3598497a3a9..8ed2d0cbbb6 100644 --- a/htdocs/core/class/ldap.class.php +++ b/htdocs/core/class/ldap.class.php @@ -1011,8 +1011,8 @@ class Ldap * Converts a little-endian hex-number to one, that 'hexdec' can convert * Required by Active Directory * - * @param string $hex - * @return string little endian + * @param string $hex Hex value + * @return string Little endian */ function littleEndian($hex) { From 845fe9512879367f1c437ed97897312ff9991980 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 20 Mar 2012 13:51:50 +0100 Subject: [PATCH 04/27] Return specific code for duplicate --- htdocs/categories/class/categorie.class.php | 5 +++-- test/phpunit/CategorieTest.php | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 7a7cc186a6d..fe00cf3a4cf 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -125,6 +125,7 @@ class Categorie * @return int -1 : erreur SQL * -2 : nouvel ID inconnu * -3 : categorie invalide + * -4 : category already exists */ function create($user='') { @@ -141,7 +142,7 @@ class Categorie { $this->error=$langs->trans("ImpossibleAddCat"); $this->error.=" : ".$langs->trans("CategoryExistsAtSameLevel"); - return -1; + return -4; } $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label, description,"; @@ -176,7 +177,7 @@ class Categorie if($this->add_fille() < 0) { $this->error=$langs->trans("ImpossibleAssociateCategory"); - return -1; + return -3; } } diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index 24693fdac20..f87a2c29d44 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -129,12 +129,16 @@ class CategorieTest extends PHPUnit_Framework_TestCase $localobject=new Categorie($this->savdb); $localobject->initAsSpecimen(); - $result=$localobject->create($user); + // We create category + $result=$localobject->create($user); $this->assertLessThan($result, 0); print __METHOD__." result=".$result."\n"; - // TODO Add test on error when creating duplicate + // We try to create same category again + $result=$localobject->create($user); + $this->assertLessThan($result, -4); + print __METHOD__." result=".$result."\n"; return $result; From b7af14393c8b7457ec0b61c5a1956142751b6e99 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 20 Mar 2012 14:42:43 +0100 Subject: [PATCH 05/27] Fix: for multicompany category sharing --- htdocs/categories/class/categorie.class.php | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 7a7cc186a6d..12dadebdd27 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2005 Matthieu Valleton * Copyright (C) 2005 Davoleau Brice * Copyright (C) 2005 Rodolphe Quiedeville - * Copyright (C) 2006-2011 Regis Houssin + * Copyright (C) 2006-2012 Regis Houssin * Copyright (C) 2006-2012 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin * @@ -589,11 +589,11 @@ class Categorie */ function get_desc($cate) { - $sql = "SELECT description FROM ".MAIN_DB_PREFIX."categorie "; - $sql .= "WHERE rowid = ".$cate; + $sql = "SELECT description FROM ".MAIN_DB_PREFIX."categorie"; + $sql.= " WHERE rowid = ".$cate; - $res = $this->db->query($sql); - $n = $this->db->fetch_array($res); + $res = $this->db->query($sql); + $n = $this->db->fetch_array($res); return($n[0]); } @@ -632,8 +632,6 @@ class Categorie */ function get_full_arbo($type,$markafterid=0) { - global $conf; - $this->cats = array(); // Charge tableau des meres @@ -641,7 +639,7 @@ class Categorie $sql.= " FROM ".MAIN_DB_PREFIX."categorie_association ca"; $sql.= ", ".MAIN_DB_PREFIX."categorie as c"; $sql.= " WHERE ca.fk_categorie_mere = c.rowid"; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('category',1).")"; // Load array this->motherof dol_syslog("Categorie::get_full_arbo build motherof array sql=".$sql, LOG_DEBUG); @@ -665,7 +663,7 @@ class Categorie $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_association as ca"; $sql.= " ON c.rowid = ca.fk_categorie_mere"; $sql.= " WHERE c.type = ".$type; - $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('category',1).")"; $sql.= " ORDER BY c.label, c.rowid"; dol_syslog("Categorie::get_full_arbo get category list sql=".$sql, LOG_DEBUG); @@ -811,6 +809,7 @@ class Categorie function get_all_categories () { $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie"; + $sql.= " WHERE entity IN (".getEntity('category',1).")"; $res = $this->db->query($sql); if ($res) @@ -839,6 +838,7 @@ class Categorie { $sql = "SELECT count(rowid)"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; + $sql.= " WHERE entity IN (".getEntity('category',1).")"; $res = $this->db->query($sql); if ($res) { @@ -870,6 +870,7 @@ class Categorie $sql.= " ON c.rowid=ca.fk_categorie_fille"; $sql.= " WHERE ca.fk_categorie_mere=".$this->id_mere; $sql.= " AND c.label='".$this->db->escape($this->label)."'"; + $sql.= " AND c.entity IN (".getEntity('category',1).")"; } else // mother_id undefined (so it's root) { @@ -883,6 +884,7 @@ class Categorie $sql.= " ON c.rowid!=ca.fk_categorie_fille"; $sql.= " WHERE c.type=".$this->type; $sql.= " AND c.label='".$this->db->escape($this->label)."'"; + $sql.= " AND c.entity IN (".getEntity('category',1).")"; } dol_syslog("Categorie::already_exists sql=".$sql); $resql = $this->db->query($sql); @@ -1101,6 +1103,7 @@ class Categorie $sql.= " FROM ".MAIN_DB_PREFIX."categorie_".$type." as ct"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON ct.fk_categorie = c.rowid"; $sql.= " WHERE ct.fk_".$table." = ".$id." AND c.type = ".$typeid; + $sql.= " AND c.entity IN (".getEntity('category',1).")"; $res = $this->db->query($sql); if ($res) @@ -1135,8 +1138,9 @@ class Categorie $cats = array (); // Generation requete recherche - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie "; - $sql .= "WHERE type = ".$type." "; + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie"; + $sql.= " WHERE type = ".$type." "; + $sql.= " AND entity IN (".getEntity('category',1).")"; if ($nom) { if (! $exact) From ea65c45b2cb87031c67768b713542881ee624801 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 20 Mar 2012 15:14:37 +0100 Subject: [PATCH 06/27] Fix: backward compatibility --- htdocs/core/class/conf.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index dbff136ff30..7c96afd2303 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -237,6 +237,7 @@ class Conf // For backward compatibility // TODO Replace this->xxx->enabled by this->modulename->enabled to remove this code if (isset($this->propale->enabled)) $this->propal->enabled=$this->propale->enabled; + if (isset($this->categorie->enabled)) $this->category->enabled=$this->categorie->enabled; // Define default dir_output and dir_temp for directories of modules foreach($this->modules as $module) From e02fe135db0fc071b16fac0c6a595fbab218de59 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 20 Mar 2012 15:28:21 +0100 Subject: [PATCH 07/27] Fix: instantiate $mc object at the end --- htdocs/core/class/conf.class.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 7c96afd2303..4ca4aff34e9 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -185,19 +185,7 @@ class Conf } $i++; } - - // Object $mc - if (! defined('NOREQUIREMC') && ! empty($this->multicompany->enabled)) - { - global $mc; - - $ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php'); - if ($ret) - { - $mc = new ActionsMulticompany($db); - $mc->setValues($this); - } - } + $db->free($resql); } //var_dump($this->modules); @@ -388,6 +376,19 @@ class Conf // For backward compatibility if ($this->top_menu == 'eldy.php') $this->top_menu='eldy_backoffice.php'; elseif ($this->top_menu == 'rodolphe.php') $this->top_menu='eldy_backoffice.php'; + + // Object $mc + if (! defined('NOREQUIREMC') && ! empty($this->multicompany->enabled)) + { + global $mc; + + $ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php'); + if ($ret) + { + $mc = new ActionsMulticompany($db); + $mc->setValues($this); + } + } } } From b83026f8832757e3183e047c654642e5574458d1 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 20 Mar 2012 22:45:15 +0800 Subject: [PATCH 08/27] Fix: for multicompany category sharing --- htdocs/categories/edit.php | 4 ++-- htdocs/categories/photos.php | 4 ++-- htdocs/categories/viewcat.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index ca82944a32a..015b964d452 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -1,7 +1,7 @@ * Copyright (C) 2006-2010 Laurent Destailleur - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2007 Patrick Raguin * * This program is free software; you can redistribute it and/or modify @@ -41,7 +41,7 @@ if ($id == "") } // Security check -$result = restrictedArea($user, 'categorie', $id); +$result = restrictedArea($user, 'categorie', $id, '&category'); diff --git a/htdocs/categories/photos.php b/htdocs/categories/photos.php index 747d2c92a5b..7730347f286 100644 --- a/htdocs/categories/photos.php +++ b/htdocs/categories/photos.php @@ -2,7 +2,7 @@ /* Copyright (C) 2001-2007 Rodolphe Quiedeville * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005 Eric Seigne - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,7 +48,7 @@ if ($id == "") } // Security check -$result = restrictedArea($user, 'categorie', $id); +$result = restrictedArea($user, 'categorie', $id, '&category'); $object = new Categorie($db); diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 5efa8c9ecec..bcf8fd65675 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -2,7 +2,7 @@ /* Copyright (C) 2005 Matthieu Valleton * Copyright (C) 2006-2010 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -44,7 +44,7 @@ if ($id == "") } // Security check -$result = restrictedArea($user, 'categorie', $id); +$result = restrictedArea($user, 'categorie', $id, '&category'); $object = new Categorie($db); $result=$object->fetch($id); From 6d7aba45de6c247f8d56387d768f63bf45e0db01 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 20 Mar 2012 17:03:10 +0100 Subject: [PATCH 09/27] Regenerate password is disbaled for disabled users --- htdocs/user/fiche.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index f8f6489903c..bac58616bce 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -1222,7 +1222,7 @@ else /* - * Barre d'actions + * Buttons actions */ print '
'; @@ -1247,13 +1247,21 @@ else // Si on a un gestionnaire de generation de mot de passe actif if ($conf->global->USER_PASSWORD_GENERATED != 'none') { - if (($user->id != $id && $caneditpassword) && $fuser->login && !$fuser->ldap_sid && + if ($fuser->statut == 0) + { + print ''.$langs->trans("ReinitPassword").''; + } + elseif (($user->id != $id && $caneditpassword) && $fuser->login && !$fuser->ldap_sid && (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1))) { print ''.$langs->trans("ReinitPassword").''; } - if (($user->id != $id && $caneditpassword) && $fuser->login && !$fuser->ldap_sid && + if ($fuser->statut == 0) + { + print ''.$langs->trans("SendNewPassword").''; + } + else if (($user->id != $id && $caneditpassword) && $fuser->login && !$fuser->ldap_sid && (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)) ) { if ($fuser->email) print ''.$langs->trans("SendNewPassword").''; From c0013a4581bda18b9f87efccec07a542b3065fde Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 20 Mar 2012 17:18:20 +0100 Subject: [PATCH 10/27] Fix: When using a disabled user, web service must be forbidden --- htdocs/core/lib/ws.lib.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/htdocs/core/lib/ws.lib.php b/htdocs/core/lib/ws.lib.php index 7145f0c2aff..babe8609f6b 100755 --- a/htdocs/core/lib/ws.lib.php +++ b/htdocs/core/lib/ws.lib.php @@ -65,6 +65,12 @@ function check_authentication($authentication,&$error,&$errorcode,&$errorlabel) $errorcode='BAD_CREDENTIALS'; $errorlabel='Bad value for login or password'; } + if (! $error && $fuser->statut == 0) + { + $error++; + $errorcode='ERROR_USER_DISABLED'; $errorlabel='This user has been locked or disabled'; + } + // Validation of login if (! $error) { From 52a8216e3ebe8870341e531736b23b3ac7543a8f Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 02:12:44 +0100 Subject: [PATCH 11/27] Fix: avoid php E_STRICT errors and compatibility with php 5.4 --- htdocs/core/class/conf.class.php | 46 ++++++++++++++++--- htdocs/core/db/mysqli.class.php | 11 +++-- htdocs/core/lib/functions.lib.php | 4 +- htdocs/core/modules/DolibarrModules.class.php | 2 +- htdocs/install/etape1.php | 4 +- htdocs/install/inc.php | 11 ++++- 6 files changed, 59 insertions(+), 19 deletions(-) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 4ca4aff34e9..c0d6d3883cb 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -91,6 +91,9 @@ class Conf $this->mycompany=(object) array(); $this->admin=(object) array(); $this->user=(object) array(); + $this->syslog=(object) array(); + $this->browser=(object) array(); + $this->multicompany=(object) array(); //! Charset for HTML output and for storing data in memory $this->file->character_set_client='UTF-8'; // UTF-8, ISO-8859-1 } @@ -250,21 +253,29 @@ class Conf // for backward compatibility. // Sous module bons d'expedition - $this->expedition_bon->enabled=defined("MAIN_SUBMODULE_EXPEDITION")?MAIN_SUBMODULE_EXPEDITION:0; + $this->expedition_bon = (object) array(); + $this->expedition_bon->enabled= defined("MAIN_SUBMODULE_EXPEDITION")?MAIN_SUBMODULE_EXPEDITION:0; // Sous module bons de livraison + $this->livraison_bon = (object) array(); $this->livraison_bon->enabled=defined("MAIN_SUBMODULE_LIVRAISON")?MAIN_SUBMODULE_LIVRAISON:0; // Module fournisseur + $this->fournisseur = (object) array(); + $this->fournisseur->commande = (object) array(); $this->fournisseur->commande->dir_output=$rootfordata."/fournisseur/commande"; $this->fournisseur->commande->dir_temp =$rootfordata."/fournisseur/commande/temp"; + $this->fournisseur->facture = (object) array(); $this->fournisseur->facture->dir_output =$rootfordata."/fournisseur/facture"; $this->fournisseur->facture->dir_temp =$rootfordata."/fournisseur/facture/temp"; // Module product/service + $this->product = (object) array(); $this->product->dir_output=$rootfordata."/produit"; $this->product->dir_temp =$rootfordata."/produit/temp"; + $this->service = (object) array(); $this->service->dir_output=$rootfordata."/produit"; $this->service->dir_temp =$rootfordata."/produit/temp"; // Module contrat + $this->contrat = (object) array(); $this->contrat->dir_output=$rootfordata."/contracts"; $this->contrat->dir_temp =$rootfordata."/contracts/temp"; @@ -311,10 +322,12 @@ class Conf if (! empty($this->global->MAIN_MAIL_EMAIL_FROM)) $this->email_from = $this->global->MAIN_MAIL_EMAIL_FROM; // conf->notification->email_from = email pour envoi par Dolibarr des notifications + $this->notification = (object) array(); $this->notification->email_from=$this->email_from; if (! empty($this->global->NOTIFICATION_EMAIL_FROM)) $this->notification->email_from=$this->global->NOTIFICATION_EMAIL_FROM; // conf->mailing->email_from = email pour envoi par Dolibarr des mailings + $this->mailing = (object) array(); $this->mailing->email_from=$this->email_from; if (! empty($this->global->MAILING_EMAIL_FROM)) $this->mailing->email_from=$this->global->MAILING_EMAIL_FROM; @@ -345,17 +358,36 @@ class Conf if (empty($this->global->TAX_MODE_BUY_SERVICE)) $this->global->TAX_MODE_BUY_SERVICE='payment'; // Delay before warnings + $this->actions = (object) array(); $this->actions->warning_delay=(isset($this->global->MAIN_DELAY_ACTIONS_TODO)?$this->global->MAIN_DELAY_ACTIONS_TODO:7)*24*60*60; + $this->commande = (object) array(); + $this->commande->client = (object) array(); $this->commande->client->warning_delay=(isset($this->global->MAIN_DELAY_ORDERS_TO_PROCESS)?$this->global->MAIN_DELAY_ORDERS_TO_PROCESS:2)*24*60*60; - $this->commande->fournisseur->warning_delay=(isset($this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS)?$this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS:7)*24*60*60; - $this->propal->cloture->warning_delay=(isset($this->global->MAIN_DELAY_PROPALS_TO_CLOSE)?$this->global->MAIN_DELAY_PROPALS_TO_CLOSE:0)*24*60*60; - $this->propal->facturation->warning_delay=(isset($this->global->MAIN_DELAY_PROPALS_TO_BILL)?$this->global->MAIN_DELAY_PROPALS_TO_BILL:0)*24*60*60; + $this->commande->fournisseur = (object) array(); + $this->commande->fournisseur->warning_delay=(isset($this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS)?$this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS:7)*24*60*60; + $this->propal = (object) array(); + $this->propal->cloture = (object) array(); + $this->propal->cloture->warning_delay=(isset($this->global->MAIN_DELAY_PROPALS_TO_CLOSE)?$this->global->MAIN_DELAY_PROPALS_TO_CLOSE:0)*24*60*60; + $this->propal->facturation = (object) array(); + $this->propal->facturation->warning_delay=(isset($this->global->MAIN_DELAY_PROPALS_TO_BILL)?$this->global->MAIN_DELAY_PROPALS_TO_BILL:0)*24*60*60; + $this->facture = (object) array(); + $this->facture->client = (object) array(); $this->facture->client->warning_delay=(isset($this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED)?$this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED:0)*24*60*60; - $this->facture->fournisseur->warning_delay=(isset($this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY)?$this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY:0)*24*60*60; - $this->contrat->services->inactifs->warning_delay=(isset($this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES)?$this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES:0)*24*60*60; - $this->contrat->services->expires->warning_delay=(isset($this->global->MAIN_DELAY_RUNNING_SERVICES)?$this->global->MAIN_DELAY_RUNNING_SERVICES:0)*24*60*60; + $this->facture->fournisseur = (object) array(); + $this->facture->fournisseur->warning_delay=(isset($this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY)?$this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY:0)*24*60*60; + $this->contrat = (object) array(); + $this->contrat->services = (object) array(); + $this->contrat->services->inactifs = (object) array(); + $this->contrat->services->inactifs->warning_delay=(isset($this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES)?$this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES:0)*24*60*60; + $this->contrat->services->expires = (object) array(); + $this->contrat->services->expires->warning_delay=(isset($this->global->MAIN_DELAY_RUNNING_SERVICES)?$this->global->MAIN_DELAY_RUNNING_SERVICES:0)*24*60*60; + $this->adherent = (object) array(); + $this->adherent->cotisation = (object) array(); $this->adherent->cotisation->warning_delay=(isset($this->global->MAIN_DELAY_MEMBERS)?$this->global->MAIN_DELAY_MEMBERS:0)*24*60*60; + $this->bank = (object) array(); + $this->bank->rappro = (object) array(); $this->bank->rappro->warning_delay=(isset($this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE)?$this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE:0)*24*60*60; + $this->bank->cheque = (object) array(); $this->bank->cheque->warning_delay=(isset($this->global->MAIN_DELAY_CHEQUES_TO_DEPOSIT)?$this->global->MAIN_DELAY_CHEQUES_TO_DEPOSIT:0)*24*60*60; // For backward compatibility diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 55cf0168bf4..ed3bf3c6268 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -83,9 +83,10 @@ class DoliDBMysqli function DoliDBMysqli($type, $host, $user, $pass, $name='', $port=0) { global $conf,$langs; - - if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set; - if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation; + + // TODO error in strict mode (static property for "$forcecharset" and "$forcecollate") + //if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set; + //if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation; $this->database_user=$user; @@ -142,7 +143,7 @@ class DoliDBMysqli $clientmustbe=''; if (preg_match('/UTF-8/i',$conf->file->character_set_client)) $clientmustbe='utf8'; if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) $clientmustbe='latin1'; - if (mysqli_client_encoding($this->db) != $clientmustbe) + if (mysqli_character_set_name($this->db) != $clientmustbe) { $this->query("SET NAMES '".$clientmustbe."'", $this->db); //$this->query("SET CHARACTER SET ". $this->forcecharset); @@ -168,7 +169,7 @@ class DoliDBMysqli $clientmustbe=''; if (preg_match('/UTF-8/i',$conf->file->character_set_client)) $clientmustbe='utf8'; if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) $clientmustbe='latin1'; - if (mysqli_client_encoding($this->db) != $clientmustbe) + if (mysqli_character_set_name($this->db) != $clientmustbe) { $this->query("SET NAMES '".$clientmustbe."'", $this->db); //$this->query("SET CHARACTER SET ". $this->forcecharset); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 59d6adf5771..5bdbc3ad554 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1101,8 +1101,8 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1) function dol_now($mode='gmt') { // Note that gmmktime and mktime return same value (GMT) whithout parameters - if ($mode == 'gmt') $ret=gmmktime(); // Time for now at greenwich. - else if ($mode == 'tzserver') // Time for now with PHP server timezone added + if ($mode == 'gmt') $ret=time(); // Time for now at greenwich. + else if ($mode == 'tzserver') // Time for now with PHP server timezone added { require_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'); $tzsecond=getServerTimeZoneInt(); // Contains tz+dayling saving time diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 5d60c70c4e6..9fcb2a89f69 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -373,7 +373,7 @@ abstract class DolibarrModules $sql.= $this->numero; $sql.= ", ".$conf->entity; $sql.= ", 1"; - $sql.= ", '".$this->db->idate(gmmktime())."'"; + $sql.= ", '".$this->db->idate(dol_now())."'"; $sql.= ", '".$this->version."'"; $sql.= ")"; diff --git a/htdocs/install/etape1.php b/htdocs/install/etape1.php index 96292a89b52..b57b0e8a1c3 100644 --- a/htdocs/install/etape1.php +++ b/htdocs/install/etape1.php @@ -236,8 +236,8 @@ if (! $error && $db->connected) { if (! empty($_POST["db_create_database"])) // If we create database, we force default value { - $defaultCharacterSet=$db->forcecharset; - $defaultCollationConnection=$db->forcecollate; + $defaultCharacterSet=getStaticMember(get_class($db),'forcecharset'); + $defaultCollationConnection=getStaticMember(get_class($db),'forcecollate'); } else // If already created, we take current value { diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index 8dd1b140d6c..3ee0e363d1a 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -43,6 +43,13 @@ require_once(ADODB_PATH.'adodb-time.inc.php'); error_reporting(E_ALL); // To have all errors without disabled E_STRICT +// IMPORTANT with strict mode E_STRICT +$conf = new stdClass(); // instantiate $conf explicitely +$conf->global = (object) array(); +$conf->file = (object) array(); +$conf->db = (object) array(); +$conf->syslog = (object) array(); + // Define $_REQUEST["logtohtml"] $_REQUEST["logtohtml"]=1; @@ -134,7 +141,7 @@ if (! defined('DONOTLOADCONF') && file_exists($conffile)) $includeconferror='ErrorBadFormatForConfFile'; } } -$conf->global->MAIN_LOGTOHTML=1; +$conf->global->MAIN_LOGTOHTML = 1; // Define prefix if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_main_db_prefix='llx_'; @@ -222,7 +229,7 @@ if (! defined('SYSLOG_FILE')) // To avoid warning on systems with constant alrea if (! defined('SYSLOG_FILE_NO_ERROR')) define('SYSLOG_FILE_NO_ERROR',1); // Removed magic_quotes -if (function_exists('get_magic_quotes_gpc')) // magic_quotes_* removed in PHP6 +if (function_exists('get_magic_quotes_gpc')) // magic_quotes_* removed in PHP 5.4 { if (get_magic_quotes_gpc()) { From aae57a9f98544f000951dad290020b28329bea41 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 02:24:09 +0100 Subject: [PATCH 12/27] Fix: remove deprecated method --- htdocs/admin/system/database.php | 2 +- htdocs/admin/system/index.php | 2 +- htdocs/core/db/mysqli.class.php | 10 ---------- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/htdocs/admin/system/database.php b/htdocs/admin/system/database.php index 395011ee2b9..8231d9c2e90 100644 --- a/htdocs/admin/system/database.php +++ b/htdocs/admin/system/database.php @@ -44,7 +44,7 @@ print_fiche_titre($langs->trans("DatabaseConfiguration"),'','setup'); // Database print ''; print ''."\n"; -print ''."\n"; +print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; diff --git a/htdocs/admin/system/index.php b/htdocs/admin/system/index.php index 0ce5fb86190..5c11f595f94 100644 --- a/htdocs/admin/system/index.php +++ b/htdocs/admin/system/index.php @@ -86,7 +86,7 @@ print "
\n"; // Database print '
'.$langs->trans("Database").'
'.$langs->trans("Version").''.$db->getLabel().' '.$db->getVersion().'
'.$langs->trans("Version").''.getStaticMember(get_class($db),'label').' '.$db->getVersion().'
'.$langs->trans("DatabaseServer").''.$conf->db->host.'
'.$langs->trans("DatabasePort").''.(empty($conf->db->port)?$langs->trans("Default"):$conf->db->port).'
'.$langs->trans("DatabaseName").''.$conf->db->name.'
'; print "\n"; -$dblabel=$db->getLabel(); +$dblabel=getStaticMember(get_class($db),'label'); $dbversion=$db->getVersion(); print "\n"; print '
".$langs->trans("Database")."
".$langs->trans("Version")."" .$dblabel." ".$dbversion."
'; diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index ed3bf3c6268..3fbda6c3613 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -233,16 +233,6 @@ class DoliDBMysqli return $this->db; } - /** - * Return label of manager - * - * @return string Label - */ - function getLabel() - { - return $this->label; - } - /** * Return version of database server * From 22c232f82dca7b9bf47f80250e4afd7480479ce7 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 08:33:36 +0100 Subject: [PATCH 13/27] Fix: move phpunit in first and stop if failure --- quickbuild.xml | 2 +- test/phpunit/jenkins_phpunittest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/quickbuild.xml b/quickbuild.xml index 09bed28b867..7378a201028 100644 --- a/quickbuild.xml +++ b/quickbuild.xml @@ -88,5 +88,5 @@ - + \ No newline at end of file diff --git a/test/phpunit/jenkins_phpunittest.xml b/test/phpunit/jenkins_phpunittest.xml index 81aa2c40dad..8c9b93179f8 100644 --- a/test/phpunit/jenkins_phpunittest.xml +++ b/test/phpunit/jenkins_phpunittest.xml @@ -8,7 +8,7 @@ convertWarningsToExceptions="true" colors="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" syntaxCheck="true"> From 95aa484e44066ff4eb243beb117692f70993663b Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 08:53:49 +0100 Subject: [PATCH 14/27] Fix: move in constructor --- htdocs/core/class/conf.class.php | 78 ++++++++++++++++---------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index c0d6d3883cb..cca1ce2e0ad 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -85,15 +85,46 @@ class Conf function Conf() { // Avoid warnings when filling this->xxx - $this->file=(object) array(); - $this->db=(object) array(); - $this->global=(object) array(); - $this->mycompany=(object) array(); - $this->admin=(object) array(); - $this->user=(object) array(); - $this->syslog=(object) array(); - $this->browser=(object) array(); - $this->multicompany=(object) array(); + $this->file = (object) array(); + $this->db = (object) array(); + $this->global = (object) array(); + $this->mycompany = (object) array(); + $this->admin = (object) array(); + $this->user = (object) array(); + $this->syslog = (object) array(); + $this->browser = (object) array(); + $this->multicompany = (object) array(); + + $this->expedition_bon = (object) array(); + $this->livraison_bon = (object) array(); + $this->fournisseur = (object) array(); + $this->fournisseur->commande = (object) array(); + $this->fournisseur->facture = (object) array(); + $this->product = (object) array(); + $this->service = (object) array(); + $this->contrat = (object) array(); + $this->actions = (object) array(); + $this->commande = (object) array(); + $this->commande->client = (object) array(); + $this->commande->fournisseur = (object) array(); + $this->propal = (object) array(); + $this->propal->cloture = (object) array(); + $this->propal->facturation = (object) array(); + $this->facture = (object) array(); + $this->facture->client = (object) array(); + $this->facture->fournisseur = (object) array(); + $this->contrat = (object) array(); + $this->contrat->services = (object) array(); + $this->contrat->services->inactifs = (object) array(); + $this->contrat->services->expires = (object) array(); + $this->adherent = (object) array(); + $this->adherent->cotisation = (object) array(); + $this->bank = (object) array(); + $this->bank->rappro = (object) array(); + $this->bank->cheque = (object) array(); + $this->notification = (object) array(); + $this->mailing = (object) array(); + //! Charset for HTML output and for storing data in memory $this->file->character_set_client='UTF-8'; // UTF-8, ISO-8859-1 } @@ -253,29 +284,21 @@ class Conf // for backward compatibility. // Sous module bons d'expedition - $this->expedition_bon = (object) array(); $this->expedition_bon->enabled= defined("MAIN_SUBMODULE_EXPEDITION")?MAIN_SUBMODULE_EXPEDITION:0; // Sous module bons de livraison - $this->livraison_bon = (object) array(); $this->livraison_bon->enabled=defined("MAIN_SUBMODULE_LIVRAISON")?MAIN_SUBMODULE_LIVRAISON:0; // Module fournisseur - $this->fournisseur = (object) array(); - $this->fournisseur->commande = (object) array(); $this->fournisseur->commande->dir_output=$rootfordata."/fournisseur/commande"; $this->fournisseur->commande->dir_temp =$rootfordata."/fournisseur/commande/temp"; - $this->fournisseur->facture = (object) array(); $this->fournisseur->facture->dir_output =$rootfordata."/fournisseur/facture"; $this->fournisseur->facture->dir_temp =$rootfordata."/fournisseur/facture/temp"; // Module product/service - $this->product = (object) array(); $this->product->dir_output=$rootfordata."/produit"; $this->product->dir_temp =$rootfordata."/produit/temp"; - $this->service = (object) array(); $this->service->dir_output=$rootfordata."/produit"; $this->service->dir_temp =$rootfordata."/produit/temp"; // Module contrat - $this->contrat = (object) array(); $this->contrat->dir_output=$rootfordata."/contracts"; $this->contrat->dir_temp =$rootfordata."/contracts/temp"; @@ -322,12 +345,10 @@ class Conf if (! empty($this->global->MAIN_MAIL_EMAIL_FROM)) $this->email_from = $this->global->MAIN_MAIL_EMAIL_FROM; // conf->notification->email_from = email pour envoi par Dolibarr des notifications - $this->notification = (object) array(); $this->notification->email_from=$this->email_from; if (! empty($this->global->NOTIFICATION_EMAIL_FROM)) $this->notification->email_from=$this->global->NOTIFICATION_EMAIL_FROM; // conf->mailing->email_from = email pour envoi par Dolibarr des mailings - $this->mailing = (object) array(); $this->mailing->email_from=$this->email_from; if (! empty($this->global->MAILING_EMAIL_FROM)) $this->mailing->email_from=$this->global->MAILING_EMAIL_FROM; @@ -358,36 +379,17 @@ class Conf if (empty($this->global->TAX_MODE_BUY_SERVICE)) $this->global->TAX_MODE_BUY_SERVICE='payment'; // Delay before warnings - $this->actions = (object) array(); $this->actions->warning_delay=(isset($this->global->MAIN_DELAY_ACTIONS_TODO)?$this->global->MAIN_DELAY_ACTIONS_TODO:7)*24*60*60; - $this->commande = (object) array(); - $this->commande->client = (object) array(); $this->commande->client->warning_delay=(isset($this->global->MAIN_DELAY_ORDERS_TO_PROCESS)?$this->global->MAIN_DELAY_ORDERS_TO_PROCESS:2)*24*60*60; - $this->commande->fournisseur = (object) array(); $this->commande->fournisseur->warning_delay=(isset($this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS)?$this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS:7)*24*60*60; - $this->propal = (object) array(); - $this->propal->cloture = (object) array(); $this->propal->cloture->warning_delay=(isset($this->global->MAIN_DELAY_PROPALS_TO_CLOSE)?$this->global->MAIN_DELAY_PROPALS_TO_CLOSE:0)*24*60*60; - $this->propal->facturation = (object) array(); $this->propal->facturation->warning_delay=(isset($this->global->MAIN_DELAY_PROPALS_TO_BILL)?$this->global->MAIN_DELAY_PROPALS_TO_BILL:0)*24*60*60; - $this->facture = (object) array(); - $this->facture->client = (object) array(); $this->facture->client->warning_delay=(isset($this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED)?$this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED:0)*24*60*60; - $this->facture->fournisseur = (object) array(); $this->facture->fournisseur->warning_delay=(isset($this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY)?$this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY:0)*24*60*60; - $this->contrat = (object) array(); - $this->contrat->services = (object) array(); - $this->contrat->services->inactifs = (object) array(); $this->contrat->services->inactifs->warning_delay=(isset($this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES)?$this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES:0)*24*60*60; - $this->contrat->services->expires = (object) array(); $this->contrat->services->expires->warning_delay=(isset($this->global->MAIN_DELAY_RUNNING_SERVICES)?$this->global->MAIN_DELAY_RUNNING_SERVICES:0)*24*60*60; - $this->adherent = (object) array(); - $this->adherent->cotisation = (object) array(); $this->adherent->cotisation->warning_delay=(isset($this->global->MAIN_DELAY_MEMBERS)?$this->global->MAIN_DELAY_MEMBERS:0)*24*60*60; - $this->bank = (object) array(); - $this->bank->rappro = (object) array(); $this->bank->rappro->warning_delay=(isset($this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE)?$this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE:0)*24*60*60; - $this->bank->cheque = (object) array(); $this->bank->cheque->warning_delay=(isset($this->global->MAIN_DELAY_CHEQUES_TO_DEPOSIT)?$this->global->MAIN_DELAY_CHEQUES_TO_DEPOSIT:0)*24*60*60; // For backward compatibility From 2341e6c881d68137bf30748f1f5c48d2a208c5f4 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 09:47:55 +0100 Subject: [PATCH 15/27] Fix: add log for debug phpunit error --- htdocs/categories/class/categorie.class.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 7f604659625..7b1297199f0 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -887,7 +887,7 @@ class Categorie $sql.= " AND c.label='".$this->db->escape($this->label)."'"; $sql.= " AND c.entity IN (".getEntity('category',1).")"; } - dol_syslog("Categorie::already_exists sql=".$sql); + dol_syslog(get_class($this)."::already_exists sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { @@ -899,13 +899,19 @@ class Categorie * So if the result have the same id, update is not for label, and if result have an other one, * update may be for label. */ - if($obj[0] > 0 && $obj[0] != $this->id) return 1; + if($obj[0] > 0 && $obj[0] != $this->id) + { + dol_syslog(get_class($this)."::already_exists category with name=".$this->label." exist id=".$obj[0], LOG_DEBUG); + return 1; + } } + dol_syslog(get_class($this)."::already_exists no category with same name=".$this->label, LOG_DEBUG); return 0; } else { - dol_print_error($this->db); + $this->error=$this->db->error(); + dol_syslog(get_class($this)."::already_exists error ".$this->error." sql=".$sql, LOG_ERR); return -1; } } From 1aa71803ce90829dd39f54536c2ab8c61557481a Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 10:08:49 +0100 Subject: [PATCH 16/27] Fix: add begin/commit/rollback --- htdocs/categories/class/categorie.class.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 7b1297199f0..84ce256308e 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -144,6 +144,8 @@ class Categorie $this->error.=" : ".$langs->trans("CategoryExistsAtSameLevel"); return -4; } + + $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label, description,"; if ($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) @@ -177,6 +179,7 @@ class Categorie if($this->add_fille() < 0) { $this->error=$langs->trans("ImpossibleAssociateCategory"); + $this->db->rollback(); return -3; } } @@ -187,17 +190,21 @@ class Categorie $result=$interface->run_triggers('CATEGORY_CREATE',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers - + + $this->db->commit(); return $id; } else { + $this->db->rollback(); return -2; } } else { - dol_print_error($this->db); + $this->error=$this->db->error(); + dol_syslog(get_class($this)."::create error ".$this->error." sql=".$sql, LOG_ERR); + $this->db->rollback(); return -1; } } From e62424294a50bfc2a7fbbe1f5f03987196e03e7b Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 10:19:52 +0100 Subject: [PATCH 17/27] Fix: test if equals for stop on failure --- test/phpunit/CategorieTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index f87a2c29d44..908681d6fea 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -137,7 +137,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase // We try to create same category again $result=$localobject->create($user); - $this->assertLessThan($result, -4); + $this->assertEquals($result, -4); print __METHOD__." result=".$result."\n"; From 5dbb246db0092cdfa7ba272353628d5849d7d94c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 10:28:31 +0100 Subject: [PATCH 18/27] Fix: the expected value is the first parameter --- test/phpunit/CategorieTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index 908681d6fea..ae9aa31b9c7 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -132,12 +132,12 @@ class CategorieTest extends PHPUnit_Framework_TestCase // We create category $result=$localobject->create($user); - $this->assertLessThan($result, 0); + $this->assertLessThan(0, $result); print __METHOD__." result=".$result."\n"; // We try to create same category again $result=$localobject->create($user); - $this->assertEquals($result, -4); + $this->assertEquals(-4, $result); print __METHOD__." result=".$result."\n"; @@ -168,7 +168,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase $catid=$localobjecttmp->create($user); print __METHOD__." catid=".$catid."\n"; - $this->assertLessThanOrEqual($catid, 0); + $this->assertLessThanOrEqual(0, $catid); // Category $localobject2=new Product($this->savdb); @@ -179,7 +179,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase $result=$localobject2->create($user); print __METHOD__." result=".$result."\n"; - $this->assertLessThanOrEqual($result, 0); + $this->assertLessThanOrEqual(0, $result); return $id; } @@ -204,7 +204,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase $localobject=new Categorie($this->savdb); $result=$localobject->fetch($id); - $this->assertLessThan($result, 0); + $this->assertLessThan(0, $result); print __METHOD__." id=".$id." result=".$result."\n"; return $localobject; } @@ -230,7 +230,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase $result=$localobject->update($user); print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $this->assertLessThan(0, $result); return $localobject; } @@ -291,7 +291,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase $result=$localobject->delete($id); print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $this->assertLessThan(0, $result); return $result; } From 67345494360a8f3b7e012ea28c237bab6be0f2c3 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 10:38:13 +0100 Subject: [PATCH 19/27] Fix: use good function with good parameters --- test/phpunit/CategorieTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index ae9aa31b9c7..bdc362efe31 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -132,7 +132,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase // We create category $result=$localobject->create($user); - $this->assertLessThan(0, $result); + $this->assertGreaterThan(0, $result); print __METHOD__." result=".$result."\n"; // We try to create same category again @@ -168,7 +168,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase $catid=$localobjecttmp->create($user); print __METHOD__." catid=".$catid."\n"; - $this->assertLessThanOrEqual(0, $catid); + $this->assertGreaterThan(0, $catid); // Category $localobject2=new Product($this->savdb); @@ -179,7 +179,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase $result=$localobject2->create($user); print __METHOD__." result=".$result."\n"; - $this->assertLessThanOrEqual(0, $result); + $this->assertGreaterThan(0, $result); return $id; } @@ -204,7 +204,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase $localobject=new Categorie($this->savdb); $result=$localobject->fetch($id); - $this->assertLessThan(0, $result); + $this->assertGreaterThan(0, $result); print __METHOD__." id=".$id." result=".$result."\n"; return $localobject; } @@ -230,7 +230,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase $result=$localobject->update($user); print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan(0, $result); + $this->assertGreaterThan(0, $result); return $localobject; } @@ -291,7 +291,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase $result=$localobject->delete($id); print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan(0, $result); + $this->assertGreaterThan(0, $result); return $result; } From 7508974cbb49825186933cbd5941b1ecd70153dd Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 10:45:50 +0100 Subject: [PATCH 20/27] Fix: print log before the test --- test/phpunit/CategorieTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index bdc362efe31..cb2e7bc2388 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -132,13 +132,13 @@ class CategorieTest extends PHPUnit_Framework_TestCase // We create category $result=$localobject->create($user); - $this->assertGreaterThan(0, $result); print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); // We try to create same category again $result=$localobject->create($user); - $this->assertEquals(-4, $result); print __METHOD__." result=".$result."\n"; + $this->assertEquals(-4, $result); return $result; @@ -203,9 +203,9 @@ class CategorieTest extends PHPUnit_Framework_TestCase $localobject=new Categorie($this->savdb); $result=$localobject->fetch($id); - - $this->assertGreaterThan(0, $result); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertGreaterThan(0, $result); return $localobject; } From 0f3f822e3dc7dd8919d4b4afe2d1568c4e120207 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 11:06:53 +0100 Subject: [PATCH 21/27] Fix: add test --- test/phpunit/CategorieTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index cb2e7bc2388..26ddd4bdfd5 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -133,6 +133,11 @@ class CategorieTest extends PHPUnit_Framework_TestCase // We create category $result=$localobject->create($user); print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); + + // We check if exist + $result=$localobject->already_exists(); + print __METHOD__." result=".$result."\n"; $this->assertGreaterThan(0, $result); // We try to create same category again From 33bf32073fb218952d52b68cd3d665b7fa66c1ab Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 11:17:52 +0100 Subject: [PATCH 22/27] Fix: add more debug log --- htdocs/categories/class/categorie.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 84ce256308e..2a8e52e7cad 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -908,11 +908,11 @@ class Categorie */ if($obj[0] > 0 && $obj[0] != $this->id) { - dol_syslog(get_class($this)."::already_exists category with name=".$this->label." exist id=".$obj[0], LOG_DEBUG); + dol_syslog(get_class($this)."::already_exists category with name=".$this->label." exist rowid=".$obj[0]." current_id=".$this->id, LOG_DEBUG); return 1; } } - dol_syslog(get_class($this)."::already_exists no category with same name=".$this->label, LOG_DEBUG); + dol_syslog(get_class($this)."::already_exists no category with same name=".$this->label." rowid=".$obj[0]." current_id=".$this->id, LOG_DEBUG); return 0; } else From 0432609502a2067dff32ee465ce4bac009d094fe Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 11:24:30 +0100 Subject: [PATCH 23/27] Fix: unset $this->id for good check test --- test/phpunit/CategorieTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index 26ddd4bdfd5..b974e6f57a5 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -135,6 +135,9 @@ class CategorieTest extends PHPUnit_Framework_TestCase print __METHOD__." result=".$result."\n"; $this->assertGreaterThan(0, $result); + // Unset $this->id for good check test + unset($localobject->id); + // We check if exist $result=$localobject->already_exists(); print __METHOD__." result=".$result."\n"; From 0c62709a9c2d714cdfa91ed0538818c449c022ca Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 11:33:50 +0100 Subject: [PATCH 24/27] Fix: save and restore value of $this->id --- test/phpunit/CategorieTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index b974e6f57a5..895fec50781 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -135,7 +135,8 @@ class CategorieTest extends PHPUnit_Framework_TestCase print __METHOD__." result=".$result."\n"; $this->assertGreaterThan(0, $result); - // Unset $this->id for good check test + // Save and unset $this->id for good check test + $saveid = $localobject->id; unset($localobject->id); // We check if exist @@ -147,6 +148,9 @@ class CategorieTest extends PHPUnit_Framework_TestCase $result=$localobject->create($user); print __METHOD__." result=".$result."\n"; $this->assertEquals(-4, $result); + + // Restore $this->id with save value + $localobject->id = $saveid; return $result; From 14996257a299c79c013575b4d411d27980959140 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 11:44:04 +0100 Subject: [PATCH 25/27] Fix: try another method --- test/phpunit/CategorieTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index 895fec50781..de6c25455dc 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -136,8 +136,8 @@ class CategorieTest extends PHPUnit_Framework_TestCase $this->assertGreaterThan(0, $result); // Save and unset $this->id for good check test - $saveid = $localobject->id; - unset($localobject->id); + $saveid = (int) $localobject->id; + $localobject->id = 0; // We check if exist $result=$localobject->already_exists(); @@ -151,6 +151,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase // Restore $this->id with save value $localobject->id = $saveid; + print __METHOD__." saveid=".$localobject->id."\n"; return $result; From b1f1c203fd6a0caab587b8dbaf63b87ff3b805d2 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 12:00:29 +0100 Subject: [PATCH 26/27] Fix: return the good result value --- test/phpunit/CategorieTest.php | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index de6c25455dc..3cdd14463fe 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -131,30 +131,24 @@ class CategorieTest extends PHPUnit_Framework_TestCase $localobject->initAsSpecimen(); // We create category - $result=$localobject->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + $resultFirstCreate=$localobject->create($user); + print __METHOD__." resultFirstCreate=".$resultFirstCreate."\n"; + $this->assertGreaterThan(0, $resultFirstCreate); - // Save and unset $this->id for good check test - $saveid = (int) $localobject->id; - $localobject->id = 0; + //Unset $this->id for good check test + unset($localobject->id); // We check if exist - $result=$localobject->already_exists(); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + $resultCheck=$localobject->already_exists(); + print __METHOD__." resultCheck=".$resultCheck."\n"; + $this->assertGreaterThan(0, $resultCheck); // We try to create same category again - $result=$localobject->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(-4, $result); - - // Restore $this->id with save value - $localobject->id = $saveid; - print __METHOD__." saveid=".$localobject->id."\n"; + $resultSecondCreate=$localobject->create($user); + print __METHOD__." result=".$resultSecondCreate."\n"; + $this->assertEquals(-4, $resultSecondCreate); - - return $result; + return $resultFirstCreate; } /** From 799b46d9413e8da78fd37d7215d5a3cf929e5c67 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 21 Mar 2012 12:07:38 +0100 Subject: [PATCH 27/27] Fix: begin test with phpunit and stop on failure --- build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.xml b/build.xml index 2c2dfb0c64c..fbfd6c3f4f6 100644 --- a/build.xml +++ b/build.xml @@ -97,5 +97,5 @@ - + \ No newline at end of file