Skip to content

Commit

Permalink
Fix confusion between ->childs and ->childsoncascade
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jun 22, 2019
1 parent 71b266b commit b202c7e
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 42 deletions.
4 changes: 2 additions & 2 deletions htdocs/asset/class/asset.class.php
Expand Up @@ -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
*/
Expand Down
25 changes: 12 additions & 13 deletions htdocs/bom/class/bom.class.php
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 List of child tables. To test if we can delete object.
*/
//protected $childtables=array();

/**
* @var array Array of child tables (child tables to delete before deleting a record)
* @var array List of child tables. To know object to delete on cascade.
*/
//protected $childtables=array('bomdet');
protected $childtablesoncascade=array('bom_bomline');

/**
* @var BillOfMaterialsLine[] Array of subtable lines
* @var BOMLine[] Array of subtable lines
*/
//public $lines = array();
public $lines = array();



Expand Down
16 changes: 15 additions & 1 deletion htdocs/core/class/commonobject.class.php
Expand Up @@ -7490,7 +7490,7 @@ public function deleteCommon(User $user, $notrigger = false, $forcechilddeletion

$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)
{
Expand Down Expand Up @@ -7518,6 +7518,20 @@ public function deleteCommon(User $user, $notrigger = false, $forcechilddeletion
}
}

// 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
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/class/coreobject.class.php
Expand Up @@ -175,7 +175,7 @@ public function removeChild($tabName, $id, $key = 'id')
*/
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)
{
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/class/emailsenderprofile.class.php
Expand Up @@ -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
*/
Expand Down
8 changes: 6 additions & 2 deletions htdocs/emailcollector/class/emailcollector.class.php
Expand Up @@ -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');


/**
Expand Down
4 changes: 2 additions & 2 deletions htdocs/emailcollector/class/emailcollectoraction.class.php
Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions htdocs/modulebuilder/template/class/myobject.class.php
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand All @@ -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();

/**
* @var array List of child tables. To know object to delete on cascade.
*/
//protected $childtables=array('myobjectdet');
//protected $childtablesoncascade=array('mymodule_myobjectdet');

/**
* @var MyObjectLine[] Array of subtable lines
Expand Down
5 changes: 4 additions & 1 deletion htdocs/product/class/product.class.php
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions htdocs/product/inventory/class/inventory.class.php
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion htdocs/projet/class/task.class.php
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions htdocs/societe/class/companypaymentmode.class.php
Expand Up @@ -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
*/
Expand Down
10 changes: 9 additions & 1 deletion htdocs/societe/class/societe.class.php
Expand Up @@ -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';

/**
Expand Down
4 changes: 2 additions & 2 deletions htdocs/societe/class/societeaccount.class.php
Expand Up @@ -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
*/
Expand Down

0 comments on commit b202c7e

Please sign in to comment.