Skip to content

Commit

Permalink
Revert "Fixed EZP-21324: Images for original object lost when editing…
Browse files Browse the repository at this point in the history
… copies"

This reverts commit c851f71.
  • Loading branch information
Bertrand Dunogier committed Oct 14, 2013
1 parent 978914c commit 18bcf8e
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 121 deletions.
4 changes: 2 additions & 2 deletions kernel/classes/datatypes/ezimage/ezimagealiashandler.php
Expand Up @@ -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() )
Expand Down
68 changes: 2 additions & 66 deletions kernel/classes/datatypes/ezimage/ezimagefile.php
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
26 changes: 0 additions & 26 deletions kernel/classes/datatypes/ezimage/ezimagetype.php
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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];
Expand All @@ -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 );
}
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions update/database/mysql/5.2/dbupdate-5.1.0-to-5.2.0.sql
Expand Up @@ -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';
Expand Down
13 changes: 0 additions & 13 deletions update/database/postgresql/5.2/dbupdate-5.1.0-to-5.2.0.sql
Expand Up @@ -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;
Expand Down

0 comments on commit 18bcf8e

Please sign in to comment.