function cliRunDeferredTask($deferred) { global $cliHelper; $runner = XenForo_Deferred_Abstract::create($deferred['execute_class']); @set_time_limit(0); if (!$runner) { $cliHelper->printWarning("{$deferred['execute_class']} deferred class not found."); return false; } $cliHelper->printStatus(''); if (!is_array($deferred['execute_data'])) { $data = unserialize($deferred['execute_data']); } else { $data = $deferred['execute_data']; } $targetRunTime = XenForo_Application::getConfig()->rebuildMaxExecution; while ($data = $runner->execute($deferred, $data, $targetRunTime, $status) and is_array($data)) { $cliHelper->printStatus($status); } if (empty($status)) { $status = $deferred['execute_class'] . ' (0)'; } $cliHelper->printStatus($status . ' - Done.'); $cliHelper->printMessage(''); }
public function actionTriggerDeferred() { $this->_assertPostOnly(); $this->assertAdminPermission('rebuildCache'); $input = $this->_input->filter(array('cache' => XenForo_Input::STRING, 'options' => XenForo_Input::ARRAY_SIMPLE)); if ($input['cache']) { $obj = XenForo_Deferred_Abstract::create($input['cache']); if ($obj) { XenForo_Application::defer($input['cache'], $input['options'], 'Rebuild' . $input['cache'], true); } } $this->_request->setParam('redirect', XenForo_Link::buildAdminLink('xengallery/rebuilds', false, array('success' => 1))); return $this->responseReroute('XenForo_ControllerAdmin_Tools', 'runDeferred'); }
public function actionTriggerDeferred() { $this->_assertPostOnly(); $this->assertAdminPermission('rebuildCache'); $input = $this->_input->filter(array('cache' => XenForo_Input::STRING, 'options' => XenForo_Input::ARRAY_SIMPLE)); if ($input['cache']) { $obj = XenForo_Deferred_Abstract::create($input['cache']); if ($obj && $obj->canTriggerManually()) { switch (get_class($obj)) { case 'XenForo_Deferred_Atomic': case 'XenForo_Deferred_ThreadAction': case 'XenForo_Deferred_ThreadDelete': case 'XenForo_Deferred_UserAction': case 'XenForo_Deferred_UserGroupDelete': case 'XenForo_Deferred_UserRevertMessageEdit': break; default: XenForo_Application::defer($input['cache'], $input['options'], 'Rebuild' . $input['cache'], true); } } } $this->_request->setParam('redirect', XenForo_Link::buildAdminLink('tools/rebuild', false, array('success' => 1))); return $this->responseReroute(__CLASS__, 'runDeferred'); }
public function runDeferred(array $deferred, $targetRunTime, &$status, &$canCancel) { $this->resetUniqueDeferInserts(); $canCancel = false; if (!$this->deleteDeferredById($deferred['deferred_id'])) { // already being run return false; } $runner = XenForo_Deferred_Abstract::create($deferred['execute_class']); if (!$runner) { return false; } $data = unserialize($deferred['execute_data']); if (!self::$_shutdownRegistered) { self::$_shutdownRegistered = true; register_shutdown_function(array(__CLASS__, 'shutdownHandleFatalDeferred')); } self::$_runningDeferred = $deferred; try { $output = $runner->execute($deferred, $data, $targetRunTime, $status); self::$_runningDeferred = false; } catch (Exception $e) { self::$_runningDeferred = false; // transactions are likely from the manual runner, so we need to roll them back // as they probably won't be committed XenForo_Db::rollbackAll(); if ($deferred['manual_execute']) { // reinsert and throw so a refresh will catch it XenForo_Application::defer($deferred['execute_class'], $data, $deferred['unique_key'], $deferred['manual_execute'], $deferred['trigger_date'], true); throw $e; } else { // log and ignore XenForo_Error::logException($e, false); $output = false; $status = "{$deferred['execute_class']} threw exception. See error log."; // TODO: phrase? } } if ($output === 'exit') { // this is for debugging - restore to previous state XenForo_Db::rollbackAll(); XenForo_Application::defer($deferred['execute_class'], $data, $deferred['unique_key'], $deferred['manual_execute'], $deferred['trigger_date'], true); exit; } else { if (is_array($output)) { $canCancel = $runner->canCancel(); return XenForo_Application::defer($deferred['execute_class'], $output, $deferred['unique_key'], $deferred['manual_execute'], $deferred['trigger_date'], true); } else { return false; } } }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('execute' => array(), 'simple' => false), $data); if ($data['simple']) { if (is_string($data['simple'])) { $classes = preg_split('/,\\s*/', $data['simple'], -1, PREG_SPLIT_NO_EMPTY); } else { $classes = $data['simple']; } foreach ($classes as $class) { $data['execute'][] = array($class, array()); } $data['simple'] = false; } $startTime = microtime(true); $limitTime = $targetRunTime > 0; while ($data['execute']) { $value = reset($data['execute']); $key = key($data['execute']); list($class, $classData) = $value; $runner = XenForo_Deferred_Abstract::create($class); if (!$runner) { unset($data['execute'][$key]); continue; } if ($limitTime) { $remainingTime = $targetRunTime - (microtime(true) - $startTime); if ($remainingTime < 1) { // ran out of time - have some pick up later break; } } else { $remainingTime = 0; } try { $output = $runner->execute($deferred, $classData, $remainingTime, $status); } catch (Exception $e) { if ($deferred['manual_execute']) { // throw and let it be handled above throw $e; } else { // log and ignore - need to roll back any transactions opened by this too XenForo_Error::logException($e, true); $output = false; $status = "{$class} threw exception. See error log."; // TODO: phrase? } } if ($output === 'exit') { return 'exit'; } else { if (is_array($output)) { $data['execute'][$key][1] = $output; } else { unset($data['execute'][$key]); } } } if (!$data['execute']) { return false; } return $data; }
/** * Sends the specified email. * * @return XenForo_ControllerResponse_Abstract */ public function actionEmailSend() { $this->_assertPostOnly(); $criteria = $this->_input->filterSingle('criteria', XenForo_Input::JSON_ARRAY); $criteria = $this->_filterUserSearchCriteria($criteria); $criteriaPrepared = $this->_prepareUserSearchCriteria($criteria); $email = $this->_input->filter(array('from_name' => XenForo_Input::STRING, 'from_email' => XenForo_Input::STRING, 'email_title' => XenForo_Input::STRING, 'email_format' => XenForo_Input::STRING, 'email_body' => XenForo_Input::STRING)); $total = $this->_input->filterSingle('total', XenForo_Input::UINT); if ($this->_input->filterSingle('test', XenForo_Input::STRING)) { $data = array('userIds' => array(XenForo_Visitor::getUserId()), 'email' => $email); XenForo_Deferred_Abstract::create('UserEmail')->execute(array(), $data, 10, $null); return $this->responseReroute(__CLASS__, 'email'); } XenForo_Application::defer('UserEmail', array('criteria' => $criteriaPrepared, 'email' => $email), 'userEmailSend', true); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('users/email', false, array('sent' => $total))); }