diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 61b95c50064..05328d57b05 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1081,32 +1081,43 @@ class Expedition extends CommonObject /** * Delete shipment. - * Warning, do not delete a shipment if a delivery is linked to (with table llx_element_element) + * Warning, do not delete a shipment if a delivery is linked to (with table llx_element_element) * * @return int >0 if OK, 0 if deletion done but failed to delete files, <0 if KO */ function delete() { global $conf, $langs, $user; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - if ($conf->productbatch->enabled) - { require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; - } + $error=0; $this->error=''; + $this->db->begin(); + // Add a protection to refuse deleting if shipment has at least one delivery $this->fetchObjectLinked($this->id, 'shipping', 0, 'delivery'); // Get deliveries linked to this shipment if (count($this->linkedObjectsIds) > 0) { $this->error='ErrorThereIsSomeDeliveries'; - return -1; + $error++; + } + + if (! $error) + { + if (! $notrigger) + { + // Call trigger + $result=$this->call_trigger('SHIPPING_DELETE',$user); + if ($result < 0) { $error++; } + // End call triggers + } } - $this->db->begin(); // Stock control - if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0) + if (! $error && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); @@ -1203,11 +1214,6 @@ class Expedition extends CommonObject if ($this->db->query($sql)) { - // Call trigger - $result=$this->call_trigger('SHIPPING_DELETE',$user); - if ($result < 0) { $error++; } - // End call triggers - if (! empty($this->origin) && $this->origin_id > 0) { $this->fetch_origin(); @@ -2440,7 +2446,7 @@ class ExpeditionLigne extends CommonObjectLine dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); $this->error.=($this->error?', '.$errmsg:$errmsg); } - + $this->db->rollback(); return -1*$error; } diff --git a/test/phpunit/CodingSqlTest.php b/test/phpunit/CodingSqlTest.php index 57be8fc62a9..460a3e2fbeb 100644 --- a/test/phpunit/CodingSqlTest.php +++ b/test/phpunit/CodingSqlTest.php @@ -200,7 +200,7 @@ class CodingSqlTest extends PHPUnit_Framework_TestCase else { // Test for non key files only - $result=(strpos($filecontent,'KEY ') && strpos($filecontent,'PRIMARY KEY ') == 0); + $result=(strpos($filecontent,'KEY ') && strpos($filecontent,'PRIMARY KEY') == 0); print __METHOD__." Result for checking we don't have ' KEY ' instead of a sql file to create index = ".$result."\n"; $this->assertTrue($result===false, 'Found KEY into '.$file.'. Bad.');