[ 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/ -> updateattributefilter.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 updatexmltext.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 attribute filter update.".
  40                                                           "\n" .
  41                                                           "updateattributefileter.php" ),
  42                                        'use-session' => true,
  43                                        'use-modules' => true,
  44                                        'use-extensions' => true ) );
  45  
  46  $script->startup();
  47  
  48  $options = $script->getOptions( "[sql]",
  49                                  "",
  50                                  array( 'sql' => "Display sql queries"
  51                                         ) );
  52  $script->initialize();
  53  
  54  $showSQL = $options['sql'] ? true : false;
  55  $siteAccess = $options['siteaccess'] ? $options['siteaccess'] : false;
  56  
  57  if ( $siteAccess )
  58  {
  59      changeSiteAccessSetting( $siteaccess, $siteAccess );
  60  }
  61  
  62  function changeSiteAccessSetting( &$siteaccess, $optionData )
  63  {
  64      global $isQuiet;
  65      $cli =& eZCLI::instance();
  66      if ( file_exists( 'settings/siteaccess/' . $optionData ) )
  67      {
  68          $siteaccess = $optionData;
  69          if ( !$isQuiet )
  70              $cli->notice( "Using siteaccess $siteaccess for xml text field update" );
  71      }
  72      else
  73      {
  74          if ( !$isQuiet )
  75              $cli->notice( "Siteaccess $optionData does not exist, using default siteaccess" );
  76      }
  77  }
  78  
  79  include_once ( 'kernel/classes/ezcontentclassattribute.php' );
  80  include_once ( 'kernel/classes/ezcontentobjectattribute.php' );
  81  include_once ( 'kernel/classes/ezcontentobject.php' );
  82  include_once ( 'kernel/classes/ezbinaryfilehandler.php' );
  83  include_once ( 'kernel/classes/datatypes/ezbinaryfile/ezbinaryfile.php' );
  84  
  85  include_once ( 'lib/ezdb/classes/ezdb.php' );
  86  include_once ( 'kernel/classes/datatypes/ezurl/ezurl.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  // A list of datatypes which we know to have simple values and the field they use
  97  $simpleTypes = array( array( 'field' => 'data_int',
  98                               'sort_field' => 'sort_key_int',
  99                               'datatypes' => array( 'ezinteger', 'ezboolean', 'ezdate', 'ezdatetime', 'ezobjectrelation' ) ),
 100                        array( 'field' => 'data_text',
 101                               'sort_field' => 'sort_key_string',
 102                               'datatypes' => array( 'ezstring', 'ezemail' ) ) );
 103  
 104  $complexTypes = array();
 105  
 106  for ( $i = 0; $i < count( $attributeList ); ++$i )
 107  {
 108      $attribute =& $attributeList[$i];
 109      $classDataTypeString = $attribute->attribute( 'data_type_string' );
 110      if ( !isset( $classDataTypeList[$classDataTypeString] ) )
 111      {
 112          $classDataType =& $attribute->attribute( 'data_type' );
 113          $sortKeyType = $classDataType->sortKeyType();
 114          if ( $sortKeyType )
 115          {
 116              $classDataTypeList[$classDataTypeString] = array( 'sort_key_type' => $sortKeyType );
 117          }
 118          else
 119              $classDataTypeList[$classDataTypeString] = false;
 120      }
 121      if ( $classDataTypeList[$classDataTypeString] )
 122      {
 123          $isSimpleType = false;
 124          foreach ( $simpleTypes as $simpleTypeKey => $simpleType )
 125          {
 126              if ( in_array( $classDataTypeString, $simpleType['datatypes'] ) )
 127              {
 128                  $isSimpleType = true;
 129                  if ( !isset( $simpleTypes[$simpleTypeKey]['id_list'] ) )
 130                      $simpleTypes[$simpleTypeKey]['id_list'] = array();
 131                  $simpleTypes[$simpleTypeKey]['id_list'][] = $attribute->attribute( 'id' );
 132                  break;
 133              }
 134          }
 135          if ( !$isSimpleType )
 136          {
 137              if ( !isset( $complexTypes[$classDataTypeString] ) )
 138                  $complexTypes[$classDataTypeString] = array();
 139              $complexTypes[$classDataTypeString][] = $attribute->attribute( 'id' );
 140          }
 141      }
 142  }
 143  unset( $attributeList );
 144  
 145  foreach ( $simpleTypes as $simpleType )
 146  {
 147      $cli->output( "Will update " . count( $simpleType['id_list'] )  ." class attribute(s) for datatype(s) " . implode( ", ", $simpleType['datatypes'] ) . " using field " . $simpleType['field'] );
 148      if ( count( $simpleType['id_list'] ) > 0 )
 149      {
 150          $sortField = $simpleType['sort_field'];
 151          $field = $simpleType['field'];
 152          $db =& eZDB::instance();
 153          $sql = "UPDATE ezcontentobject_attribute SET $sortField=$field WHERE contentclassattribute_id IN (" . implode( ",", $simpleType['id_list'] ) . ")";
 154          $db->query( $sql );
 155      }
 156  }
 157  
 158  foreach ( $complexTypes as $complexTypeString => $complexTypeList )
 159  {
 160      $cli->output( "Will update " . count( $complexTypeList )  ." class attribute(s) for datatype " . $complexTypeString );
 161      $counter = 0;
 162      $column = 0;
 163      $objectAttributeList =& eZContentObjectAttribute::fetchListByClassID( $complexTypeList );
 164      $objectAttributeCount = count( $objectAttributeList );
 165      $cli->output( "Total of " . $objectAttributeCount . " attributes" );
 166      for ( $i = 0; $i < $objectAttributeCount; ++$i )
 167      {
 168          $objectAttribute =& $objectAttributeList[$i];
 169          // re-store the attribute
 170          $objectAttribute->store();
 171          $cli->output( ".", false );
 172          flush();
 173          ++$counter;
 174          ++$column;
 175          if ( $column > 70 or $counter == $objectAttributeCount )
 176          {
 177              $percent = ( $counter * 100 ) / ( $objectAttributeCount );
 178              $percentText = number_format( $percent, 2 );
 179              $cli->output( " $percentText%" );
 180              $column = 0;
 181          }
 182      }
 183      $cli->output();
 184      unset( $objectAttributeList );
 185  }
 186  
 187  $dbName = $db->DB;
 188  $cacheDir = eZSys::cacheDirectory();
 189  
 190  // VS-DBFILE
 191  
 192  require_once ( 'kernel/classes/ezclusterfilehandler.php' );
 193  $cacgeFilePath = "$cacheDir/sortkey_$dbName.php";
 194  $cacheFile = eZClusterFileHandler::instance( $cacheFilePath );
 195  if ( $cacheFile->exists() )
 196  {
 197      // VS-DBFILE : FIXME: optimize not to use recursive delete.
 198      $cacheFile->delete();
 199      $cli->output( 'Removed cache file : ' . $cacheFile );
 200  }
 201  
 202  
 203  // $attributeCount = eZContentObjectAttribute::fetchListByClassID( $classAttributeIDList, false, array( 'offset' => 0,
 204  //                                                                                                      'length' => 3 ),
 205  //                                                                 false, true );
 206  // if ( $showDebug )
 207  //     print( "Attribute count = '$attributeCount'\n" );
 208  
 209  $script->shutdown();
 210  
 211  ?>


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