public static function fetchTrashObjectCount($objectNameFilter, $attributeFilter = false)
 {
     $params = array();
     if ($objectNameFilter !== false) {
         $params['ObjectNameFilter'] = $objectNameFilter;
     }
     $params['AttributeFilter'] = $attributeFilter;
     $trashCount = eZContentObjectTrashNode::trashListCount($params);
     return array('result' => $trashCount);
 }
Пример #2
0
 /**
  * Executes the purge operation
  *
  * @param int|null $iterationLimit Number of trashed objects to treat per iteration, use null to use a default value.
  * @param int|null $sleep Number of seconds to sleep between two iterations, use null to use a default value.
  *
  * @return bool True if the operation succeeded.
  */
 public function run($iterationLimit = 100, $sleep = 1)
 {
     if ($iterationLimit === null) {
         $iterationLimit = 100;
     }
     if ($sleep === null) {
         $sleep = 1;
     }
     if ($this->memoryMonitoring) {
         eZLog::rotateLog($this->logFile);
         $this->cli->output("Logging memory usage to {$this->logFile}");
     }
     $this->cli->output("Purging trash items:");
     $this->monitor("start");
     $db = eZDB::instance();
     // Get user's ID who can remove subtrees. (Admin by default with userID = 14)
     $userCreatorID = eZINI::instance()->variable("UserSettings", "UserCreatorID");
     $user = eZUser::fetch($userCreatorID);
     if (!$user) {
         $this->cli->error("Cannot get user object with userID = '{$userCreatorID}'.\n(See site.ini[UserSettings].UserCreatorID)");
         return false;
     }
     eZUser::setCurrentlyLoggedInUser($user, $userCreatorID);
     $trashCount = eZContentObjectTrashNode::trashListCount(false);
     if (!$this->quiet) {
         $this->cli->output("Found {$trashCount} object(s) in trash.");
     }
     if ($trashCount == 0) {
         return true;
     }
     if ($this->script !== null) {
         $this->script->resetIteration($trashCount);
     }
     while ($trashCount > 0) {
         $this->monitor("iteration start");
         $trashList = eZContentObjectTrashNode::trashList(array('Limit' => $iterationLimit), false);
         $db->begin();
         foreach ($trashList as $trashNode) {
             $object = $trashNode->attribute('object');
             $this->monitor("purge");
             $object->purge();
             if ($this->script !== null) {
                 $this->script->iterate($this->cli, true);
             }
         }
         if (!$db->commit()) {
             $this->cli->output();
             $this->cli->error('Trash has not been emptied, impossible to commit the whole transaction');
             return false;
         }
         $trashCount = eZContentObjectTrashNode::trashListCount(false);
         if ($trashCount > 0) {
             eZContentObject::clearCache();
             if ($sleep > 0) {
                 sleep($sleep);
             }
         }
         $this->monitor("iteration end");
     }
     if (!$this->quiet) {
         $this->cli->output('Trash successfully emptied');
     }
     $this->monitor("end");
     return true;
 }