diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 1aad39954fc..06a5aa3e598 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -2404,7 +2404,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'; 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..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; @@ -175,7 +176,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/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/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..4edc39a74af 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 { /** @@ -275,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 = '') { 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 5ded310683b..5187d8522a2 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 */