From b202c7eaa0286a8d9b1d3b0f8a53b5ecb2cd1e34 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Jun 2019 20:17:40 +0200 Subject: [PATCH] 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 */