1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
<?php
App::import('Core', 'Controller');
require_once 'bedita_base.php';
class CacheShell extends BeditaBaseShell {
public function remove() {
$id = !empty($this->params['id']) ? $this->params['id'] : null;
if ($id) {
$this->cleanupObjectIdCache($id);
$this->out('Cache of object id ' . $id . ' removed');
return;
}
if (empty($this->params['t'])) {
$this->out('Please select object id (-id) or object type (-t)');
return;
}
$type = $this->params['t'];
$objectTypeId = Configure::read('objectTypes.' . $type . '.id');
if (empty($objectTypeId)) {
$this->out('Object type "' . $type . '" not found');
return;
}
$BEObject = ClassRegistry::init('BEObject');
$BEObject->contain();
$conditions = array('object_type_id' => $objectTypeId);
$nObj = $BEObject->find('count', array('conditions' => $conditions));
$pageSize = 1000;
$pageNum = 0;
$this->out('Number of objects cache to cleanup: '. $nObj);
$count = 0;
while( ($pageSize * $pageNum) < $nObj ) {
$res = $BEObject->find('list',array(
'fields' => array('id'),
'conditions' => $conditions,
'order' => array('id' => 'asc'),
'limit' => $pageSize,
'offset' => $pageNum * $pageSize,
));
$pageNum++;
foreach ($res as $id) {
$count++;
$this->cleanupObjectIdCache($id);
$this->out('Cache of object id ' . $id . ' removed');
}
}
$this->out('Done');
}
private function cleanupObjectIdCache($id) {
$BEObject = ClassRegistry::init('BEObject');
$BEObject->clearCache($id);
}
function help() {
$this->out('Available functions:');
$this->out(' ');
$this->out('1. remove: clean object cache by type or id');
$this->out(' ');
$this->out(' Usage: remove [-id <object-id>] [-t <object-type>');
$this->out(' ');
$this->out(" -t <object-type>\t object type cache to clean - image, video, document,...");
$this->out(" -id <object-id>\t object id cache to clean");
$this->out(' ');
}
}