3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Class CRM_Queue_Page_AJAX
31 class CRM_Queue_Page_AJAX
{
34 * Run the next task and return status information.
36 * Outputs JSON: array(
38 * is_continue => bool,
39 * numberOfItems => int,
40 * exception => htmlString
43 public static function runNext() {
44 $errorPolicy = new CRM_Queue_ErrorPolicy();
45 $errorPolicy->call(function () {
46 global $activeQueueRunner;
47 $qrid = CRM_Utils_Request
::retrieve('qrid', 'String', CRM_Core_DAO
::$_nullObject, TRUE, NULL, 'POST');
48 $activeQueueRunner = CRM_Queue_Runner
::instance($qrid);
49 if (!is_object($activeQueueRunner)) {
50 throw new Exception('Queue runner must be configured before execution.');
52 $result = $activeQueueRunner->runNext(TRUE);
53 CRM_Queue_Page_AJAX
::_return('runNext', $result);
58 * Run the next task and return status information.
60 * Outputs JSON: array(
62 * is_continue => bool,
63 * numberOfItems => int,
64 * exception => htmlString
67 public static function skipNext() {
68 $errorPolicy = new CRM_Queue_ErrorPolicy();
69 $errorPolicy->call(function () {
70 global $activeQueueRunner;
71 $qrid = CRM_Utils_Request
::retrieve('qrid', 'String', CRM_Core_DAO
::$_nullObject, TRUE, NULL, 'POST');
72 $activeQueueRunner = CRM_Queue_Runner
::instance($qrid);
73 if (!is_object($activeQueueRunner)) {
74 throw new Exception('Queue runner must be configured before execution.');
76 $result = $activeQueueRunner->skipNext(TRUE);
77 CRM_Queue_Page_AJAX
::_return('skipNext', $result);
82 * Run the next task and return status information.
84 * Outputs JSON: array(
86 * is_continue => bool,
87 * numberOfItems => int,
88 * exception => htmlString
91 public static function onEnd() {
92 $errorPolicy = new CRM_Queue_ErrorPolicy();
93 $errorPolicy->call(function () {
94 global $activeQueueRunner;
95 $qrid = CRM_Utils_Request
::retrieve('qrid', 'String', CRM_Core_DAO
::$_nullObject, TRUE, NULL, 'POST');
96 $activeQueueRunner = CRM_Queue_Runner
::instance($qrid);
97 if (!is_object($activeQueueRunner)) {
98 throw new Exception('Queue runner must be configured before execution. - onEnd');
100 $result = $activeQueueRunner->handleEnd(FALSE);
101 CRM_Queue_Page_AJAX
::_return('onEnd', $result);
106 * Performing any view-layer filtering on result and send to client.
109 * @param array $result
111 public static function _return($op, $result) {
112 if ($result['is_error']) {
113 if (is_object($result['exception'])) {
114 CRM_Core_Error
::debug_var("CRM_Queue_Page_AJAX_{$op}_error", CRM_Core_Error
::formatTextException($result['exception']));
116 $config = CRM_Core_Config
::singleton();
117 if ($config->backtrace || CRM_Core_Config
::isUpgradeMode()) {
118 $result['exception'] = CRM_Core_Error
::formatHtmlException($result['exception']);
121 $result['exception'] = $result['exception']->getMessage();
125 CRM_Core_Error
::debug_var("CRM_Queue_Page_AJAX_{$op}_error", $result);
128 CRM_Utils_JSON
::output($result);