Fix: task #11248 : there is no DB transaction on products->delete

Qual: Mutualize code to see of an object as child
This commit is contained in:
Laurent Destailleur 2011-08-28 12:57:23 +00:00
parent 058636e01b
commit be5333589e
4 changed files with 563 additions and 564 deletions

View File

@ -571,20 +571,6 @@ class Product extends CommonObject
} }
} }
if (! $error)
{
$sqlz = "DELETE FROM ".MAIN_DB_PREFIX."product";
$sqlz.= " WHERE rowid = ".$id;
dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG);
$resultz = $this->db->query($sqlz);
if ( ! $resultz )
{
$error++;
$this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR);
}
}
if (! $error) if (! $error)
{ {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
@ -606,6 +592,21 @@ class Product extends CommonObject
} }
} }
// Delete product
if (! $error)
{
$sqlz = "DELETE FROM ".MAIN_DB_PREFIX."product";
$sqlz.= " WHERE rowid = ".$id;
dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG);
$resultz = $this->db->query($sqlz);
if ( ! $resultz )
{
$error++;
$this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR);
}
}
if (! $error) if (! $error)
{ {
// Appel des triggers // Appel des triggers

View File

@ -85,8 +85,10 @@ $parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
$error=$hookmanager->error; $errors=$hookmanager->errors; $error=$hookmanager->error; $errors=$hookmanager->errors;
if ($action == 'setproductaccountancycodebuy') if (empty($reshook))
{ {
if ($action == 'setproductaccountancycodebuy')
{
$product = new Product($db); $product = new Product($db);
$result=$product->fetch($id); $result=$product->fetch($id);
$product->accountancy_code_buy=$_POST["productaccountancycodebuy"]; $product->accountancy_code_buy=$_POST["productaccountancycodebuy"];
@ -98,10 +100,10 @@ if ($action == 'setproductaccountancycodebuy')
$action=""; $action="";
$id=$_POST["id"]; $id=$_POST["id"];
$_GET["id"]=$_POST["id"]; $_GET["id"]=$_POST["id"];
} }
if ($action == 'setproductaccountancycodesell') if ($action == 'setproductaccountancycodesell')
{ {
$product = new Product($db); $product = new Product($db);
$result=$product->fetch($id); $result=$product->fetch($id);
$product->accountancy_code_sell=$_POST["productaccountancycodesell"]; $product->accountancy_code_sell=$_POST["productaccountancycodesell"];
@ -111,21 +113,21 @@ if ($action == 'setproductaccountancycodesell')
$mesg=join(',',$product->errors); $mesg=join(',',$product->errors);
} }
$action=""; $action="";
} }
if ($action == 'fastappro') if ($action == 'fastappro')
{ {
$product = new Product($db); $product = new Product($db);
$product->fetch($id); $product->fetch($id);
$result = $product->fastappro($user); $result = $product->fastappro($user);
Header("Location: fiche.php?id=".$id); Header("Location: fiche.php?id=".$id);
exit; exit;
} }
// Add a product or service // Add a product or service
if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer)) if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer))
{ {
$error=0; $error=0;
if (empty($_POST["libelle"])) if (empty($_POST["libelle"]))
@ -222,11 +224,11 @@ if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service
$_GET["type"] = $_POST["type"]; $_GET["type"] = $_POST["type"];
} }
} }
} }
// Update a product or service // Update a product or service
if ($action == 'update' && ($user->rights->produit->creer || $user->rights->service->creer)) if ($action == 'update' && ($user->rights->produit->creer || $user->rights->service->creer))
{ {
if (! empty($_POST["cancel"])) if (! empty($_POST["cancel"]))
{ {
$action = ''; $action = '';
@ -285,11 +287,11 @@ if ($action == 'update' && ($user->rights->produit->creer || $user->rights->serv
} }
} }
} }
} }
// Action clone object // Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->produit->creer || $user->rights->service->creer)) if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->produit->creer || $user->rights->service->creer))
{ {
if (! GETPOST('clone_content') && ! GETPOST('clone_prices') ) if (! GETPOST('clone_content') && ! GETPOST('clone_prices') )
{ {
$mesg='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>'; $mesg='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>';
@ -349,39 +351,36 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->produit->
dol_print_error($product->db); dol_print_error($product->db);
} }
} }
} }
/* // Delete a product
* Suppression d'un produit/service pas encore affect if ($action == 'confirm_delete' && $confirm == 'yes')
*/
if ($action == 'confirm_delete' && $confirm == 'yes')
{
$product = new Product($db);
$product->fetch($id);
if ( ($product->type == 0 && $user->rights->produit->supprimer) || ($product->type == 1 && $user->rights->service->supprimer) )
{ {
$result = $product->delete($id); $object = new Product($db);
$object->fetch($id);
if ( ($object->type == 0 && $user->rights->produit->supprimer) || ($object->type == 1 && $user->rights->service->supprimer) )
{
$result = $object->delete($id);
} }
if ($result > 0) if ($result > 0)
{ {
Header('Location: '.DOL_URL_ROOT.'/product/liste.php?delprod='.urlencode($product->ref)); Header('Location: '.DOL_URL_ROOT.'/product/liste.php?delprod='.urlencode($object->ref));
exit; exit;
} }
else else
{ {
$mesg=$object->error;
$reload = 0; $reload = 0;
$action=''; $action='';
} }
} }
/* // Add product into proposal
* Ajout du produit dans une propal if ($action == 'addinpropal')
*/ {
if ($action == 'addinpropal')
{
$propal = new Propal($db); $propal = new Propal($db);
$result=$propal->fetch($_POST["propalid"]); $result=$propal->fetch($_POST["propalid"]);
if ($result <= 0) if ($result <= 0)
@ -457,13 +456,11 @@ if ($action == 'addinpropal')
} }
$mesg = $langs->trans("ErrorUnknown").": $result"; $mesg = $langs->trans("ErrorUnknown").": $result";
} }
/* // Add product into order
* Ajout du produit dans une commande if ($action == 'addincommande')
*/ {
if ($action == 'addincommande')
{
$commande = new Commande($db); $commande = new Commande($db);
$result=$commande->fetch($_POST["commandeid"]); $result=$commande->fetch($_POST["commandeid"]);
if ($result <= 0) if ($result <= 0)
@ -541,13 +538,11 @@ if ($action == 'addincommande')
Header("Location: ".DOL_URL_ROOT."/commande/fiche.php?id=".$commande->id); Header("Location: ".DOL_URL_ROOT."/commande/fiche.php?id=".$commande->id);
exit; exit;
} }
} }
/* // Add product into invoice
* Ajout du produit dans une facture if ($action == 'addinfacture' && $user->rights->facture->creer)
*/ {
if ($action == 'addinfacture' && $user->rights->facture->creer)
{
$facture = New Facture($db); $facture = New Facture($db);
$result=$facture->fetch($_POST["factureid"]); $result=$facture->fetch($_POST["factureid"]);
if ($result <= 0) if ($result <= 0)
@ -627,9 +622,10 @@ if ($action == 'addinfacture' && $user->rights->facture->creer)
Header("Location: ".DOL_URL_ROOT."/compta/facture.php?facid=".$facture->id); Header("Location: ".DOL_URL_ROOT."/compta/facture.php?facid=".$facture->id);
exit; exit;
} }
}
} }
if ($_POST["cancel"] == $langs->trans("Cancel")) if (GETPOST("cancel") == $langs->trans("Cancel"))
{ {
$action = ''; $action = '';
Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST["id"]); Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST["id"]);

View File

@ -938,20 +938,6 @@ class Societe extends CommonObject
} }
} }
// Remove third party
if (! $error)
{
$sql = "DELETE from ".MAIN_DB_PREFIX."societe";
$sql.= " WHERE rowid = " . $id;
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
if (! $this->db->query($sql))
{
$error++;
$this->error = $this->db->lasterror();
dol_syslog(get_class($this)."::delete erreur -3 ".$this->error, LOG_ERR);
}
}
if (! $error) if (! $error)
{ {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
@ -973,6 +959,20 @@ class Societe extends CommonObject
} }
} }
// Remove third party
if (! $error)
{
$sql = "DELETE from ".MAIN_DB_PREFIX."societe";
$sql.= " WHERE rowid = " . $id;
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
if (! $this->db->query($sql))
{
$error++;
$this->error = $this->db->lasterror();
dol_syslog(get_class($this)."::delete erreur -3 ".$this->error, LOG_ERR);
}
}
if (! $error) if (! $error)
{ {
// Appel des triggers // Appel des triggers

View File

@ -424,9 +424,9 @@ if (empty($reshook))
$object->fetch($socid); $object->fetch($socid);
$result = $object->delete($socid); $result = $object->delete($socid);
if ($result >= 0) if ($result > 0)
{ {
Header("Location: ".DOL_URL_ROOT."/societe/societe.php?delsoc=".$object->nom.""); Header("Location: ".DOL_URL_ROOT."/societe/societe.php?delsoc=".urlencode($object->name));
exit; exit;
} }
else else
@ -498,6 +498,7 @@ $formcompany = new FormCompany($db);
$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
// TODO Mutualize this part of code (same than product/fiche.php and contact/fiche.php) // TODO Mutualize this part of code (same than product/fiche.php and contact/fiche.php)
if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
{ {
@ -538,6 +539,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
} }
else else
{ {
// ----------------------------------------- // -----------------------------------------
// When used in standard mode // When used in standard mode
// ----------------------------------------- // -----------------------------------------