Beispiel #1
0
 /**
  * Removes all the image aliases and their information.
  * The stored images will also be removed if the attribute is the owner
  * of the images.
  *
  * After the images are removed the attribute will containe an internal
  * structure with empty data
  *
  * @param eZContentObjectAttribute $contentObjectAttribute
  *        Content object attribute to remove aliases for
  *
  * @return void
  */
 function removeAliases($contentObjectAttribute)
 {
     $aliasList = $this->aliasList();
     $alternativeText = false;
     $contentObjectAttributeVersion = $this->ContentObjectAttributeData['version'];
     $contentObjectAttributeID = $this->ContentObjectAttributeData['id'];
     $isImageOwner = $this->isImageOwner();
     // We loop over each image alias, and look up the file in ezcontentobject_attribute
     // Only images referenced by one version will be removed
     foreach ($aliasList as $aliasName => $alias) {
         $dirpath = $alias['dirpath'];
         $doNotDelete = false;
         // Do not delete files from storage
         if ($aliasName == 'original') {
             $alternativeText = $alias['alternative_text'];
         }
         if ($alias['is_valid']) {
             $filepath = $alias['url'];
             // Fetch ezimage attributes that use $filepath
             // Always returns current attribute (array of $contentObjectAttributeID and $contentObjectAttributeVersion)
             $dbResult = eZImageFile::fetchImageAttributesByFilepath($filepath, $contentObjectAttributeID);
             $dbResultCount = count($dbResult);
             // Check if there are the attributes.
             if ($dbResultCount > 0) {
                 $doNotDelete = true;
                 foreach ($dbResult as $res) {
                     // We only look results where the version matches
                     if ($res['version'] == $contentObjectAttributeVersion) {
                         // If more than one result has been returned, it means
                         // that another version is using the same image,
                         // and we should not delete this file
                         if ($dbResultCount > 1) {
                             continue;
                         } else {
                             $doNotDelete = false;
                         }
                     }
                     eZImageFile::appendFilepath($res['id'], $filepath, true);
                 }
             }
             if (!$doNotDelete) {
                 $file = eZClusterFileHandler::instance($filepath);
                 if ($file->exists()) {
                     $file->delete();
                     eZImageFile::removeFilepath($contentObjectAttributeID, $filepath);
                     eZDir::cleanupEmptyDirectories($dirpath);
                 } else {
                     eZDebug::writeError("Image file {$filepath} for alias {$aliasName} does not exist, could not remove from disk", __METHOD__);
                 }
             }
         }
     }
     $doc = new DOMDocument('1.0', 'utf-8');
     $imageNode = $doc->createElement("ezimage");
     $doc->appendChild($imageNode);
     $imageNode->setAttribute('serial_number', false);
     $imageNode->setAttribute('is_valid', false);
     $imageNode->setAttribute('filename', false);
     $imageNode->setAttribute('suffix', false);
     $imageNode->setAttribute('basename', false);
     $imageNode->setAttribute('dirpath', false);
     $imageNode->setAttribute('url', false);
     $imageNode->setAttribute('original_filename', false);
     $imageNode->setAttribute('mime_type', false);
     $imageNode->setAttribute('width', false);
     $imageNode->setAttribute('height', false);
     $imageNode->setAttribute('alternative_text', $alternativeText);
     $imageNode->setAttribute('alias_key', false);
     $imageNode->setAttribute('timestamp', false);
     $this->ContentObjectAttributeData['DataTypeCustom']['dom_tree'] = $doc;
     unset($this->ContentObjectAttributeData['DataTypeCustom']['alias_list']);
     $this->storeDOMTree($doc, true, $contentObjectAttribute);
 }
    if( $nbImageFiles > 0 )
    {
        // Progress bar initialization
        $progressBarOptions = array(
            'emptyChar'     => ' ',
            'barChar'       => '='
        );
        $progressBar = new ezcConsoleProgressbar( $output, $nbImageFiles, $progressBarOptions );

        // Loop the image files and check if it is still used by a content object attribute. If not, delete it.
        foreach( $aImageFiles as $image )
        {
            $filePath = $image->attribute( 'filepath' );
            $dirpath = dirname( $filePath );
            $contentObjectAttributeID = $image->attribute( 'contentobject_attribute_id' );
            $dbResult = eZImageFile::fetchImageAttributesByFilepath( $filePath, $contentObjectAttributeID );
            if( count( $dbResult ) == 0 )
            {
                $file = eZClusterFileHandler::instance( $filePath );
                if ( $file->exists() ) // Delete the file physically
                {
                    $file->delete();
                    eZImageFile::removeFilepath( $contentObjectAttributeID, $filePath );
                    eZDir::cleanupEmptyDirectories( $dirpath );
                }

                // Delete the obsolete reference in the database
                $image->remove();
            }

            $progressBar->advance();
 function updateAliasPath($dirpath, $name)
 {
     if (!file_exists($dirpath)) {
         eZDir::mkdir($dirpath, false, true);
     }
     $aliasList = $this->aliasList();
     $this->resetImageSerialNumber();
     foreach ($aliasList as $aliasName => $alias) {
         if ($alias['dirpath'] != $dirpath) {
             $oldDirpath = $alias['url'];
             $oldURL = $alias['url'];
             $basename = $name;
             if ($aliasName != 'original') {
                 $basename .= '_' . $aliasName;
             }
             eZMimeType::changeFileData($alias, $dirpath, $basename);
             $alias['full_path'] = $alias['url'];
             if ($this->isImageOwner()) {
                 if ($oldURL == '') {
                     continue;
                 }
                 $fileHandler = eZClusterFileHandler::instance();
                 $fileHandler->fileMove($oldURL, $alias['url']);
                 eZDir::cleanupEmptyDirectories($oldDirpath);
                 eZImageFile::moveFilepath($this->ContentObjectAttributeData['id'], $oldURL, $alias['url']);
             } else {
                 $fileHandler = eZClusterFileHandler::instance();
                 $fileHandler->fileLinkCopy($oldURL, $alias['url'], false);
                 // we still move the file if no other attribute from the current content uses it
                 if (count(eZImageFile::fetchImageAttributesByFilepath($oldURL, $this->ContentObjectAttributeData['id'])) == 1) {
                     eZImageFile::moveFilepath($this->ContentObjectAttributeData['id'], $oldURL, $alias['url']);
                 } else {
                     eZImageFile::appendFilepath($this->ContentObjectAttributeData['id'], $alias['url']);
                 }
             }
             $this->setAliasVariation($aliasName, $alias);
         }
     }
     $this->recreateDOMTree();
     $this->setStorageRequired();
 }