Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented EZP-20787: fiximagesoutsidevardir improvements #623

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions update/common/scripts/5.1/fiximagesoutsidevardir.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* database references to the new path
*/

require 'autoload.php';
require_once 'autoload.php';

$cli = eZCLI::instance();

Expand Down Expand Up @@ -62,6 +62,8 @@

foreach ( $rows as $row )
{
$moveFile = true;

$filePath = $row['filepath'];
$imageAttributeId = $row['contentobject_attribute_id'];
$cli->output( "- $filePath" );
Expand All @@ -72,15 +74,27 @@
strpos( $filePath, 'storage/images/' )
);

$newPath = $varDir . $relativePath;

if ( !$clusterHandler->fileExists( $filePath ) )
{
$cli->output( " File doesn't exist, skipping" );
continue;
if ( $clusterHandler->fileExists( $newPath ) )
{
$moveFile = false;
$cli->output( " File is already in the correct directory, updating references" );
}
else
{
$cli->output( " File doesn't exist, skipping" );
continue;
}
}
else
{
$cli->output( " Moving file to $newPath" );
}

$newPath = $varDir . $relativePath;
$cli->output( " Moving file to $newPath" );
if ( !$optDryRun )
if ( !$optDryRun && $moveFile )
{
$clusterHandler->fileMove( $filePath, $newPath );
$db->query( "UPDATE ezimagefile SET filepath = '$newPath' WHERE contentobject_attribute_id = $imageAttributeId" );
Expand All @@ -93,7 +107,7 @@
$renamedFiles[$imageAttributeId][$filePath] = $newPath;
}

foreach( $renamedFiles as $attributeId => $files )
foreach ( $renamedFiles as $attributeId => $files )
{
$attributeObjects = eZContentObjectAttribute::fetchObjectList(
eZContentObjectAttribute::definition(),
Expand Down Expand Up @@ -139,17 +153,3 @@

eZContentCacheManager::clearAllContentCache();
$script->shutdown();

/**
* Updates the image node $node that references $oldPath to reference $newPath (url & dirpath attributes)
*/
function updateDomImage( DOMNode $node, $oldPath, $newPath )
{
if ( $node->getAttribute( 'url' ) == $oldPath )
{
$node->setAttribute( 'url', $newPath );
$node->setAttribute( 'dirpath', dirname( $newPath ) );
return true;
}
return false;
}