diff --git a/classes/CustomerMessage.php b/classes/CustomerMessage.php index a8ec2395d..ae8709d5b 100644 --- a/classes/CustomerMessage.php +++ b/classes/CustomerMessage.php @@ -104,6 +104,11 @@ class CustomerMessageCore extends ObjectModel WHERE '.$where ); } - -} - + + public function delete() + { + if (!empty($this->file_name)) + @unlink(_PS_UPLOAD_DIR_.$this->file_name); + return parent::delete(); + } +} \ No newline at end of file diff --git a/classes/CustomerThread.php b/classes/CustomerThread.php index a2822aab5..3425b38d1 100644 --- a/classes/CustomerThread.php +++ b/classes/CustomerThread.php @@ -97,11 +97,27 @@ class CustomerThreadCore extends ObjectModel { if (!Validate::isUnsignedId($this->id)) return false; - Db::getInstance()->execute(' - DELETE FROM `'._DB_PREFIX_.'customer_message` + + $return = true; + $result = Db::getInstance()->executeS(' + SELECT `id_customer_message` + FROM `'._DB_PREFIX_.'customer_message` WHERE `id_customer_thread` = '.(int)$this->id ); - return (parent::delete()); + + if( count($result)) + { + foreach ($result AS $res) + { + $message = new CustomerMessage((int)$res['id_customer_message']); + if (!Validate::isLoadedObject($message)) + $return = false; + else + $return &= $message->delete(); + } + } + $return &= parent::delete(); + return $return; } public static function getCustomerMessages($id_customer, $read = null) @@ -204,5 +220,4 @@ class CustomerThreadCore extends ObjectModel ' ORDER BY ct.date_upd ASC '); } -} - +} \ No newline at end of file