ArticleImage::OnImageDelete PHP Method

OnImageDelete() public static method

It will disassociate the image from all articles.
public static OnImageDelete ( integer $p_imageId ) : void
$p_imageId integer
return void
    public static function OnImageDelete($p_imageId)
    {
        global $g_ado_db;
        // Get the articles that use this image.
        $queryStr = "SELECT * FROM ArticleImages WHERE IdImage={$p_imageId}";
        $rows = $g_ado_db->GetAll($queryStr);
        if (is_array($rows)) {
            foreach ($rows as $row) {
                ArticleImage::RemoveImageTagsFromArticleText($row['NrArticle'], $row['Number']);
            }
            $queryStr = "DELETE FROM ArticleImages WHERE IdImage={$p_imageId}";
            $g_ado_db->Execute($queryStr);
            $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
            $cacheService->clearNamespace('article_image');
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * 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;
 }
All Usage Examples Of ArticleImage::OnImageDelete