eZ Publish  [4.0]
flatten.php
Go to the documentation of this file.
00001 #!/usr/bin/env php
00002 <?php
00003 //
00004 // Created on: <19-Dec-2003 14:34:55 amos>
00005 //
00006 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00007 // SOFTWARE NAME: eZ Publish
00008 // SOFTWARE RELEASE: 4.0.x
00009 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00010 // SOFTWARE LICENSE: GNU General Public License v2.0
00011 // NOTICE: >
00012 //   This program is free software; you can redistribute it and/or
00013 //   modify it under the terms of version 2.0  of the GNU General
00014 //   Public License as published by the Free Software Foundation.
00015 //
00016 //   This program is distributed in the hope that it will be useful,
00017 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //   GNU General Public License for more details.
00020 //
00021 //   You should have received a copy of version 2.0 of the GNU General
00022 //   Public License along with this program; if not, write to the Free
00023 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 //   MA 02110-1301, USA.
00025 //
00026 //
00027 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00028 //
00029 
00030 set_time_limit( 0 );
00031 
00032 //include_once( 'lib/ezutils/classes/ezcli.php' );
00033 //include_once( 'kernel/classes/ezscript.php' );
00034 require 'autoload.php';
00035 
00036 $cli = eZCLI::instance();
00037 $endl = $cli->endlineString();
00038 
00039 $script = eZScript::instance( array( 'description' => ( "eZ Publish database flattening.\n\n" .
00040                                                         "Will remove data that is not considered currently in use to minimize the amount of database data it consumes\n" .
00041                                                         "\n" .
00042                                                         "Possible values for NAME is:\n" .
00043                                                         "contentobject, contentclass, workflow, role or all (for all items)\n" .
00044                                                         "flatten.php -s admin contentobject"),
00045                                      'use-session' => false,
00046                                      'use-modules' => true,
00047                                      'use-extensions' => true ) );
00048 
00049 $script->startup();
00050 
00051 $options = $script->getOptions( "[db-host:][db-user:][db-password:][db-database:][db-type:|db-driver:][sql]",
00052                                 "[name]",
00053                                 array( 'db-host' => "Database host",
00054                                        'db-user' => "Database user",
00055                                        'db-password' => "Database password",
00056                                        'db-database' => "Database name",
00057                                        'db-driver' => "Database driver",
00058                                        'db-type' => "Database driver, alias for --db-driver",
00059                                        'sql' => "Display sql queries"
00060                                        ) );
00061 $script->initialize();
00062 
00063 if ( count( $options['arguments'] ) < 1 )
00064 {
00065     $cli->error( "Missing NAME value ( could be contentobject, contentclass, workflow, role or all )" );
00066     $script->shutdown( 1 );
00067 }
00068 
00069 $dbUser = $options['db-user'] ? $options['db-user'] : false;
00070 $dbPassword = $options['db-password'] ? $options['db-password'] : false;
00071 $dbHost = $options['db-host'] ? $options['db-host'] : false;
00072 $dbName = $options['db-database'] ? $options['db-database'] : false;
00073 $dbImpl = $options['db-driver'] ? $options['db-driver'] : false;
00074 $showSQL = $options['sql'] ? true : false;
00075 $siteAccess = $options['siteaccess'] ? $options['siteaccess'] : false;
00076 
00077 if ( $siteAccess )
00078 {
00079     changeSiteAccessSetting( $siteAccess );
00080 }
00081 
00082 
00083 $flattenAllItems = false;
00084 $flattenItems = array();
00085 $flatten = array( 'contentobject' => false,
00086                   'contentclass' => false,
00087                   'workflow' => false,
00088                   'role' => false );
00089 
00090 foreach ( $options['arguments'] as $arg )
00091 {
00092 
00093     $item = strtolower( $arg );
00094     if ( $item == 'all' )
00095         $flattenAllItems = true;
00096     else
00097         $flattenItems[] = $item;
00098 }
00099 
00100 if ( $flattenAllItems )
00101 {
00102     $names = array_keys( $flatten );
00103     foreach ( $names as $name )
00104     {
00105         $flatten[$name] = true;
00106     }
00107 }
00108 else
00109 {
00110     if ( count( $flattenItems ) == 0 )
00111     {
00112         help();
00113         exit;
00114     }
00115     foreach ( $flattenItems as $name )
00116     {
00117         $flatten[$name] = true;
00118     }
00119 }
00120 
00121 function changeSiteAccessSetting( $siteAccess )
00122 {
00123     global $isQuiet;
00124     $cli = eZCLI::instance();
00125     if ( file_exists( 'settings/siteaccess/' . $siteAccess) )
00126     {
00127         if ( !$isQuiet )
00128             $cli->notice( "Using siteaccess $siteAccess for nice url update" );
00129     }
00130     else
00131     {
00132         if ( !$isQuiet )
00133             $cli->notice( "Siteaccess $siteAccess does not exist, using default siteaccess" );
00134     }
00135 }
00136 
00137 $db = eZDB::instance();
00138 
00139 if ( $dbHost or $dbName or $dbUser or $dbImpl )
00140 {
00141     $params = array();
00142     if ( $dbHost !== false )
00143         $params['server'] = $dbHost;
00144     if ( $dbUser !== false )
00145     {
00146         $params['user'] = $dbUser;
00147         $params['password'] = '';
00148     }
00149     if ( $dbPassword !== false )
00150         $params['password'] = $dbPassword;
00151     if ( $dbName !== false )
00152         $params['database'] = $dbName;
00153     $db = eZDB::instance( $dbImpl, $params, true );
00154     eZDB::setInstance( $db );
00155 }
00156 
00157 $db->setIsSQLOutputEnabled( $showSQL );
00158 
00159 //include_once( 'kernel/classes/ezpersistentobject.php' );
00160 
00161 if ( $flatten['contentobject'] )
00162 {
00163     //include_once( 'kernel/classes/ezcontentobject.php' );
00164     $cli->output( "Removing non-published content object versions" );
00165     eZContentObjectVersion::removeVersions();
00166 }
00167 
00168 if ( $flatten['contentclass'] )
00169 {
00170     //include_once( 'kernel/classes/ezcontentclass.php' );
00171     $cli->output( "Removing temporary content classes" );
00172     eZContentClass::removeTemporary();
00173 }
00174 
00175 if ( $flatten['workflow'] )
00176 {
00177     //include_once( 'kernel/classes/ezworkflow.php' );
00178     $cli->output( "Removing temporary workflows" );
00179     eZWorkflow::removeTemporary();
00180 }
00181 
00182 if ( $flatten['role'] )
00183 {
00184     //include_once( 'kernel/classes/ezrole.php' );
00185     $cli->output( "Removing temporary roles" );
00186     eZRole::removeTemporary();
00187 }
00188 
00189 
00190 $script->shutdown();
00191 
00192 ?>