punknroll

Untitled

Feb 2nd, 2017
183
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env php
  2. <?php
  3. // useage:
  4. // php extension/myextension/bin/php/changeProductsOnlyEnglish.php 2 --siteaccess=administration
  5.  
  6. require 'autoload.php';
  7.  
  8. $cli = eZCLI::instance();
  9. $script = eZScript::instance(
  10.     array(
  11.         'description' => (
  12.             "This script sets the main language to english\n\n" .
  13.             "parent node_id of subtree\n"
  14.         ),
  15.         'use-session' => false,
  16.         'use-modules' => true,
  17.         'use-extensions' => true
  18.     )
  19. );
  20.  
  21. $script->startup();
  22. $options = $script->getOptions(
  23.     "",
  24.     "[node]",
  25.     array(
  26.         'node' => 'parent node_id of subtree'
  27.     ),
  28.     false,
  29.     array( 'user' => true )
  30. );
  31. $script->initialize();
  32.  
  33. if ( count( $options['arguments'] ) < 1 )
  34. {
  35.     $cli->error( "Need a parent node of the subtree " );
  36.     $script->shutdown( 1 );
  37. }
  38. eZUser::setCurrentlyLoggedInUser( eZUser::fetch( 14 ), 14 );
  39. $nodeID = $options['arguments'][0];
  40.  
  41. $nodes = eZContentObjectTreeNode::subTreeByNodeID(
  42.     array(
  43.         'ClassFilterType' => 'include',
  44.         'ClassFilterArray' => array( 'myclassidentifier' ),
  45.         'Depth'       => false,
  46.         'Limitation'  => array(),
  47.         'LoadDataMap' => false,
  48.         'AsObject'    => true
  49.     ),
  50.     $nodeID
  51. );
  52. if ( !count( $nodes ) )
  53. {
  54.     $cli->output( "no childnodes to examine. Maybe you forgot the --sitaccess=administration option?" );
  55. }
  56.  
  57. $cli->output( "Use nodeID ".$nodeID );
  58. // Language to keep
  59. $englishLanguageId = eZContentLanguage::idByLocale( 'eng-GB' );
  60.  
  61. $productCount = sizeof( $nodes );
  62. $langsToDelete = array();
  63.  
  64. for ( $i = 0; $i < $productCount; $i++ )
  65. {
  66.     $langsToDelete = array();
  67.     $product = $nodes[$i];
  68.     $object = $product->object();
  69.  
  70.     // set primary language to language to keep
  71.     $object->setAttribute( 'initial_language_id', $englishLanguageId );
  72.     $object->store();
  73.     $parameters = array(
  74.         'object_id' => $object->attribute( 'id' ),
  75.         'new_initial_language_id' => $englishLanguageId,
  76.         'node_id' => $product->attribute( 'node_id' )
  77.     );
  78.     $myres = eZOperationHandler::execute( 'content', 'updateinitiallanguage', $parameters );
  79.  
  80.     $languages = $object->languages();
  81.     foreach ( $languages as $languageObject )
  82.     {
  83.         // Keep defined language
  84.         if ( $languageObject->attribute( 'id' ) != $englishLanguageId )
  85.         {
  86.             $langsToDelete[] = $languageObject->attribute( 'id' );
  87.         }
  88.     }
  89.     if ( count( $langsToDelete ) )
  90.     {
  91.         $parameters = array(
  92.             'object_id' => $object->attribute( 'id' ),
  93.             'language_id_list' => $langsToDelete,
  94.             'node_id' => $product->attribute( 'node_id' )
  95.         );
  96.         $myres = eZOperationHandler::execute( 'content', 'removetranslation', $parameters );
  97.  
  98.         $cli->output( $object->attribute( 'name' )." contentobject_id: ".$object->attribute( 'id' )."node_id".$product->attribute( 'node_id' ).": ".print_r( $langsToDelete )."\n" );
  99.     }
  100. }
  101.  
  102. $script->shutdown();
  103. ?>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×