Merge pull request #2664 from colemanw/tabs
[civicrm-core.git] / CRM / Queue / Page / Runner.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28
29 require_once 'CRM/Core/Page.php';
30
31 /**
32 * The queue-runner page provides an interactive, web-based system
33 * running the tasks in a queue and monitoring its progression.
34 *
35 * Do not link or redirect to this page directly -- go through
36 * CRM_Queue_Runner::runAllViaWeb().
37 *
38 * Note: The queue runner only requires 'access CiviCRM' permission.
39 * To ensure that malicious parties don't use this feature to
40 * run queues on the wrong schedule, the queue-runner has an
41 * extra authorization step: it checks for a session variable named
42 * $_SESSION['queueRunners][$qrid]. This variable is properly setup
43 * if you use the CRM_Queue_Runner::runAllViaWeb() interface.
44 */
45 class CRM_Queue_Page_Runner extends CRM_Core_Page {
46
47 /**
48 *
49 * POST Param 'qrid': string, usually the name of the queue
50 */
51 function run() {
52 $qrid = CRM_Utils_Request::retrieve('qrid', 'String', $this, TRUE);
53 $runner = CRM_Queue_Runner::instance($qrid);
54 // dpm(array( 'action' => 'CRM_Queue_Page_Runner::run()', 'session' => $_SESSION, 'runner' => $runner, 'qrid' => $qrid ));
55 if (!is_object($runner)) {
56 CRM_Core_Error::fatal('Queue runner must be configured before execution.');
57 }
58
59 CRM_Utils_System::setTitle($runner->title);
60 $this->assign('queueRunnerData', array(
61 'qrid' => $runner->qrid,
62 'runNextAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/runNext', NULL, FALSE, NULL, FALSE ),
63 'skipNextAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/skipNext', NULL, FALSE, NULL, FALSE ),
64 'onEndAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/onEnd', NULL, FALSE, NULL, FALSE ),
65 'completed' => 0,
66 'numberOfItems' => $runner->queue->numberOfItems(),
67 'buttons' => $runner->buttons,
68 ));
69
70 if ($runner->isMinimal) {
71 // Render page header
72 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region::instance('html-header', FALSE)) {
73 CRM_Utils_System::addHTMLHead($region->render(''));
74 }
75 $smarty = CRM_Core_Smarty::singleton();
76 $content = $smarty->fetch('CRM/Queue/Page/Runner.tpl');
77 echo CRM_Utils_System::theme($content, $this->_print, TRUE);
78 }
79 else {
80 parent::run();
81 }
82 }
83 }