[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/bin/php/ -> ezcache.php (source)

   1  #!/usr/bin/env php
   2  <?php
   3  //
   4  // Created on: <19-Jul-2004 10:51:17 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  include_once ( 'lib/ezutils/classes/ezcli.php' );
  29  include_once ( 'kernel/classes/ezscript.php' );
  30  
  31  $cli =& eZCLI::instance();
  32  $script =& eZScript::instance( array( 'description' => ( "eZ publish Cache Handler\n" .
  33                                                           "Allows for easy clearing of Cache files\n" .
  34                                                           "\n" .
  35                                                           "./bin/ezcache.php --clear-tag=content" ),
  36                                        'use-session' => false,
  37                                        'use-modules' => false,
  38                                        'use-extensions' => true ) );
  39  
  40  $script->startup();
  41  
  42  $options = $script->getOptions( "[clear-tag:][clear-id:][clear-all][list-tags][list-ids]",
  43                                  "",
  44                                  array( 'clear-tag' => 'Clears all caches related to a given tag',
  45                                         'clear-id' => 'Clears all caches related to a given id, separate multiple ids with a comma',
  46                                         'clear-all' => 'Clears all caches',
  47                                         'list-tags' => 'Lists all available tags',
  48                                         'list-ids' => 'Lists all available ids' ) );
  49  $sys =& eZSys::instance();
  50  
  51  $script->initialize();
  52  
  53  include_once ( 'kernel/classes/ezcache.php' );
  54  
  55  $cacheList = eZCache::fetchList();
  56  
  57  if ( $options['list-tags'] )
  58  {
  59      $tagList = eZCache::fetchTagList( $cacheList );
  60      if ( $script->verboseOutputLevel() > 0 )
  61      {
  62          $cli->output( "The following tags are defined:" );
  63          $column = 0;
  64          foreach ( $tagList as $tagName )
  65          {
  66              $len = strlen( $tagName );
  67              if ( $len > $column )
  68                  $column = $len;
  69          }
  70          $column += 2;
  71          foreach ( $tagList as $tagName )
  72          {
  73              $cacheEntries = eZCache::fetchByTag( $tagName, $cacheList );
  74              $cli->output( $cli->stylize( 'emphasize', $tagName ) . ':', false );
  75              $i = 0;
  76              foreach ( $cacheEntries as $cacheEntry )
  77              {
  78                  if ( $i > 0 )
  79                      $cli->output( str_repeat( ' ', $column ), false );
  80                  else
  81                      $cli->output( str_repeat( ' ', $column - strlen( $tagName ) - 1 ), false );
  82                  $cli->output( $cacheEntry['name'] );
  83                  ++$i;
  84              }
  85          }
  86      }
  87      else
  88      {
  89          $cli->output( "The following tags are defined: (use --verbose for more details)" );
  90          $cli->output( $cli->stylize( 'emphasize', implode( ', ', $tagList ) ) );
  91      }
  92      return $script->shutdown();
  93  }
  94  
  95  if ( $options['list-ids'] )
  96  {
  97      if ( $script->verboseOutputLevel() > 0 )
  98      {
  99          $cli->output( "The following ids are defined:" );
 100          $column = 0;
 101          foreach ( $cacheList as $cacheInfo )
 102          {
 103              $len = strlen( $cacheInfo['id'] );
 104              if ( $len > $column )
 105                  $column = $len;
 106          }
 107          $column += 2;
 108          foreach ( $cacheList as $cacheInfo )
 109          {
 110              $cli->output( $cli->stylize( 'emphasize', $cacheInfo['id'] ) . ':', false );
 111              $cli->output( str_repeat( ' ', $column - strlen( $cacheInfo['id'] ) - 1 ), false );
 112              $cli->output( $cacheInfo['name'] );
 113          }
 114      }
 115      else
 116      {
 117          $idList = eZCache::fetchIDList( $cacheList );
 118          $cli->output( "The following ids are defined: (use --verbose for more details)" );
 119          $cli->output( $cli->stylize( 'emphasize', implode( ', ', $idList ) ) );
 120      }
 121      return $script->shutdown();
 122  }
 123  
 124  if ( $options['clear-all'] )
 125  {
 126      $cli->output( 'Clearing : ', false );
 127      $i = 0;
 128      foreach ( $cacheList as $cacheEntry )
 129      {
 130          if ( $i > 0 )
 131              $cli->output( ', ', false );
 132          $cli->output( $cli->stylize( 'emphasize', $cacheEntry['name'] ), false );
 133          eZCache::clearItem( $cacheEntry );
 134          ++$i;
 135      }
 136      $cli->output();
 137      return $script->shutdown();
 138  }
 139  
 140  if ( $options['clear-tag'] )
 141  {
 142      $tagName = $options['clear-tag'];
 143      $cacheEntries = eZCache::fetchByTag( $tagName, $cacheList );
 144      $cli->output( 'Clearing ' . $cli->stylize( 'emphasize', $tagName ) . ': ', false );
 145      $i = 0;
 146      foreach ( $cacheEntries as $cacheEntry )
 147      {
 148          if ( $i > 0 )
 149              $cli->output( ', ', false );
 150          $cli->output( $cli->stylize( 'emphasize', $cacheEntry['name'] ), false );
 151          eZCache::clearItem( $cacheEntry );
 152          ++$i;
 153      }
 154      $cli->output();
 155  }
 156  
 157  if ( $options['clear-id'] )
 158  {
 159      $idName = $options['clear-id'];
 160      $idList = explode( ',', $idName );
 161      $missingIDList = array();
 162      $cacheEntries = array();
 163      foreach ( $idList as $id )
 164      {
 165          $cacheEntry = eZCache::fetchByID( $id, $cacheList );
 166          if ( $cacheEntry )
 167          {
 168              $cacheEntries[] = $cacheEntry;
 169          }
 170          else
 171          {
 172              $missingIDList[] = $id;
 173          }
 174      }
 175      if ( count( $missingIDList ) > 0 )
 176      {
 177          $cli->warning( 'No such cache ID: ' . $cli->stylize( 'emphasize', implode( ', ', $missingIDList ) ) );
 178          $script->shutdown( 1 );
 179      }
 180      $cli->output( 'Clearing ' . $cli->stylize( 'emphasize', $idName ) . ': ', false );
 181      $i = 0;
 182      foreach ( $cacheEntries as $cacheEntry )
 183      {
 184          if ( $i > 0 )
 185              $cli->output( ', ', false );
 186          $cli->output( $cli->stylize( 'emphasize', $cacheEntry['name'] ), false );
 187          eZCache::clearItem( $cacheEntry );
 188          ++$i;
 189      }
 190      $cli->output();
 191  }
 192  
 193  $script->shutdown();
 194  
 195  ?>


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