Browse Source

Merge branch '11.0' of git@github.com:Dolibarr/dolibarr.git into 12.0

Laurent Destailleur 4 years ago
parent
commit
2c2142ddba

+ 12 - 0
htdocs/core/class/commonobject.class.php

@@ -8379,6 +8379,18 @@ abstract class CommonObject
 			}
 		}
 
+		// Delete llx_ecm_files
+		if (!$error) {
+			$sql = 'DELETE FROM '.MAIN_DB_PREFIX."ecm_files WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? '' : '@'.$this->module))."' AND src_object_id = ".$this->id;
+			$resql = $this->db->query($sql);
+			if (!$resql)
+			{
+				$this->error = $this->db->lasterror();
+				$this->errors[] = $this->error;
+				$error++;
+			}
+		}
+
 		if (!$error && !empty($this->isextrafieldmanaged))
 		{
 			$result = $this->deleteExtraFields();

+ 1 - 1
htdocs/ecm/class/ecmfiles.class.php

@@ -312,7 +312,7 @@ class EcmFiles extends CommonObject
 	 * @param  string $relativepath    	Relative path of file from document directory. Example: path/path2/file
 	 * @param  string $hashoffile      	Hash of file content. Take the first one found if same file is at different places. This hash will also change if file content is changed.
 	 * @param  string $hashforshare    	Hash of file sharing.
-	 * @param  string $src_object_type 	src_object_type to search
+	 * @param  string $src_object_type 	src_object_type to search (value of object->table_element)
 	 * @param  string $src_object_id 	src_object_id to search
 	 * @return int                 	   	<0 if KO, 0 if not found, >0 if OK
 	 */

+ 32 - 15
htdocs/expensereport/class/expensereport.class.php

@@ -1106,30 +1106,47 @@ class ExpenseReport extends CommonObject
 
         if (!$rowid) $rowid = $this->id;
 
+        $error = 0;
+
+        // Delete lines
         $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line.' WHERE '.$this->fk_element.' = '.$rowid;
-        if ($this->db->query($sql))
+        if (!$error && !$this->db->query($sql))
         {
+        	$this->error = $this->db->error()." sql=".$sql;
+        	dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
+        	$error++;
+        }
+
+        // Delete llx_ecm_files
+        if (!$error) {
+        	$sql = 'DELETE FROM '.MAIN_DB_PREFIX."ecm_files WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? '' : '@'.$this->module))."' AND src_object_id = ".$this->id;
+        	$resql = $this->db->query($sql);
+        	if (!$resql)
+        	{
+        		$this->error = $this->db->lasterror();
+        		$this->errors[] = $this->error;
+        		$error++;
+        	}
+        }
+
+        // Delete main record
+        if (!$error) {
             $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid = '.$rowid;
             $resql = $this->db->query($sql);
-            if ($resql)
-            {
-                $this->db->commit();
-                return 1;
-            }
-            else
+            if (!$resql)
             {
                 $this->error = $this->db->error()." sql=".$sql;
                 dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
-                $this->db->rollback();
-                return -6;
             }
         }
-        else
-        {
-            $this->error = $this->db->error()." sql=".$sql;
-            dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
-            $this->db->rollback();
-            return -4;
+
+        // Commit or rollback
+        if ($error) {
+        	$this->db->rollback();
+        	return -1;
+        } else {
+        	$this->db->commit();
+        	return 1;
         }
     }