本文整理汇总了PHP中eZScript::iterate方法的典型用法代码示例。如果您正苦于以下问题:PHP eZScript::iterate方法的具体用法?PHP eZScript::iterate怎么用?PHP eZScript::iterate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZScript
的用法示例。
在下文中一共展示了eZScript::iterate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* 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;
}