Skip to content

Commit

Permalink
Merge pull request #83 from crevillo/updatecontenobjectname-work
Browse files Browse the repository at this point in the history
Updatecontenobjectname work
  • Loading branch information
lolautruche committed Jun 23, 2011
2 parents 22802f1 + 1939d8b commit 745c07b
Showing 1 changed file with 75 additions and 57 deletions.
132 changes: 75 additions & 57 deletions update/common/scripts/updatecontentobjectname.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,50 @@
set_time_limit( 0 );

$cli = eZCLI::instance();
$script = eZScript::instance( array( 'debug-message' => '',
'use-session' => true,
'use-modules' => true,
'use-extensions' => true ) );
$script = eZScript::instance(
array(
'debug-message' => '',
'use-session' => true,
'use-modules' => true,
'use-extensions' => true
)
);

$script->startup();

$endl = $cli->endlineString();
$webOutput = $cli->isWebOutput();

function help()
{
$argv = $_SERVER['argv'];
$cli = eZCLI::instance();
$cli->output( "Usage: " . $argv[0] . " [OPTION]...\n" .
"eZ Publish content object name update.\n" .
"Goes trough all objects and updates all content object names\n" .
"\n" .
"General options:\n" .
" -h,--help display this help and exit \n" .
" -q,--quiet do not give any output except when errors occur\n" .
" -s,--siteaccess selected siteaccess for operations, if not specified default siteaccess is used\n" .
" -d,--debug display debug output at end of execution\n" .
" --db-host=HOST Use database host HOST\n" .
" --db-user=USER Use database user USER\n" .
" --db-password=PWD Use database password PWD\n" .
" --db-database=DB Use database named DB\n" .
" --db-driver=DRIVER Use database driver DRIVER\n" .
" -c,--colors display output using ANSI colors\n" .
" --sql display sql queries\n" .
" --logfiles create log files\n" .
" --no-logfiles do not create log files (default)\n" .
" --no-colors do not use ANSI coloring (default)\n" );
$cli->output(
"Usage: " . $argv[0] . " [OPTION]...\n" .
"eZ Publish content object name update.\n" .
"Goes trough all objects and updates all content object names\n" .
"\n" .
"General options:\n" .
" -h,--help display this help and exit \n" .
" -q,--quiet do not give any output except when errors occur\n" .
" -s,--siteaccess selected siteaccess for operations, if not specified default siteaccess is used\n" .
" -d,--debug display debug output at end of execution\n" .
" --db-host=HOST Use database host HOST\n" .
" --db-user=USER Use database user USER\n" .
" --db-password=PWD Use database password PWD\n" .
" --db-database=DB Use database named DB\n" .
" --db-driver=DRIVER Use database driver DRIVER\n" .
" -c,--colors display output using ANSI colors\n" .
" --sql display sql queries\n" .
" --logfiles create log files\n" .
" --no-logfiles do not create log files (default)\n" .
" --no-colors do not use ANSI coloring (default)\n"
);
}

function changeSiteAccessSetting( &$siteaccess, $optionData )
{
$ini = eZINI::instance();
$cli = eZCLI::instance();
$availableSiteAccessList = $ini->variable( 'SiteAccessSettings', 'AvailableSiteAccessList' );
if ( in_array( $optionData, $availableSiteAccessList ) )
if ( in_array( $optionData, eZINI::instance()->variable( 'SiteAccessSettings', 'AvailableSiteAccessList' ) ) )
{
$siteaccess = $optionData;
$cli->output( "Using siteaccess $siteaccess for content object name update" );
Expand Down Expand Up @@ -88,12 +91,9 @@ function changeSiteAccessSetting( &$siteaccess, $optionData )
for ( $i = 1; $i < count( $argv ); ++$i )
{
$arg = $argv[$i];
if ( $readOptions and
strlen( $arg ) > 0 and
$arg[0] == '-' )
if ( $readOptions && strlen( $arg ) > 0 && $arg[0] == '-' )
{
if ( strlen( $arg ) > 1 and
$arg[1] == '-' )
if ( strlen( $arg ) > 1 && $arg[1] == '-' )
{
$flag = substr( $arg, 2 );
if ( in_array( $flag, $longOptionsWithData ) )
Expand Down Expand Up @@ -239,6 +239,7 @@ function changeSiteAccessSetting( &$siteaccess, $optionData )
}
}
}

$script->setUseDebugOutput( $debugOutput );
$script->setAllowedDebugLevels( $allowedDebugLevels );
$script->setUseDebugAccumulators( $useDebugAccumulators );
Expand All @@ -250,22 +251,19 @@ function changeSiteAccessSetting( &$siteaccess, $optionData )
$useColors = true;

$cli->setUseStyles( $useColors );
$script->setDebugMessage( "\n\n" . str_repeat( '#', 36 ) . $cli->style( 'emphasize' ) . " DEBUG " . $cli->style( 'emphasize-end' ) . str_repeat( '#', 36 ) . "\n" );

$script->setDebugMessage( "\n\n" . str_repeat( '#', 36 ) . $cli->style( 'emphasize' ) . " DEBUG " . $cli->style( 'emphasize-end' ) . str_repeat( '#', 36 ) . "\n" );
$script->setUseSiteAccess( $siteaccess );

$script->initialize();

print( "Updating content object names\n" );

//eZDebug::setHandleType( eZDebug::HANDLE_FROM_PHP );
$cli->output( "Updating content object names" );

// eZModule::setGlobalPathList( array( "kernel" ) );
eZExecution::registerShutdownHandler( );

$db = eZDB::instance();

if ( $dbHost or $dbName or $dbUser or $dbImpl )
if ( $dbHost || $dbName || $dbUser || $dbImpl )
{
$params = array();
if ( $dbHost !== false )
Expand All @@ -285,30 +283,44 @@ function changeSiteAccessSetting( &$siteaccess, $optionData )

$db->setIsSQLOutputEnabled( $showSQL );

// Get top node
$topNodeArray = eZPersistentObject::fetchObjectList( eZContentObjectTreeNode::definition(),
null,
array( 'parent_node_id' => 1,
'depth' => 1 ) );
// Get top nodes
$topNodeArray = eZPersistentObject::fetchObjectList(
eZContentObjectTreeNode::definition(),
null,
array(
'parent_node_id' => 1,
'depth' => 1
)
);

$subTreeCount = 0;
foreach ( array_keys ( $topNodeArray ) as $key )
foreach ( $topNodeArray as $node )
{
$subTreeCount += $topNodeArray[$key]->subTreeCount( array( 'Limitation' => false ) );
$subTreeCount += $node->subTreeCount(
array(
'Limitation' => array()
)
);
}

print( "Number of objects to update: $subTreeCount $endl" );
$cli->output( "Number of objects to update: $subTreeCount" );

$i = 0;
$dotMax = 70;
$dotCount = 0;
$limit = 50;

foreach ( array_keys ( $topNodeArray ) as $key )
foreach ( $topNodeArray as $node )
{
$node =& $topNodeArray[$key];
$offset = 0;
$subTree =& $node->subTree( array( 'Offset' => $offset, 'Limit' => $limit,
'Limitation' => array() ) );
$subTree = $node->subTree(
array(
'Offset' => $offset,
'Limit' => $limit,
'Limitation' => array()
)
);

while ( $subTree != null )
{
foreach ( $subTree as $innerNode )
Expand All @@ -323,23 +335,29 @@ function changeSiteAccessSetting( &$siteaccess, $optionData )
// show progress bar
++$i;
++$dotCount;
print( "." );
if ( $dotCount >= $dotMax or $i >= $subTreeCount )
$cli->output( '.', false );
if ( $dotCount >= $dotMax || $i >= $subTreeCount )
{
$dotCount = 0;
$percent = (float)( ($i*100.0) / $subTreeCount );
print( " " . $percent . "%" . $endl );
$percent = number_format( ( $i * 100.0 ) / $subTreeCount, 2 );
$cli->output( " " . $percent . "%" );
}
}
$offset += $limit;
unset( $subTree );
$subTree =& $node->subTree( array( 'Offset' => $offset, 'Limit' => $limit,
'Limitation' => array() ) );
$subTree = $node->subTree(
array(
'Offset' => $offset,
'Limit' => $limit,
'Limitation' => array()
)
);
}
}

print( $endl . "done" . $endl );
$cli->output( "done" );

$script->shutdown();

?>

0 comments on commit 745c07b

Please sign in to comment.