-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
TasksController.php
112 lines (99 loc) · 2.65 KB
/
TasksController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* @package Joomla.Administrator
* @subpackage com_scheduler
*
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Scheduler\Administrator\Controller;
// Restrict direct access
\defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\AdminController;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Router\Route;
use Joomla\Component\Scheduler\Administrator\Model\TaskModel;
use Joomla\Utilities\ArrayHelper;
/**
* MVC Controller for TasksView.
*
* @since 4.1.0
*/
class TasksController extends AdminController
{
/**
* Proxy for the parent method.
*
* @param string $name The name of the model.
* @param string $prefix The prefix for the PHP class name.
* @param array $config Array of configuration parameters.
*
* @return BaseDatabaseModel
*
* @since 4.1.0
*/
public function getModel($name = 'Task', $prefix = 'Administrator', $config = ['ignore_request' => true]): BaseDatabaseModel
{
return parent::getModel($name, $prefix, $config);
}
/**
* Unlock a locked task, i.e., a task that is presumably still running but might have crashed and got stuck in the
* "locked" state.
*
* @return void
*
* @since 4.1.0
*/
public function unlock(): void
{
// Check for request forgeries
$this->checkToken();
/** @var integer[] $cid Items to publish (from request parameters). */
$cid = (array) $this->input->get('cid', [], 'int');
// Remove zero values resulting from input filter
$cid = array_filter($cid);
if (empty($cid))
{
$this->app->getLogger()
->warning(Text::_($this->text_prefix . '_NO_ITEM_SELECTED'), array('category' => 'jerror'));
}
else
{
/** @var TaskModel $model */
$model = $this->getModel();
// Make sure the item IDs are integers
$cid = ArrayHelper::toInteger($cid);
// Unlock the items.
try
{
$model->unlock($cid);
$errors = $model->getErrors();
$noticeText = null;
if ($errors)
{
$this->app->enqueueMessage(Text::plural($this->text_prefix . '_N_ITEMS_FAILED_UNLOCKING', \count($cid)), 'error');
}
else
{
$noticeText = $this->text_prefix . '_N_ITEMS_UNLOCKED';
}
if (\count($cid))
{
$this->setMessage(Text::plural($noticeText, \count($cid)));
}
}
catch (\Exception $e)
{
$this->setMessage($e->getMessage(), 'error');
}
}
$this->setRedirect(
Route::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToListAppend(),
false
)
);
}
}