3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class CRM_Queue_Page_AJAX
15 class CRM_Queue_Page_AJAX
{
18 * Run the next task and return status information.
20 * Outputs JSON: array(
22 * is_continue => bool,
23 * numberOfItems => int,
24 * exception => htmlString
27 public static function runNext() {
28 $errorPolicy = new CRM_Queue_ErrorPolicy();
29 $errorPolicy->call(function () {
30 global $activeQueueRunner;
31 $qrid = CRM_Utils_Request
::retrieve('qrid', 'String', CRM_Core_DAO
::$_nullObject, TRUE, NULL, 'POST');
32 $activeQueueRunner = CRM_Queue_Runner
::instance($qrid);
33 if (!is_object($activeQueueRunner)) {
34 throw new Exception('Queue runner must be configured before execution.');
36 $result = $activeQueueRunner->runNext(TRUE);
37 CRM_Queue_Page_AJAX
::_return('runNext', $result);
42 * Run the next task and return status information.
44 * Outputs JSON: array(
46 * is_continue => bool,
47 * numberOfItems => int,
48 * exception => htmlString
51 public static function skipNext() {
52 $errorPolicy = new CRM_Queue_ErrorPolicy();
53 $errorPolicy->call(function () {
54 global $activeQueueRunner;
55 $qrid = CRM_Utils_Request
::retrieve('qrid', 'String', CRM_Core_DAO
::$_nullObject, TRUE, NULL, 'POST');
56 $activeQueueRunner = CRM_Queue_Runner
::instance($qrid);
57 if (!is_object($activeQueueRunner)) {
58 throw new Exception('Queue runner must be configured before execution.');
60 $result = $activeQueueRunner->skipNext(TRUE);
61 CRM_Queue_Page_AJAX
::_return('skipNext', $result);
66 * Run the next task and return status information.
68 * Outputs JSON: array(
70 * is_continue => bool,
71 * numberOfItems => int,
72 * exception => htmlString
75 public static function onEnd() {
76 $errorPolicy = new CRM_Queue_ErrorPolicy();
77 $errorPolicy->call(function () {
78 global $activeQueueRunner;
79 $qrid = CRM_Utils_Request
::retrieve('qrid', 'String', CRM_Core_DAO
::$_nullObject, TRUE, NULL, 'POST');
80 $activeQueueRunner = CRM_Queue_Runner
::instance($qrid);
81 if (!is_object($activeQueueRunner)) {
82 throw new Exception('Queue runner must be configured before execution. - onEnd');
84 $result = $activeQueueRunner->handleEnd(FALSE);
85 CRM_Queue_Page_AJAX
::_return('onEnd', $result);
90 * Performing any view-layer filtering on result and send to client.
93 * @param array $result
95 public static function _return($op, $result) {
96 if ($result['is_error']) {
97 if (is_object($result['exception'])) {
98 CRM_Core_Error
::debug_var("CRM_Queue_Page_AJAX_{$op}_error", CRM_Core_Error
::formatTextException($result['exception']));
100 $config = CRM_Core_Config
::singleton();
101 if ($config->backtrace || CRM_Core_Config
::isUpgradeMode()) {
102 $result['exception'] = CRM_Core_Error
::formatHtmlException($result['exception']);
105 $result['exception'] = $result['exception']->getMessage();
109 CRM_Core_Error
::debug_var("CRM_Queue_Page_AJAX_{$op}_error", $result);
112 CRM_Utils_JSON
::output($result);