Update commonobject.class.php

This commit is contained in:
Laurent Destailleur 2020-06-06 21:37:53 +02:00 committed by GitHub
parent af440b7c49
commit d9ac7ab9da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7892,35 +7892,37 @@ abstract class CommonObject
}
// Delete cascade first
if (!empty($this->childtablesoncascade)) {
if (is_array($this->childtablesoncascade)) {
foreach ($this->childtablesoncascade as $table)
{
$deleteFromObject=explode(':', $table);
$deleteFromObject = explode(':', $table);
if (count($deleteFromObject)>=2) {
$className=str_replace('@', '', $deleteFromObject[0]);
$filePath=$deleteFromObject[1];
$columnName=$deleteFromObject[2];
$className = str_replace('@', '', $deleteFromObject[0]);
$filePath = $deleteFromObject[1];
$columnName = $deleteFromObject[2];
if (dol_include_once($filePath)) {
$childObject = new $className($this->db);
if (is_callable($childObject, 'deleteByParentField')) {
if (method_exists($childObject, 'deleteByParentField')) {
$result = $childObject->deleteByParentField($this->id, $columnName);
if ($result < 0) {
$error++;
$this->errors[] = $childObject->error;
return -1;
break;
}
}
} else {
$this->errors[] = 'Cannot find child class file ' .$filePath;
return -1;
$error++;
$this->errors[] = 'Cannot include child class file ' .$filePath;
break;
}
} else {
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $table . ' WHERE ' . $this->fk_element . ' = ' . $this->id;
$resql = $this->db->query($sql);
if (!$resql) {
$error++;
$this->error = $this->db->lasterror();
$this->errors[] = $this->error;
$this->db->rollback();
return -1;
break;
}
}
}