diff --git a/kernel/classes/datatypes/ezimage/ezimagealiashandler.php b/kernel/classes/datatypes/ezimage/ezimagealiashandler.php index a3f95a88c81..de3d3152b58 100644 --- a/kernel/classes/datatypes/ezimage/ezimagealiashandler.php +++ b/kernel/classes/datatypes/ezimage/ezimagealiashandler.php @@ -653,10 +653,10 @@ static function removeAllAliases( $contentObjectAttribute ) return; } $attributeData = $handler->originalAttributeData(); - + $files = eZImageFile::fetchForContentObjectAttribute( $attributeData['attribute_id'], false ); $dirs = array(); - foreach ( eZImageFile::fetchRemovableImagesFromObjectAttribute( $attributeData['attribute_id'] ) as $filepath ) + foreach ( $files as $filepath ) { $file = eZClusterFileHandler::instance( $filepath ); if ( $file->exists() ) diff --git a/kernel/classes/datatypes/ezimage/ezimagefile.php b/kernel/classes/datatypes/ezimage/ezimagefile.php index 404cfb534b3..717a5700480 100644 --- a/kernel/classes/datatypes/ezimage/ezimagefile.php +++ b/kernel/classes/datatypes/ezimage/ezimagefile.php @@ -73,71 +73,6 @@ static function fetchForContentObjectAttribute( $contentObjectAttributeID, $asOb return $rows; } - /** - * Returns images that are safe for removal for a specific $contentObjectAttributeID - * - * The ezimagefile table references in which attributes image files are used. This function returns - * for a given $contentObjectAttributeID, the list of image files solely owned it. - * - * @param int $contentObjectAttributeID Content object acctribute ID - * - * @return array - */ - public static function fetchRemovableImagesFromObjectAttribute( $contentObjectAttributeID ) - { - $result = array(); - - foreach ( - eZDB::instance()->arrayQuery( - "SELECT i1.filepath ". - "FROM ezimagefile AS i1 ". - "LEFT JOIN ezimagefile AS i2 ON i1.filepath = i2.filepath AND i1.id < i2.id ". - "WHERE i1.contentobject_attribute_id = " . (int)$contentObjectAttributeID . " AND i2.contentobject_attribute_id IS NULL" - ) as $row - ) - { - $result[] = $row["filepath"]; - } - - return $result; - } - - /** - * Performs possible cleanup after an update to the alias path is performed. - * - * @param eZContentObjectAttribute $contentObjectAttribute - */ - public static function cleanupDataAfterAliasPathUpdate( eZContentObjectAttribute $contentObjectAttribute ) - { - $urlSet = array(); - $db = eZDB::instance(); - $contentObjectAttributeId = (int)$contentObjectAttribute->attribute( "id" ); - - foreach ( - $db->arrayQuery( - "SELECT data_text FROM ezcontentobject_attribute WHERE id = " . $contentObjectAttributeId - ) as $row - ) - { - foreach ( simplexml_load_string( $row["data_text"] )->xpath( "//*/@url" ) as $url ) - { - $url = (string)$url; - - if ( $url === "" ) - continue; - - // generateSQLINStatement does not add quotes when casting to string - $urlSet["'" . $db->escapeString( (string)$url ) . "'"] = true; - } - } - - $db->query( - "DELETE FROM ezimagefile ". - "WHERE contentobject_attribute_id = $contentObjectAttributeId AND " . - $db->generateSQLINStatement( array_keys( $urlSet ), "filepath", true, false, "string" ) - ); - } - /** * Looks up ezcontentobjectattribute entries matching an image filepath and * a contentobjectattribute ID @@ -239,7 +174,8 @@ static function appendFilepath( $contentObjectAttributeID, $filepath, $ignoreUni $fileObject = eZImageFile::fetchByFilepath( $contentObjectAttributeID, $filepath ); if ( $fileObject ) return false; - + $fileObject = eZImageFile::create( $contentObjectAttributeID, $filepath ); + $fileObject->store(); return true; } diff --git a/kernel/classes/datatypes/ezimage/ezimagetype.php b/kernel/classes/datatypes/ezimage/ezimagetype.php index 83036b2f9db..1fd87ad49dd 100644 --- a/kernel/classes/datatypes/ezimage/ezimagetype.php +++ b/kernel/classes/datatypes/ezimage/ezimagetype.php @@ -333,25 +333,6 @@ function storeObjectAttribute( $contentObjectAttribute ) } } - public function postStore( $objectAttribute ) - { - $objectAttributeId = $objectAttribute->attribute( "id" ); - - if ( ( $doc = simplexml_load_string( $objectAttribute->attribute( "data_text" ) ) ) === false ) - return; - - // Creates ezimagefile entries - foreach ( $doc->xpath( "//*/@url" ) as $url ) - { - $url = (string)$url; - - if ( $url === "" ) - continue; - - eZImageFile::create( $objectAttributeId, $url )->store(); - } - } - /*! HTTP file insertion is supported. */ @@ -453,7 +434,6 @@ function onPublish( $contentObjectAttribute, $contentObject, $publishedNodes ) { $imageHandler = $contentObjectAttribute->attribute( 'content' ); $mainNode = false; - $cleanupNeeded = false; foreach ( array_keys( $publishedNodes ) as $publishedNodeKey ) { $publishedNode = $publishedNodes[$publishedNodeKey]; @@ -471,18 +451,12 @@ function onPublish( $contentObjectAttribute, $contentObject, $publishedNodes ) { $name = $imageHandler->imageNameByNode( $contentObjectAttribute, $mainNode ); $imageHandler->updateAliasPath( $dirpath, $name ); - $cleanupNeeded = true; } } if ( $imageHandler->isStorageRequired() ) { $imageHandler->store( $contentObjectAttribute ); $contentObjectAttribute->store(); - - if ( $cleanupNeeded ) - { - eZImageFile::cleanupDataAfterAliasPathUpdate( $contentObjectAttribute ); - } } } } diff --git a/update/database/mysql/5.2/dbupdate-5.1.0-to-5.2.0.sql b/update/database/mysql/5.2/dbupdate-5.1.0-to-5.2.0.sql index 1ca0cffb45e..db809bdaac1 100644 --- a/update/database/mysql/5.2/dbupdate-5.1.0-to-5.2.0.sql +++ b/update/database/mysql/5.2/dbupdate-5.1.0-to-5.2.0.sql @@ -81,20 +81,6 @@ SET o.language_mask = (o.language_mask & 1) | (v.language_mask & ~1); -- End EZP-21469 --- Start EZP-21324: --- Cleanup extra lines in the ezimagefile table in order to create the unique key: -DELETE i1 -FROM - ezimagefile i1 -INNER JOIN - ezimagefile i2 ON i1.contentobject_attribute_id = i2.contentobject_attribute_id AND i1.filepath = i2.filepath -WHERE - i1.id > i2.id; - --- Create the unique key: -CREATE UNIQUE INDEX ezimagefile_co_attr_id_filepath ON ezimagefile (contentobject_attribute_id, filepath(255)); --- End EZP-21324 - -- Start EZP-21648: -- Adding 'priority' and 'is_hidden' columns to the 'eznode_assignment' table ALTER TABLE eznode_assignment ADD COLUMN priority int(11) NOT NULL DEFAULT '0'; diff --git a/update/database/postgresql/5.2/dbupdate-5.1.0-to-5.2.0.sql b/update/database/postgresql/5.2/dbupdate-5.1.0-to-5.2.0.sql index 7ba54b6c752..db1f9e5c07b 100644 --- a/update/database/postgresql/5.2/dbupdate-5.1.0-to-5.2.0.sql +++ b/update/database/postgresql/5.2/dbupdate-5.1.0-to-5.2.0.sql @@ -68,19 +68,6 @@ WHERE o.id = v.contentobject_id AND o.current_version = v.version; -- End EZP-21469 --- Start EZP-21324: --- Cleanup extra lines in the ezimagefile table in order to create the unique key: -DELETE FROM - ezimagefile i1 -USING - ezimagefile i2 -WHERE - i1.contentobject_attribute_id = i2.contentobject_attribute_id AND i1.filepath = i2.filepath AND i1.id > i2.id; - --- Create the unique key: -CREATE UNIQUE INDEX ezimagefile_co_attr_id_filepath ON ezimagefile USING btree (contentobject_attribute_id, filepath); --- End EZP-21324 - -- Start EZP-21648: -- Adding 'priority' and 'is_hidden' columns to the 'eznode_assignment' table ALTER TABLE eznode_assignment ADD priority integer DEFAULT 0 NOT NULL;