Image file cleanup

Author Message

Sebastiaan van der Vliet

Tuesday 02 June 2009 5:48:44 am

Hi,

It appears that the bin/php/flatten.php script to remove non-published versions of the object does not clean up the matching image files per removed object version. Is this a correct assumption, and if so, what function/script would be the best option to use to clean up the image files?

Thanks,
Sebastiaan

Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.

Sebastiaan van der Vliet

Tuesday 02 June 2009 7:59:42 am

Hmm-what about this...

function deleteOldVersions( $eZObjectID )
{
	 global $cli;
	$eZObject = eZContentObject::fetch( $eZObjectID );
	$objectVersions = $eZObject->versions();
	
	$objectVersionID = $eZObject->attribute( 'current_version' );
	$cli->output(count($objectVersions)." versions");
	foreach ( $objectVersions as $version )
	{
		$versionID = $version->attribute('version');
		if ($objectVersionID != $versionID)
		{
			$contentObjectAttributes = $version->contentObjectAttributes();
			
			foreach ( $contentObjectAttributes as $contentObjectAttribute )
			{
				
				$classAttribute = $contentObjectAttribute->contentClassAttribute();
				$dataTypeString = $classAttribute->attribute( 'data_type_string' );

				if ($dataTypeString == "ezimage")
				{
					 eZImageAliasHandler::removeAllAliases( $contentObjectAttribute );
	 				$cli->output("deleting image");
				}
			}		    	
			$db = eZDB::instance();
			$db->begin();
			$version->removeThis();
			$cli->output("removing version ".$versionID);
			$db->commit();
		}
	}
	$objectVersions = $eZObject->versions();
	$cli->output(count($objectVersions)." versions remaining. Current version is ".$objectVersionID);
}

Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.

Heath

Tuesday 02 June 2009 9:02:03 am

Sebastiaan,

I would recommend creating a new issue in the issue tracker to add this functionality into the default ezpublish releases. This seems like something that should be available by default.

Cheers,
Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.