[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/update/common/scripts/ -> updatetranslations.php (source)

   1  #!/usr/bin/env php
   2  <?php
   3  //
   4  // Created on: <23-Sep-2003 15:47:14 amos>
   5  //
   6  // SOFTWARE NAME: eZ publish
   7  // SOFTWARE RELEASE: 3.9.0
   8  // BUILD VERSION: 17785
   9  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  10  // SOFTWARE LICENSE: GNU General Public License v2.0
  11  // NOTICE: >
  12  //   This program is free software; you can redistribute it and/or
  13  //   modify it under the terms of version 2.0  of the GNU General
  14  //   Public License as published by the Free Software Foundation.
  15  //
  16  //   This program is distributed in the hope that it will be useful,
  17  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  18  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19  //   GNU General Public License for more details.
  20  //
  21  //   You should have received a copy of version 2.0 of the GNU General
  22  //   Public License along with this program; if not, write to the Free
  23  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  24  //   MA 02110-1301, USA.
  25  //
  26  //
  27  
  28  /*! \file updatetranslations.php
  29  */
  30  
  31  set_time_limit( 0 );
  32  
  33  include_once ( 'lib/ezutils/classes/ezcli.php' );
  34  include_once ( 'kernel/classes/ezscript.php' );
  35  
  36  $cli =& eZCLI::instance();
  37  $endl = $cli->endlineString();
  38  
  39  $script =& eZScript::instance( array( 'description' => ( "eZ publish update of translations.\n\n".
  40                                                           "Will go over objects and reinitialize attributes for missing translations" .
  41                                                           "\n" .
  42                                                           "updatetranslations.php" ),
  43                                        'use-session' => true,
  44                                        'use-modules' => true,
  45                                        'use-extensions' => true ) );
  46  
  47  $script->startup();
  48  
  49  $options = $script->getOptions( "[sql]",
  50                                  "",
  51                                  array( 'sql' => "Display sql queries"
  52                                         ) );
  53  $script->initialize();
  54  
  55  $showSQL = $options['sql'] ? true : false;
  56  $siteAccess = $options['siteaccess'] ? $options['siteaccess'] : false;
  57  
  58  if ( $siteAccess )
  59  {
  60      changeSiteAccessSetting( $siteaccess, $siteAccess );
  61  }
  62  
  63  function changeSiteAccessSetting( &$siteaccess, $optionData )
  64  {
  65      global $isQuiet;
  66      $cli =& eZCLI::instance();
  67      if ( file_exists( 'settings/siteaccess/' . $optionData ) )
  68      {
  69          $siteaccess = $optionData;
  70          if ( !$isQuiet )
  71              $cli->notice( "Using siteaccess $siteaccess for translation update" );
  72      }
  73      else
  74      {
  75          if ( !$isQuiet )
  76              $cli->notice( "Siteaccess $optionData does not exist, using default siteaccess" );
  77      }
  78  }
  79  
  80  include_once ( 'kernel/classes/ezcontentclassattribute.php' );
  81  include_once ( 'kernel/classes/ezcontentobjectattribute.php' );
  82  include_once ( 'kernel/classes/ezcontentobject.php' );
  83  include_once ( 'kernel/classes/ezbinaryfilehandler.php' );
  84  include_once ( 'kernel/classes/datatypes/ezbinaryfile/ezbinaryfile.php' );
  85  
  86  include_once ( 'lib/ezdb/classes/ezdb.php' );
  87  
  88  $db =& eZDB::instance();
  89  $db->setIsSQLOutputEnabled( $showSQL );
  90  
  91  $attributeList =& eZContentClassAttribute::fetchList( true, array( 'version' => 0 ) );
  92  
  93  $classAttributeIDList = array();
  94  $classDataTypeList = array();
  95  
  96  $complexTypes = array();
  97  
  98  $objectCount = eZContentObject::fetchListCount();
  99  
 100  $cli->output( "Going to update " . $cli->stylize( 'emphasize', $objectCount ) . " objects" );
 101  
 102  $maxFetch = 30;
 103  $index = 0;
 104  $column = 0;
 105  
 106  $script->setIterationData( '.', '~', array( '.', '~', '*', '#' ), false );
 107  $script->resetIteration( $objectCount );
 108  
 109  while ( $index < $objectCount )
 110  {
 111      $objectList = eZContentObject::fetchList( true, null, $index, $maxFetch );
 112      foreach ( array_keys( $objectList ) as $objectKey )
 113      {
 114          $object =& $objectList[$objectKey];
 115  
 116          $currentVersion = $object->currentVersion();
 117  
 118          if ( !is_object( $currentVersion ) )
 119          {
 120              $script->iterate( $cli, 0, "Object " . $object->attribute( 'id' ) . " does not have a current version, skipping" );
 121              ++$index;
 122              continue;
 123          }
 124  
 125          $versions =& $object->versions();
 126          $classAttributes = & eZContentClassAttribute::fetchListByClassID( $object->attribute( 'contentclass_id' ) );
 127  
 128          $updated = false;
 129          $allFixed = true;
 130          foreach ( array_keys( $versions ) as $versionKey )
 131          {
 132              $version =& $versions[$versionKey];
 133              $translations = $version->translationList( false, false );
 134              foreach ( $translations as $languageCode )
 135              {
 136                  $attributes =& $version->contentObjectAttributes( $languageCode );
 137  
 138                  foreach ( $classAttributes as $classAttribute )
 139                  {
 140                      $attributeExist = false;
 141                      $classAttributeID = $classAttribute->attribute( 'id' );
 142  
 143                      //check to see if this attribute is among the attributes for the translation
 144                      foreach ( $attributes as $attribute )
 145                      {
 146                          $attributeID = $attribute->attribute( "contentclassattribute_id" );
 147                          if ( $attributeID == $classAttributeID )
 148                          {
 149                              $attributeExist = true;
 150                          }
 151                      }
 152  
 153                      //if not, we create the missing attributes
 154                      if ( !$attributeExist )
 155                      {
 156                          $versionNumber = $version->attribute( 'version' );
 157  
 158                          //this initilizes the new translated attribute with values from the original attribute
 159                          //uncomment to create 'empty' attributes instead (also change the initialize command below)
 160  
 161                          $orgAttributes =& $version->contentObjectAttributes();
 162                          foreach ( $orgAttributes as $orgAttribute )
 163                          {
 164                              if ( $classAttributeID == $orgAttribute->attribute( 'contentclassattribute_id' ) )
 165                                  break;
 166                              $orgAttribute = null;
 167                          }
 168  
 169                          if ( !$classAttribute->attribute( 'can_translate' ) )
 170                              $orgAttribute = null;
 171  
 172                          $objectAttribute = eZContentObjectAttribute::create( $classAttributeID, $object->attribute( 'id' ), $versionNumber );
 173                          $objectAttribute->setAttribute( 'language_code', $languageCode );
 174                          $objectAttribute->initialize( $versionNumber, $orgAttribute );
 175                          $objectAttribute->store();
 176                      }
 177                  }
 178  
 179                  foreach ( array_keys( $attributes ) as $attributeKey )
 180                  {
 181                      $attribute =& $attributes[$attributeKey];
 182                      $dataType = $attribute->dataType();
 183                      $status = $dataType->repairContentObjectAttribute( $attribute );
 184                      if ( $status === true )
 185                      {
 186                          $updated = true;
 187                          $attribute->store();
 188                      }
 189                      else if ( $status === false )
 190                      {
 191                          $updated = true;
 192                          $allFixed = false;
 193                      }
 194                  }
 195              }
 196          }
 197          if ( $updated )
 198          {
 199              $script->iterate( $cli, $allFixed ? 2 : 3, "Object " . $object->attribute( 'id' ) . " was updated" );
 200          }
 201          else
 202          {
 203              $script->iterate( $cli, 1, "Object " . $object->attribute( 'id' ) . " did not require an update" );
 204          }
 205          ++$index;
 206      }
 207  }
 208  
 209  $script->shutdown();
 210  
 211  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7