Skip to content

Instantly share code, notes, and snippets.

@Opencontent
Created November 16, 2017 11:38
Show Gist options
  • Save Opencontent/73611a3a77d5cc3bca0d04bcde896ebd to your computer and use it in GitHub Desktop.
Save Opencontent/73611a3a77d5cc3bca0d04bcde896ebd to your computer and use it in GitHub Desktop.
<?php
require 'autoload.php';
$script = eZScript::instance( array( 'description' => ( 'Download images from endpoint' ),
'use-session' => false,
'use-modules' => true,
'use-extensions' => true ) );
$script->startup();
$options = $script->getOptions( '[url:][vardir:]',
'',
array(
'url' => 'Endpoint url',
'vardir' => 'Remote var directory (eg ezflow_site)'
)
);
$script->initialize();
$script->setUseDebugAccumulators( true );
$cli = eZCLI::instance();
$output = new ezcConsoleOutput();
$query = "SELECT distinct ezcontentobject_version.contentobject_id, COUNT( * ) as qtd FROM ezcontentobject_version WHERE ezcontentobject_version.status = 1 GROUP BY ezcontentobject_version.contentobject_id HAVING count(*) > 1;";
$res = eZDB::instance()->arrayQuery($query);
$objectIdList = array();
foreach ($res as $row) {
$objectIdList[] = $row['contentobject_id'];
}
foreach ($objectIdList as $objectId) {
$query = "SELECT * FROM ezcontentobject_version WHERE contentobject_id = {$objectId} AND status = 1 ORDER BY modified ASC";
$versions = eZDB::instance()->arrayQuery($query);
$object = eZContentObject::fetch($objectId);
if ($object instanceof eZContentObject){
$cli->warning($object->attribute('name'), false);
$current = $object->attribute('current_version');
$cli->warning(" (versione corrente $current)");
if (count($versions) > 1){
foreach ($versions as $version) {
if($version['version'] != $current){
$versionVersion = $version['version'];
$query = "UPDATE ezcontentobject_version SET status = 3 WHERE version = {$versionVersion} AND contentobject_id = {$objectId}";
$cli->notice('Archivio versione ' . $versionVersion);
eZDB::instance()->arrayQuery($query);
}
}
}
}else{
$cli->error("Oggetto non trovato $objectId");
}
}
$script->shutdown();
@Opencontent
Copy link
Author

Copiare in document root di un solo nodo del cluster e lanciare con:
php fix_multi_published_version.php -s001admin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment