/**
* Delete the row from the database, all article references to this image,
* and the file(s) on disk.
*
* @return mixed
* TRUE if the record was deleted,
* return a PEAR_Error on failure.
*/
public function delete()
{
require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleImage.php';
if (function_exists("camp_load_translation_strings")) {
camp_load_translation_strings("api");
}
$imageStorageService = Zend_Registry::get('container')->getService('image.update_storage');
if ($imageStorageService->isDeletable($this->getImageFileName())) {
// Deleting the images from disk is the most common place for
// something to go wrong, so we do that first.
$thumb = $this->getThumbnailStorageLocation();
$imageFile = $this->getImageStorageLocation();
if (file_exists($thumb) && !is_writable($thumb)) {
return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $thumb), CAMP_ERROR_DELETE_FILE);
}
if (file_exists($imageFile) && !is_writable($imageFile)) {
return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $imageFile), CAMP_ERROR_DELETE_FILE);
}
if (file_exists($imageFile) && !unlink($imageFile)) {
return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $imageFile), CAMP_ERROR_DELETE_FILE);
}
if (file_exists($thumb) && !unlink($thumb)) {
return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $thumb), CAMP_ERROR_DELETE_FILE);
}
}
// Delete all the references to this image.
ArticleImage::OnImageDelete($this->getImageId());
$imageId = $this->getImageId();
$imageDescription = $this->getDescription();
// @ticket CS-4225
$em = \Zend_Registry::get('container')->getService('em');
$entity = $em->find('Newscoop\\Image\\LocalImage', $imageId);
$em->remove($entity);
$em->flush();
// Delete the record in the database
if (!parent::delete()) {
return new PEAR_Error(getGS("Could not delete record from the database."));
}
return true;
}