Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezdbgarbagecollector.php
Go to the documentation of this file.
1 <?php
32 class eZDBGarbageCollector
33 {
37 const ITEM_LIMIT = 3000;
38
60 function collectBaskets( $maxTime = false, $sleepTime = false, $limit = false )
61 {
62 $db = eZDB::instance();
63
64 if ( $maxTime === false and $db->hasRequiredServerVersion( '4.0', 'mysql' ) )
65 {
66 $sql = "DELETE FROM ezbasket, ezproductcollection, ezproductcollection_item, ezproductcollection_item_opt
67 USING ezsession
68 RIGHT JOIN ezbasket
69 ON ezsession.session_key = ezbasket.session_id
70 LEFT JOIN ezproductcollection
71 ON ezbasket.productcollection_id = ezproductcollection.id
72 LEFT JOIN ezproductcollection_item
73 ON ezproductcollection.id = ezproductcollection_item.productcollection_id
74 LEFT JOIN ezproductcollection_item_opt
75 ON ezproductcollection_item.id = ezproductcollection_item_opt.item_id
76 WHERE ezsession.session_key IS NULL";
77 $db->query( $sql );
78 return;
79 }
80
81 // Find all baskets which are lacking a session (db leaks)
82 if ( $db->hasRequiredServerVersion( '8', 'oracle' ) )
83 {
84 $sql = "SELECT id, productcollection_id
85 FROM ezsession, ezbasket
86 WHERE ezbasket.session_id = ezsession.session_key (+) AND
87 ezsession.session_key IS NULL";
88 }
89 else
90 {
91 $sql = "SELECT id, productcollection_id
92 FROM ezsession
93 RIGHT JOIN ezbasket
94 ON ezbasket.session_id = ezsession.session_key
95 WHERE ezsession.session_key IS NULL";
96 }
97 if ( $limit === false )
98 $limit = eZDBGarbageCollector::ITEM_LIMIT;
99 $end = false;
100 if ( is_numeric( $maxTime ) )
101 $end = time() + $maxTime;
102
103 do
104 {
105 $rows = $db->arrayQuery( $sql, array( 'offset' => 0, 'limit' => $limit ) );
106 if ( count( $rows ) == 0 )
107 break;
108
109 $productCollectionIDList = array();
110 $idList = array();
111 foreach ( $rows as $row )
112 {
113 $idList[] = (int)$row['id'];
114 $productCollectionIDList[] = (int)$row['productcollection_id'];
115 }
116 eZProductCollection::cleanupList( $productCollectionIDList );
117
118 $ids = implode( ', ', $idList );
119 $db->query( "DELETE FROM ezbasket WHERE id IN ( $ids )" );
120
121 // Stop when we used up our time
122 if ( $end !== false and time() > $end )
123 break;
124
125 // Sleep a little if required, reduces load on server
126 if ( $sleepTime !== false )
127 sleep( $sleepTime );
128
129 } while ( true );
130 }
131
153 function collectProductCollections( $maxTime = false, $sleepTime = false, $limit = false )
154 {
155 $db = eZDB::instance();
156
157 // Create a temporary table for filling in collection ids
158 // that are in use
159 if ( $db->databaseName() == 'mysql' )
160 $db->query( "DROP TABLE IF EXISTS ezproductcollection_used" );
161 $db->query( "CREATE TABLE ezproductcollection_used ( id int )" );
162
163 // Fill in collections used by orders
164 $db->query( "INSERT INTO ezproductcollection_used (id) SELECT productcollection_id FROM ezorder" );
165
166 // Fill in collections used by wish lists
167 $db->query( "INSERT INTO ezproductcollection_used (id) SELECT productcollection_id FROM ezwishlist" );
168
169 // Fill in collections used by baskets
170 $db->query( "INSERT INTO ezproductcollection_used (id) SELECT productcollection_id FROM ezbasket" );
171
172 // Create the index for faster selects
173 $db->query( "CREATE INDEX ezproductcollection_used_id on ezproductcollection_used( id )" );
174
175 if ( $maxTime === false and $db->hasRequiredServerVersion( '4.0', 'mysql' ) )
176 {
177 // Delete entries which are not in ezproductcollection_used
178 $db->query( "DELETE FROM ezproductcollection, ezproductcollection_item, ezproductcollection_item_opt
179 USING ezproductcollection_used
180 RIGHT JOIN ezproductcollection
181 ON ezproductcollection_used.id = ezproductcollection.id
182 LEFT JOIN ezproductcollection_item
183 ON ezproductcollection.id = ezproductcollection_item.productcollection_id
184 LEFT JOIN ezproductcollection_item_opt
185 ON ezproductcollection_item.id = ezproductcollection_item_opt.item_id
186 WHERE ezproductcollection_used.id IS NULL" );
187 $db->query( $sql );
188
189 // Remove the temporary table
190 $db->query( "DROP TABLE ezproductcollection_used" );
191
192 return;
193 }
194
195 // Find all product collections which are not in use
196 if ( $db->hasRequiredServerVersion( '8', 'oracle' ) )
197 {
198 $sql = "SELECT ezproductcollection.id
199 FROM ezproductcollection_used, ezproductcollection
200 WHERE ezproductcollection_used.id = ezproductcollection.id (+) AND
201 ezproductcollection_used.id IS NULL";
202 }
203 else
204 {
205 $sql = "SELECT ezproductcollection.id
206 FROM ezproductcollection_used
207 RIGHT JOIN ezproductcollection
208 ON ezproductcollection_used.id = ezproductcollection.id
209 WHERE ezproductcollection_used.id IS NULL";
210 }
211 if ( $limit === false )
212 $limit = eZDBGarbageCollector::ITEM_LIMIT;
213 $end = false;
214 if ( is_numeric( $maxTime ) )
215 $end = time() + $maxTime;
216
217 do
218 {
219 $rows = $db->arrayQuery( $sql, array( 'offset' => 0, 'limit' => $limit ) );
220 if ( count( $rows ) == 0 )
221 break;
222
223 $idList = array();
224 foreach ( $rows as $row )
225 {
226 $idList[] = (int)$row['id'];
227 }
228 eZProductCollectionItem::cleanupList( $idList );
229
230 $ids = implode( ', ', $idList );
231 $db->query( "DELETE FROM ezproductcollection WHERE id IN ( $ids )" );
232 $db->query( "DELETE FROM ezproductcollection_used WHERE id IN ( $ids )" );
233
234 // Stop when we used up our time
235 if ( $end !== false and time() > $end )
236 break;
237
238 // Sleep a little if required, reduces load on server
239 if ( $sleepTime !== false )
240 sleep( $sleepTime );
241
242 } while ( true );
243
244 // Remove the temporary table
245 $db->query( "DROP TABLE ezproductcollection_used" );
246 }
247
268 function collectProductCollectionItems( $maxTime = false, $sleepTime = false, $limit = false )
269 {
270 $db = eZDB::instance();
271
272 if ( $maxTime === false and $db->hasRequiredServerVersion( '4.0', 'mysql' ) )
273 {
274 $sql = "DELETE FROM ezproductcollection_item, ezproductcollection_item_opt
275 USING ezproductcollection
276 LEFT JOIN ezproductcollection_item
277 ON ezproductcollection.id = ezproductcollection_item.productcollection_id
278 LEFT JOIN ezproductcollection_item_opt
279 ON ezproductcollection_item.id = ezproductcollection_item_opt.item_id
280 WHERE ezproductcollection.id IS NULL";
281 $db->query( $sql );
282
283 return;
284 }
285
286 // Find all items which are lacking a collection (db leaks)
287 if ( $db->hasRequiredServerVersion( '8', 'oracle' ) )
288 {
289 $sql = "SELECT ezproductcollection_item.productcollection_id
290 FROM ezproductcollection, ezproductcollection_item
291 WHERE ezproductcollection.id = ezproductcollection_item.productcollection_id (+) AND
292 ezproductcollection.id IS NULL";
293 }
294 else
295 {
296 $sql = "SELECT ezproductcollection_item.productcollection_id
297 FROM ezproductcollection
298 RIGHT JOIN ezproductcollection_item
299 ON ezproductcollection.id = ezproductcollection_item.productcollection_id
300 WHERE ezproductcollection.id IS NULL";
301 }
302 if ( $limit === false )
303 $limit = eZDBGarbageCollector::ITEM_LIMIT;
304 $end = false;
305 if ( is_numeric( $maxTime ) )
306 $end = time() + $maxTime;
307
308 do
309 {
310 $rows = $db->arrayQuery( $sql, array( 'offset' => 0, 'limit' => $limit ) );
311 if ( count( $rows ) == 0 )
312 break;
313
314 $idList = array();
315 foreach ( $rows as $row )
316 {
317 $idList[] = (int)$row['productcollection_id'];
318 }
319 eZProductCollectionItemOption::cleanupList( $idList );
320
321 $ids = implode( ', ', $idList );
322 $db->query( "DELETE FROM ezproductcollection_item WHERE productcollection_id IN ( $ids )" );
323
324 // Stop when we used up our time
325 if ( $end !== false and time() > $end )
326 break;
327
328 // Sleep a little if required, reduces load on server
329 if ( $sleepTime !== false )
330 sleep( $sleepTime );
331
332 } while ( true );
333 }
334
353 function collectProductCollectionItemOptions( $maxTime = false, $sleepTime = false, $limit = false )
354 {
355 $db = eZDB::instance();
356
357 if ( $maxTime === false and $db->hasRequiredServerVersion( '4.0', 'mysql' ) )
358 {
359 $sql = "DELETE FROM ezproductcollection_item_opt
360 USING ezproductcollection_item
361 LEFT JOIN ezproductcollection_item_opt
362 ON ezproductcollection_item.id = ezproductcollection_item_opt.item_id
363 WHERE ezproductcollection_item.id IS NULL";
364 $db->query( $sql );
365
366 return;
367 }
368
369 // Find all items which are lacking a collection (db leaks)
370 if ( $db->hasRequiredServerVersion( '8', 'oracle' ) )
371 {
372 $sql = "SELECT ezproductcollection_item_opt.item_id
373 FROM ezproductcollection_item, ezproductcollection_item_opt
374 WHERE ezproductcollection_item.id = ezproductcollection_item_opt.item_id (+) AND
375 ezproductcollection_item.id IS NULL";
376 }
377 else
378 {
379 $sql = "SELECT ezproductcollection_item_opt.item_id
380 FROM ezproductcollection_item
381 RIGHT JOIN ezproductcollection_item_opt
382 ON ezproductcollection_item.id = ezproductcollection_item_opt.item_id
383 WHERE ezproductcollection_item.id IS NULL";
384 }
385 if ( $limit === false )
386 $limit = eZDBGarbageCollector::ITEM_LIMIT;
387 $end = false;
388 if ( is_numeric( $maxTime ) )
389 $end = time() + $maxTime;
390
391 do
392 {
393 $rows = $db->arrayQuery( $sql, array( 'offset' => 0, 'limit' => $limit ) );
394 if ( count( $rows ) == 0 )
395 break;
396
397 $idList = array();
398 foreach ( $rows as $row )
399 {
400 $idList[] = (int)$row['item_id'];
401 }
402
403 $ids = implode( ', ', $idList );
404 $db->query( "DELETE FROM ezproductcollection_item_opt WHERE item_id IN ( $ids )" );
405
406 // Stop when we used up our time
407 if ( $end !== false and time() > $end )
408 break;
409
410 // Sleep a little if required, reduces load on server
411 if ( $sleepTime !== false )
412 sleep( $sleepTime );
413
414 } while ( true );
415 }
416 }
417
418 ?>
eZDBGarbageCollector
Definition: ezdbgarbagecollector.php:33
eZDBGarbageCollector\collectProductCollectionItems
collectProductCollectionItems( $maxTime=false, $sleepTime=false, $limit=false)
Definition: ezdbgarbagecollector.php:268
eZDBGarbageCollector\ITEM_LIMIT
const ITEM_LIMIT
Definition: ezdbgarbagecollector.php:37
eZDBGarbageCollector\collectBaskets
collectBaskets( $maxTime=false, $sleepTime=false, $limit=false)
Definition: ezdbgarbagecollector.php:60
eZDBGarbageCollector\collectProductCollections
collectProductCollections( $maxTime=false, $sleepTime=false, $limit=false)
Definition: ezdbgarbagecollector.php:153
eZDBGarbageCollector\collectProductCollectionItemOptions
collectProductCollectionItemOptions( $maxTime=false, $sleepTime=false, $limit=false)
Definition: ezdbgarbagecollector.php:353
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZProductCollectionItemOption\cleanupList
static cleanupList( $itemIDList)
Definition: ezproductcollectionitemoption.php:130
eZProductCollectionItem\cleanupList
static cleanupList( $productCollectionIDList)
Definition: ezproductcollectionitem.php:277
eZProductCollection\cleanupList
static cleanupList( $productCollectionIDList)
Definition: ezproductcollection.php:153
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.