Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezscriptclusterpurge.php
Go to the documentation of this file.
1 <?php
31 class eZScriptClusterPurge
32 {
33 public function __construct()
34 {
35 $this->options = array(
36 'dry-run' => false,
37 'iteration-sleep' => 1,
38 'iteration-limit' => 100,
39 'memory-monitoring' => false,
40 'scopes' => false,
41 'expiry' => 2592000 // 60*60*24*30 = 30 days
42 );
43 }
44
52 public static function isRequired()
53 {
54 $clusterHandler = eZClusterFileHandler::instance();
55 $result = $clusterHandler->requiresPurge();
56
57 return $result;
58 }
59
65 public function run()
66 {
67 $cli = eZCLI::instance();
68
69 if ( $this->optMemoryMonitoring == true )
70 {
71 eZLog::rotateLog( self::LOG_FILE );
72 $cli->output( "Logging memory usage to " . self::LOG_FILE );
73 }
74
75 if ( $this->optIterationSleep > 0 )
76 $sleep = ( $this->optIterationSleep * 1000000 );
77 else
78 $sleep = false;
79
80 $limit = array( 0, $this->optIterationLimit );
81
82 $cli->output( "Purging expired items:" );
83
84 self::monitor( "start" );
85
86 // Fetch a limited list of purge items from the handler itself
87 $clusterHandler = eZClusterFileHandler::instance();
88 while ( $filesList = $clusterHandler->fetchExpiredItems( $this->optScopes, $limit, $this->optExpiry ) )
89 {
90 self::monitor( "iteration start" );
91 foreach( $filesList as $file )
92 {
93 $cli->output( "- $file" );
94 if ( $this->optDryRun == false )
95 {
96 self::monitor( "purge" );
97 $fh = eZClusterFileHandler::instance( $file );
98 $fh->purge( false, false );
99 unset( $fh );
100 }
101 }
102 if ( $sleep !== false )
103 usleep( $sleep );
104
105 // the offset only has to be increased in dry run mode
106 // since each batch is not deleted
107 if ( $this->optDryRun == true )
108 {
109 $limit[0] += $limit[1];
110 }
111 self::monitor( "iteration end" );
112 }
113
114 self::monitor( "end" );
115 }
116
117 public function __get( $propertyName )
118 {
119 switch( $propertyName )
120 {
121 case 'optDryRun':
122 {
123 return $this->options['dry-run'];
124 } break;
125
126 // no sleep in dry-run, it's not nap time !
127 case 'optIterationSleep':
128 {
129 if ( $this->optDryRun == true )
130 return 0;
131 else
132 return $this->options['iteration-sleep'];
133 } break;
134
135 case 'optIterationLimit':
136 {
137 return $this->options['iteration-limit'];
138 } break;
139
140 case 'optMemoryMonitoring':
141 {
142 return $this->options['memory-monitoring'];
143 } break;
144
145 case 'optScopes':
146 {
147 return $this->options['scopes'];
148 } break;
149
150 case 'optExpiry':
151 {
152 return $this->options['expiry'];
153 } break;
154 }
155 }
156
160 public function __set( $propertyName, $propertyValue )
161 {
162 switch( $propertyName )
163 {
164 case 'optDryRun':
165 {
166 $this->options['dry-run'] = $propertyValue;
167 } break;
168
169 case 'optIterationSleep':
170 {
171 return $this->options['iteration-sleep'] = $propertyValue;
172 } break;
173
174 case 'optIterationLimit':
175 {
176 $this->options['iteration-limit'] = $propertyValue;
177 } break;
178
179 case 'optMemoryMonitoring':
180 {
181 $this->options['memory-monitoring'] = $propertyValue;
182 } break;
183
184 case 'optScopes':
185 {
186 $this->options['scopes'] = $propertyValue;
187 } break;
188
189 case 'optExpiry':
190 {
191 $this->options['expiry'] = $propertyValue;
192 } break;
193 }
194 }
195
196 public function monitor( $text )
197 {
198 if ( $this->opt == true )
199 {
200 eZLog::write( "mem [$text]: " . memory_get_usage(), self::LOG_FILE );
201 }
202 }
203
204 private $options = array();
205
206 const LOG_FILE = 'clusterpurge.log';
207 }
208 ?>
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:22
eZLog\write
static write( $message, $logName='common.log', $dir='var/log')
Definition: ezlog.php:30
eZLog\rotateLog
static rotateLog( $fileName)
Definition: ezlog.php:178
eZScriptClusterPurge
Definition: ezscriptclusterpurge.php:32
eZScriptClusterPurge\run
run()
Definition: ezscriptclusterpurge.php:65
eZScriptClusterPurge\__construct
__construct()
Definition: ezscriptclusterpurge.php:33
eZScriptClusterPurge\$options
$options
Definition: ezscriptclusterpurge.php:204
eZScriptClusterPurge\isRequired
static isRequired()
Definition: ezscriptclusterpurge.php:52
eZScriptClusterPurge\monitor
monitor( $text)
Definition: ezscriptclusterpurge.php:196
eZScriptClusterPurge\__get
__get( $propertyName)
Definition: ezscriptclusterpurge.php:117
eZScriptClusterPurge\__set
__set( $propertyName, $propertyValue)
Definition: ezscriptclusterpurge.php:160
eZScriptClusterPurge\LOG_FILE
const LOG_FILE
Definition: ezscriptclusterpurge.php:206
$result
$result
Definition: companysearch.php:94
$fh
$fh
Definition: ezfilemanager/user/filedownload.php:254
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.