From d9f6d9f0c319e09a6fbeef176979268dc1614a82 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Jun 2019 19:12:44 +0200 Subject: [PATCH 1/5] Code comment --- htdocs/debugbar/class/DataCollector/DolQueryCollector.php | 1 + htdocs/debugbar/class/TraceableDB.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/debugbar/class/DataCollector/DolQueryCollector.php b/htdocs/debugbar/class/DataCollector/DolQueryCollector.php index 8430cf41adf..03811890f43 100644 --- a/htdocs/debugbar/class/DataCollector/DolQueryCollector.php +++ b/htdocs/debugbar/class/DataCollector/DolQueryCollector.php @@ -24,6 +24,7 @@ class DolQueryCollector extends DataCollector implements Renderable, AssetProvid { global $db; + // Replace $db handler with new handler override by TraceableDB $db = new TraceableDB($db); $this->db = $db; diff --git a/htdocs/debugbar/class/TraceableDB.php b/htdocs/debugbar/class/TraceableDB.php index 0caf6c2489f..4d34da61465 100644 --- a/htdocs/debugbar/class/TraceableDB.php +++ b/htdocs/debugbar/class/TraceableDB.php @@ -7,7 +7,6 @@ require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php'; * * Used to log queries into DebugBar */ - class TraceableDB extends DoliDB { /** From 2854e0dae600108f5763d0e4f5b2ce7aa37d27a7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Jun 2019 19:15:15 +0200 Subject: [PATCH 2/5] Code comment --- htdocs/core/db/DoliDB.class.php | 4 ++-- htdocs/debugbar/class/TraceableDB.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php index b05f118b08b..3819e785f68 100644 --- a/htdocs/core/db/DoliDB.class.php +++ b/htdocs/core/db/DoliDB.class.php @@ -160,10 +160,10 @@ abstract class DoliDB implements Database } /** - * Annulation d'une transaction et retour aux anciennes valeurs + * Cancel a transaction and go back to initial data values * * @param string $log Add more log to default log line - * @return resource|int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur + * @return resource|int 1 if cancelation is ok or transaction not open, 0 if error */ public function rollback($log = '') { diff --git a/htdocs/debugbar/class/TraceableDB.php b/htdocs/debugbar/class/TraceableDB.php index 4d34da61465..4edc39a74af 100644 --- a/htdocs/debugbar/class/TraceableDB.php +++ b/htdocs/debugbar/class/TraceableDB.php @@ -274,10 +274,10 @@ class TraceableDB extends DoliDB } /** - * Annulation d'une transaction et retour aux anciennes valeurs + * Cancel a transaction and go back to initial data values * - * @param string $log Add more log to default log line - * @return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur + * @param string $log Add more log to default log line + * @return resource|int 1 if cancelation is ok or transaction not open, 0 if error */ public function rollback($log = '') { From 71b266b5a815be97e8fed88cb6524349293c1544 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Jun 2019 19:20:01 +0200 Subject: [PATCH 3/5] Code comment --- htdocs/adherents/class/adherent.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index c1bb04d90fc..115d1fb8ab4 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -2403,7 +2403,7 @@ class Adherent extends CommonObject $this->country_id = 1; $this->country_code = 'FR'; $this->country = 'France'; - $this->morphy = 1; + $this->morphy = 'mor'; $this->email = 'specimen@specimen.com'; $this->skype = 'skypepseudo'; $this->twitter = 'twitterpseudo'; From b202c7eaa0286a8d9b1d3b0f8a53b5ecb2cd1e34 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Jun 2019 20:17:40 +0200 Subject: [PATCH 4/5] Fix confusion between ->childs and ->childsoncascade --- htdocs/asset/class/asset.class.php | 4 +-- htdocs/bom/class/bom.class.php | 25 +++++++++---------- htdocs/core/class/commonobject.class.php | 16 +++++++++++- htdocs/core/class/coreobject.class.php | 2 +- .../core/class/emailsenderprofile.class.php | 4 +-- .../class/emailcollector.class.php | 8 ++++-- .../class/emailcollectoraction.class.php | 4 +-- .../template/class/myobject.class.php | 18 ++++++------- htdocs/product/class/product.class.php | 5 +++- .../inventory/class/inventory.class.php | 8 ++++-- htdocs/projet/class/task.class.php | 6 ++++- .../class/companypaymentmode.class.php | 4 +-- htdocs/societe/class/societe.class.php | 10 +++++++- htdocs/societe/class/societeaccount.class.php | 4 +-- 14 files changed, 76 insertions(+), 42 deletions(-) diff --git a/htdocs/asset/class/asset.class.php b/htdocs/asset/class/asset.class.php index 8e9e31e68b2..37aeb4607c8 100644 --- a/htdocs/asset/class/asset.class.php +++ b/htdocs/asset/class/asset.class.php @@ -163,9 +163,9 @@ class Asset extends CommonObject */ //public $class_element_line = 'Assetline'; /** - * @var array Array of child tables (child tables to delete before deleting a record) + * @var array List of child tables. To test if we can delete object. */ - //protected $childtables=array('assetdet'); + //protected $childtables=array(); /** * @var AssetLine[] Array of subtable lines */ diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 99331de8c62..5d9f1f50cbc 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -41,12 +41,6 @@ class BOM extends CommonObject */ public $table_element = 'bom_bom'; - /** - * @var string Name of subtable if this object has sub lines - */ - public $table_element_line = 'bom_bomline'; - public $fk_element = 'fk_bom'; - /** * @var int Does bom support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe */ @@ -134,27 +128,32 @@ class BOM extends CommonObject /** * @var int Name of subtable line */ - //public $table_element_line = 'bomdet'; + public $table_element_line = 'bom_bomline'; /** * @var int Field with ID of parent key if this field has a parent */ - //public $fk_element = 'fk_bom'; + public $fk_element = 'fk_bom'; /** * @var int Name of subtable class that manage subtable lines */ - //public $class_element_line = 'BillOfMaterialsline'; + public $class_element_line = 'BOMLine'; /** - * @var array Array of child tables (child tables to delete before deleting a record) + * @var array List of child tables. To test if we can delete object. */ - //protected $childtables=array('bomdet'); + //protected $childtables=array(); /** - * @var BillOfMaterialsLine[] Array of subtable lines + * @var array List of child tables. To know object to delete on cascade. */ - //public $lines = array(); + protected $childtablesoncascade=array('bom_bomline'); + + /** + * @var BOMLine[] Array of subtable lines + */ + public $lines = array(); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index f989f0bb431..9c5812069b7 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7490,7 +7490,7 @@ abstract class CommonObject $this->db->begin(); - if ($forcechilddeletion) + if ($forcechilddeletion) // Force also delete of childtables that should lock deletion in standard case when option force is off { foreach($this->childtables as $table) { @@ -7518,6 +7518,20 @@ abstract class CommonObject } } + // Delete cascade first + foreach($this->childtablesoncascade as $table) + { + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error=$this->db->lasterror(); + $this->errors[]=$this->error; + $this->db->rollback(); + return -1; + } + } + if (! $error) { if (! $notrigger) { // Call triggers diff --git a/htdocs/core/class/coreobject.class.php b/htdocs/core/class/coreobject.class.php index 02a083978ef..4cd3fe1b2ed 100644 --- a/htdocs/core/class/coreobject.class.php +++ b/htdocs/core/class/coreobject.class.php @@ -175,7 +175,7 @@ class CoreObject extends CommonObject */ public function fetchChild() { - if($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) + if ($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) { foreach($this->childtables as &$childTable) { diff --git a/htdocs/core/class/emailsenderprofile.class.php b/htdocs/core/class/emailsenderprofile.class.php index f9eeeabf4c6..c3d37d03b85 100644 --- a/htdocs/core/class/emailsenderprofile.class.php +++ b/htdocs/core/class/emailsenderprofile.class.php @@ -131,9 +131,9 @@ class EmailSenderProfile extends CommonObject */ //public $class_element_line = 'EmailSenderProfileline'; /** - * @var array Array of child tables (child tables to delete before deleting a record) + * @var array List of child tables. To test if we can delete object. */ - //protected $childtables=array('emailsenderprofiledet'); + //protected $childtables=array(); /** * @var EmailSenderProfileLine[] Array of subtable lines */ diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index ff4be06fcab..b22d7b23607 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -62,9 +62,13 @@ class EmailCollector extends CommonObject public $fk_element = 'fk_emailcollector'; /** - * @var array Array of child tables (child tables to delete before deleting a record) + * @var array List of child tables. To test if we can delete object. */ - protected $childtables=array('emailcollector_emailcollectorfilter', 'emailcollector_emailcollectoraction'); + protected $childtables=array(); + /** + * @var array List of child tables. To know object to delete on cascade. + */ + protected $childtablesoncascade=array('emailcollector_emailcollectorfilter','emailcollector_emailcollectoraction'); /** diff --git a/htdocs/emailcollector/class/emailcollectoraction.class.php b/htdocs/emailcollector/class/emailcollectoraction.class.php index ca710f99216..96f650c9fc0 100644 --- a/htdocs/emailcollector/class/emailcollectoraction.class.php +++ b/htdocs/emailcollector/class/emailcollectoraction.class.php @@ -127,9 +127,9 @@ class EmailCollectorAction extends CommonObject //public $class_element_line = 'EmailcollectorActionline'; // /** - // * @var array Array of child tables (child tables to delete before deleting a record) + // * @var array List of child tables. To test if we can delete object. // */ - //protected $childtables=array('emailcollectoractiondet'); + //protected $childtables=array(); // /** // * @var EmailcollectorActionLine[] Array of subtable lines diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 1b4d1c7b52d..0025c00165d 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -42,12 +42,6 @@ class MyObject extends CommonObject */ public $table_element = 'mymodule_myobject'; - /** - * @var string Name of subtable if this object has sub lines - */ - //public $table_element_line = 'mymodule_myobjectline'; - //public $fk_element = 'fk_myobject'; - /** * @var int Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe */ @@ -171,13 +165,12 @@ class MyObject extends CommonObject // END MODULEBUILDER PROPERTIES - // If this object has a subtable with lines /** * @var int Name of subtable line */ - //public $table_element_line = 'myobjectdet'; + //public $table_element_line = 'mymodule_myobjectline'; /** * @var int Field with ID of parent key if this field has a parent @@ -190,9 +183,14 @@ class MyObject extends CommonObject //public $class_element_line = 'MyObjectline'; /** - * @var array Array of child tables (child tables to delete before deleting a record) + * @var array List of child tables. To test if we can delete object. */ - //protected $childtables=array('myobjectdet'); + //protected $childtables=array(); + + /** + * @var array List of child tables. To know object to delete on cascade. + */ + //protected $childtablesoncascade=array('mymodule_myobjectdet'); /** * @var MyObjectLine[] Array of subtable lines diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index a5491045c16..02de9b4d47d 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -59,7 +59,10 @@ class Product extends CommonObject */ public $fk_element='fk_product'; - protected $childtables=array('supplier_proposaldet', 'propaldet','commandedet','facturedet','contratdet','facture_fourn_det','commande_fournisseurdet'); // To test if we can delete object + /** + * @var array List of child tables. To test if we can delete object. + */ + protected $childtables=array('supplier_proposaldet', 'propaldet', 'commandedet', 'facturedet', 'contratdet', 'facture_fourn_det', 'commande_fournisseurdet'); /** * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index 7f535a2eac0..62cfc476ba8 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -169,9 +169,13 @@ class Inventory extends CommonObject public $class_element_line = 'Inventoryline'; /** - * @var array Array of child tables (child tables to delete before deleting a record) + * @var array List of child tables. To test if we can delete object. */ - protected $childtables=array('inventorydet'); + protected $childtables=array(); + /** + * @var array List of child tables. To know object to delete on cascade. + */ + protected $childtablesoncascade=array('inventorydet'); /** * @var InventoryLine[] Array of subtable lines diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index a5f63e32826..ce4779e1a6d 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -48,7 +48,11 @@ class Task extends CommonObject public $fk_element='fk_task'; public $picto = 'task'; - protected $childtables=array('projet_task_time'); // To test if we can delete object + + /** + * @var array List of child tables. To test if we can delete object. + */ + protected $childtables=array('projet_task_time'); /** * @var int ID parent task diff --git a/htdocs/societe/class/companypaymentmode.class.php b/htdocs/societe/class/companypaymentmode.class.php index e3e86e2cf4a..4275d356566 100644 --- a/htdocs/societe/class/companypaymentmode.class.php +++ b/htdocs/societe/class/companypaymentmode.class.php @@ -204,9 +204,9 @@ class CompanyPaymentMode extends CommonObject */ //public $class_element_line = 'CompanyPaymentModeline'; /** - * @var array Array of child tables (child tables to delete before deleting a record) + * @var array List of child tables. To test if we can delete object. */ - //protected $childtables=array('companypaymentmodedet'); + //protected $childtables=array(); /** * @var CompanyPaymentModeLine[] Array of subtable lines */ diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 2ad9a3473a4..b1d037552aa 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -59,8 +59,16 @@ class Societe extends CommonObject public $fk_element='fk_soc'; public $fieldsforcombobox='nom,name_alias'; - protected $childtables=array("supplier_proposal"=>'SupplierProposal',"propal"=>'Proposal',"commande"=>'Order',"facture"=>'Invoice',"facture_rec"=>'RecurringInvoiceTemplate',"contrat"=>'Contract',"fichinter"=>'Fichinter',"facture_fourn"=>'SupplierInvoice',"commande_fournisseur"=>'SupplierOrder',"projet"=>'Project',"expedition"=>'Shipment',"prelevement_lignes"=>'DirectDebitRecord'); // To test if we can delete object + + /** + * @var array List of child tables. To test if we can delete object. + */ + protected $childtables=array("supplier_proposal"=>'SupplierProposal',"propal"=>'Proposal',"commande"=>'Order',"facture"=>'Invoice',"facture_rec"=>'RecurringInvoiceTemplate',"contrat"=>'Contract',"fichinter"=>'Fichinter',"facture_fourn"=>'SupplierInvoice',"commande_fournisseur"=>'SupplierOrder',"projet"=>'Project',"expedition"=>'Shipment',"prelevement_lignes"=>'DirectDebitRecord'); + /** + * @var array List of child tables. To know object to delete on cascade. + */ protected $childtablesoncascade=array("societe_prices", "societe_log", "societe_address", "product_fournisseur_price", "product_customer_price_log", "product_customer_price", "socpeople", "adherent", "societe_account", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "categorie", "notify", "notify_def", "actioncomm"); + public $picto = 'company'; /** diff --git a/htdocs/societe/class/societeaccount.class.php b/htdocs/societe/class/societeaccount.class.php index a82ad69091b..5f333da69a3 100644 --- a/htdocs/societe/class/societeaccount.class.php +++ b/htdocs/societe/class/societeaccount.class.php @@ -164,9 +164,9 @@ class SocieteAccount extends CommonObject */ //public $class_element_line = 'societeAccountline'; /** - * @var array Array of child tables (child tables to delete before deleting a record) + * @var array List of child tables. To test if we can delete object. */ - //protected $childtables=array('societe_accountdet'); + //protected $childtables=array(); /** * @var societeAccountLine[] Array of subtable lines */ From 8a9c858609413bea81f7a6fe97b171d6c573a0ce Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Jun 2019 20:18:55 +0200 Subject: [PATCH 5/5] Code comment --- htdocs/core/class/coreobject.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/class/coreobject.class.php b/htdocs/core/class/coreobject.class.php index 4cd3fe1b2ed..41aae05d74a 100644 --- a/htdocs/core/class/coreobject.class.php +++ b/htdocs/core/class/coreobject.class.php @@ -25,6 +25,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; +// TODO Remove this class (used in Expensereportik and ExpenseReportRule class CoreObject extends CommonObject { public $withChild = true;