[ 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/ -> cleanup.php (source)

   1  #!/usr/bin/env php
   2  <?php
   3  //
   4  // Created on: <18-Dec-2003 17:44:15 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  set_time_limit( 0 );
  29  
  30  include_once ( 'lib/ezutils/classes/ezcli.php' );
  31  include_once ( 'kernel/classes/ezscript.php' );
  32  
  33  $cli =& eZCLI::instance();
  34  $endl = $cli->endlineString();
  35  
  36  $script =& eZScript::instance( array( 'description' => ( "eZ publish database cleanup.\n\n" .
  37                                                           "Will cleanup various data from the currently used database in eZ publish\n" .
  38                                                           "\n" .
  39                                                           "Possible values for NAME is:\n" .
  40                                                           "session, expired_session, preferences, browse, tipafriend, shop, forgotpassword, workflow,\n" .
  41                                                           "collaboration, collectedinformation, notification, searchstats or all (for all items)\n" .
  42                                                           "cleanup.php -s admin session"),
  43                                        'use-session' => false,
  44                                        'use-modules' => true,
  45                                        'use-extensions' => true ) );
  46  
  47  $script->startup();
  48  
  49  $options = $script->getOptions( "[db-user:][db-password:][db-database:][db-type:|db-driver:][sql]",
  50                                  "[name]",
  51                                  array( 'db-host' => "Database host",
  52                                         'db-user' => "Database user",
  53                                         'db-password' => "Database password",
  54                                         'db-database' => "Database name",
  55                                         'db-driver' => "Database driver",
  56                                         'db-type' => "Database driver, alias for --db-driver",
  57                                         'sql' => "Display sql queries"
  58                                         ) );
  59  $script->initialize();
  60  
  61  if ( count( $options['arguments'] ) < 1 )
  62  {
  63      $cli->error( "Missing NAME value ( could be session, expired_session, preferences, browse, tipafriend, shop, forgotpassword, workflow,\n" .
  64                   "collaboration, collectedinformation, notification, searchstats or all )" );
  65      $script->shutdown( 1 );
  66  }
  67  
  68  $dbUser = $options['db-user'] ? $options['db-user'] : false;
  69  $dbPassword = $options['db-password'] ? $options['db-password'] : false;
  70  $dbHost = $options['db-host'] ? $options['db-host'] : false;
  71  $dbName = $options['db-database'] ? $options['db-database'] : false;
  72  $dbImpl = $options['db-driver'] ? $options['db-driver'] : false;
  73  $showSQL = $options['sql'] ? true : false;
  74  $siteAccess = $options['siteaccess'] ? $options['siteaccess'] : false;
  75  
  76  if ( $siteAccess )
  77  {
  78      changeSiteAccessSetting( $siteaccess, $siteAccess );
  79  }
  80  
  81  $cleanAllItems = false;
  82  $clean = array( 'session' => false,
  83                  'preferences' => false,
  84                  'browse' => false,
  85                  'tipafriend' => false,
  86                  'shop' => false,
  87                  'forgotpassword' => false,
  88                  'workflow' => false,
  89                  'collaboration' => false,
  90                  'collectedinformation' => false,
  91                  'notification' => false,
  92                  'searchstats' => false );
  93  
  94  foreach ( $options['arguments'] as $arg )
  95  {
  96  
  97      $item = strtolower( $arg );
  98      if ( $item == 'all' )
  99          $cleanAllItems = true;
 100      else
 101          $cleanItems[] = $item;
 102  }
 103  
 104  if ( $cleanAllItems )
 105  {
 106      $names = array_keys( $clean );
 107      foreach ( $names as $name )
 108      {
 109          $clean[$name] = true;
 110      }
 111  }
 112  else
 113  {
 114      if ( count( $cleanItems ) == 0 )
 115      {
 116          help();
 117          exit;
 118      }
 119      foreach ( $cleanItems as $name )
 120      {
 121          $clean[$name] = true;
 122      }
 123  }
 124  
 125  function changeSiteAccessSetting( &$siteaccess, $optionData )
 126  {
 127      global $isQuiet;
 128      $cli =& eZCLI::instance();
 129      if ( file_exists( 'settings/siteaccess/' . $optionData ) )
 130      {
 131          $siteaccess = $optionData;
 132          if ( !$isQuiet )
 133              $cli->notice( "Using siteaccess $siteaccess for database cleanup" );
 134      }
 135      else
 136      {
 137          if ( !$isQuiet )
 138              $cli->notice( "Siteaccess $optionData does not exist, using default siteaccess" );
 139      }
 140  }
 141  
 142  $db =& eZDB::instance();
 143  if ( $dbHost or $dbName or $dbUser or $dbImpl )
 144  {
 145      $params = array();
 146      if ( $dbHost !== false )
 147          $params['server'] = $dbHost;
 148      if ( $dbUser !== false )
 149      {
 150          $params['user'] = $dbUser;
 151          $params['password'] = '';
 152      }
 153      if ( $dbPassword !== false )
 154          $params['password'] = $dbPassword;
 155      if ( $dbName !== false )
 156          $params['database'] = $dbName;
 157      $db =& eZDB::instance( $dbImpl, $params, true );
 158      eZDB::setInstance( $db );
 159  }
 160  
 161  $db->setIsSQLOutputEnabled( $showSQL );
 162  
 163  include_once ( 'kernel/classes/ezpersistentobject.php' );
 164  
 165  include_once ( 'lib/ezutils/classes/ezsession.php' );
 166  if ( $clean['session'] )
 167  {
 168      $cli->output( "Removing all sessions" );
 169      eZSessionEmpty();
 170  }
 171  
 172  if ( $clean['expired_session'] )
 173  {
 174      $cli->output( "Removing expired sessions,", false );
 175      eZSessionGarbageCollector();
 176      $activeCount = eZSessionCountActive();
 177      $cli->output( " " . $cli->stylize( 'emphasize', $activeCount ) . " left" );
 178  }
 179  
 180  if ( $clean['preferences'] )
 181  {
 182      include_once ( 'kernel/classes/ezpreferences.php' );
 183      $cli->output( "Removing all preferences" );
 184      eZPreferences::cleanup();
 185  }
 186  
 187  if ( $clean['browse'] )
 188  {
 189      include_once ( 'kernel/classes/ezcontentbrowserecent.php' );
 190      include_once ( 'kernel/classes/ezcontentbrowsebookmark.php' );
 191      $cli->output( "Removing all recent items and bookmarks for browse page" );
 192      eZContentBrowseRecent::cleanup();
 193      eZContentBrowseBookmark::cleanup();
 194  }
 195  
 196  if ( $clean['tipafriend'] )
 197  {
 198      include_once ( 'kernel/classes/eztipafriendcounter.php' );
 199      $cli->output( "Removing all counters for tip-a-friend" );
 200      eZTipafriendCounter::cleanup();
 201  }
 202  
 203  if ( $clean['shop'] )
 204  {
 205      include_once ( 'kernel/classes/ezbasket.php' );
 206      $cli->output( "Removing all baskets" );
 207      eZBasket::cleanup();
 208      include_once ( 'kernel/classes/ezwishlist.php' );
 209      $cli->output( "Removing all wishlists" );
 210      eZWishList::cleanup();
 211      include_once ( 'kernel/classes/ezorder.php' );
 212      $cli->output( "Removing all orders" );
 213      eZOrder::cleanup();
 214      $productCount = eZProductCollection::count();
 215      if ( $productCount > 0 )
 216      {
 217          $cli->warning( "$productCount product collections still exists, must be a leak" );
 218      }
 219  }
 220  
 221  if ( $clean['forgotpassword'] )
 222  {
 223      include_once ( 'kernel/classes/datatypes/ezuser/ezforgotpassword.php' );
 224      $cli->output( "Removing all forgot password requests" );
 225      eZForgotPassword::cleanup();
 226  }
 227  
 228  if ( $clean['workflow'] )
 229  {
 230      include_once ( 'lib/ezutils/classes/ezoperationmemento.php' );
 231      include_once ( 'kernel/classes/ezworkflowprocess.php' );
 232      $cli->output( "Removing all workflow processes and operation mementos" );
 233      eZOperationMemento::cleanup();
 234      eZWorkflowProcess::cleanup();
 235  }
 236  
 237  if ( $clean['collaboration'] )
 238  {
 239      include_once ( 'kernel/classes/ezcollaborationitem.php' );
 240      $cli->output( "Removing all collaboration elements" );
 241      eZCollaborationItem::cleanup();
 242  }
 243  
 244  if ( $clean['collectedinformation'] )
 245  {
 246      include_once ( 'kernel/classes/ezinformationcollection.php' );
 247      $cli->output( "Removing all collected information" );
 248      eZInformationCollection::cleanup();
 249  }
 250  
 251  if ( $clean['notification'] )
 252  {
 253      include_once ( 'kernel/classes/notification/eznotificationevent.php' );
 254      include_once ( 'kernel/classes/notification/eznotificationcollection.php' );
 255      include_once ( 'kernel/classes/notification/eznotificationeventfilter.php' );
 256      $cli->output( "Removing all notifications events" );
 257      eZNotificationEvent::cleanup();
 258      eZNotificationCollection::cleanup();
 259      eZNotificationEventFilter::cleanup();
 260  }
 261  
 262  if ( $clean['searchstats'] )
 263  {
 264      include_once ( 'kernel/classes/ezsearchlog.php' );
 265      $cli->output( "Removing all search statistics" );
 266      eZSearchLog::removeStatistics();
 267  }
 268  
 269  
 270  $script->shutdown();
 271  
 272  ?>


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