Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env php
- <?php
- // useage:
- // php extension/myextension/bin/php/changeProductsOnlyEnglish.php 2 --siteaccess=administration
- require 'autoload.php';
- $cli = eZCLI::instance();
- $script = eZScript::instance(
- array(
- 'description' => (
- "This script sets the main language to english\n\n" .
- "parent node_id of subtree\n"
- ),
- 'use-session' => false,
- 'use-modules' => true,
- 'use-extensions' => true
- )
- );
- $script->startup();
- $options = $script->getOptions(
- "",
- "[node]",
- array(
- 'node' => 'parent node_id of subtree'
- ),
- false,
- array( 'user' => true )
- );
- $script->initialize();
- if ( count( $options['arguments'] ) < 1 )
- {
- $cli->error( "Need a parent node of the subtree " );
- $script->shutdown( 1 );
- }
- eZUser::setCurrentlyLoggedInUser( eZUser::fetch( 14 ), 14 );
- $nodeID = $options['arguments'][0];
- $nodes = eZContentObjectTreeNode::subTreeByNodeID(
- array(
- 'ClassFilterType' => 'include',
- 'ClassFilterArray' => array( 'myclassidentifier' ),
- 'Depth' => false,
- 'Limitation' => array(),
- 'LoadDataMap' => false,
- 'AsObject' => true
- ),
- $nodeID
- );
- if ( !count( $nodes ) )
- {
- $cli->output( "no childnodes to examine. Maybe you forgot the --sitaccess=administration option?" );
- }
- $cli->output( "Use nodeID ".$nodeID );
- // Language to keep
- $englishLanguageId = eZContentLanguage::idByLocale( 'eng-GB' );
- $productCount = sizeof( $nodes );
- $langsToDelete = array();
- for ( $i = 0; $i < $productCount; $i++ )
- {
- $langsToDelete = array();
- $product = $nodes[$i];
- $object = $product->object();
- // set primary language to language to keep
- $object->setAttribute( 'initial_language_id', $englishLanguageId );
- $object->store();
- $parameters = array(
- 'object_id' => $object->attribute( 'id' ),
- 'new_initial_language_id' => $englishLanguageId,
- 'node_id' => $product->attribute( 'node_id' )
- );
- $myres = eZOperationHandler::execute( 'content', 'updateinitiallanguage', $parameters );
- $languages = $object->languages();
- foreach ( $languages as $languageObject )
- {
- // Keep defined language
- if ( $languageObject->attribute( 'id' ) != $englishLanguageId )
- {
- $langsToDelete[] = $languageObject->attribute( 'id' );
- }
- }
- if ( count( $langsToDelete ) )
- {
- $parameters = array(
- 'object_id' => $object->attribute( 'id' ),
- 'language_id_list' => $langsToDelete,
- 'node_id' => $product->attribute( 'node_id' )
- );
- $myres = eZOperationHandler::execute( 'content', 'removetranslation', $parameters );
- $cli->output( $object->attribute( 'name' )." contentobject_id: ".$object->attribute( 'id' )."node_id".$product->attribute( 'node_id' ).": ".print_r( $langsToDelete )."\n" );
- }
- }
- $script->shutdown();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement