eZ Publish  [4.0]
internal_drafts_cleanup.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Created on: <24-Mar-2006 15:36:53 amos>
00004 //
00005 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00006 // SOFTWARE NAME: eZ Publish
00007 // SOFTWARE RELEASE: 4.0.x
00008 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00009 // SOFTWARE LICENSE: GNU General Public License v2.0
00010 // NOTICE: >
00011 //   This program is free software; you can redistribute it and/or
00012 //   modify it under the terms of version 2.0  of the GNU General
00013 //   Public License as published by the Free Software Foundation.
00014 //
00015 //   This program is distributed in the hope that it will be useful,
00016 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //   GNU General Public License for more details.
00019 //
00020 //   You should have received a copy of version 2.0 of the GNU General
00021 //   Public License along with this program; if not, write to the Free
00022 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00023 //   MA 02110-1301, USA.
00024 //
00025 //
00026 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00027 //
00028 
00029 /*! \file internal_drafts_cleanup.php
00030 */
00031 
00032 //include_once( 'lib/ezutils/classes/ezini.php' );
00033 //include_once( 'kernel/classes/ezcontentobjectversion.php' );
00034 
00035 if ( !$isQuiet )
00036     $cli->output( "Cleaning up internal drafts..." );
00037 
00038 // Remove all temporary internal drafts
00039 $ini = eZINI::instance( 'content.ini' );
00040 $internalDraftsCleanUpLimit = $ini->hasVariable( 'VersionManagement', 'InternalDraftsCleanUpLimit' ) ?
00041                                  $ini->variable( 'VersionManagement', 'InternalDraftsCleanUpLimit' ) : 0;
00042 $durationSetting = $ini->hasVariable( 'VersionManagement', 'InternalDraftsDuration' ) ?
00043                       $ini->variable( 'VersionManagement', 'InternalDraftsDuration' ) : array( 'hours' => 24 ); // by default, only remove drafts older than 1 day
00044 
00045 $isDurationSet = false;
00046 $duration = 0;
00047 if ( is_array( $durationSetting ) )
00048 {
00049     if ( isset( $durationSetting[ 'days' ] ) and is_numeric( $durationSetting[ 'days' ] ) )
00050     {
00051         $duration += $durationSetting[ 'days' ] * 60 * 60 * 24;
00052         $isDurationSet = true;
00053     }
00054     if ( isset( $durationSetting[ 'hours' ] ) and is_numeric( $durationSetting[ 'hours' ] ) )
00055     {
00056         $duration += $durationSetting[ 'hours' ] * 60 * 60;
00057         $isDurationSet = true;
00058     }
00059     if ( isset( $durationSetting[ 'minutes' ] ) and is_numeric( $durationSetting[ 'minutes' ] ) )
00060     {
00061         $duration += $durationSetting[ 'minutes' ] * 60;
00062         $isDurationSet = true;
00063     }
00064     if ( isset( $durationSetting[ 'seconds' ] ) and is_numeric( $durationSetting[ 'seconds' ] ) )
00065     {
00066         $duration += $durationSetting[ 'seconds' ];
00067         $isDurationSet = true;
00068     }
00069 }
00070 
00071 if ( $isDurationSet )
00072 {
00073     $expiryTime = time() - $duration;
00074     $processedCount = eZContentObjectVersion::removeVersions( eZContentObjectVersion::STATUS_INTERNAL_DRAFT, $internalDraftsCleanUpLimit, $expiryTime );
00075 
00076     if ( !$isQuiet )
00077         $cli->output( "Cleaned up " . $processedCount . " internal drafts" );
00078 }
00079 else
00080 {
00081     if ( !$isQuiet )
00082         $cli->output( "Lifetime is not set for internal drafts (see your ini-settings, content.ini, VersionManagement section)." );
00083 }
00084 
00085 ?>