CoreFiles by mySites.guru
TasksController.php111 lines, 2,680 bytes, from Joomla_4.1.0-beta1-Beta-Full_Package.zip
Raw History Compare with 4.0.0-beta7
md5
dd8728d62e86760231430251e4e5ee3c
sha1
7e4a284cf2b0c84bd7532891683f9e6ffe96a68b
sha256
110a4a1cfa3eae8912efc834cee2fdd44303c443e3ba38c3b71866ea8cf35aa4
<?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\Factory;
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 __DEPLOY__VERSION__
	 */
	public function unlock(): void
	{
		// Check for request forgeries
		$this->checkToken();

		/** @var integer[] $cid Items to publish (from request parameters). */
		$cid = $this->input->get('cid', [], 'array');

		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)
				{
					Factory::getApplication()
						->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
			)
		);
	}
}

The same content is in 9 releases, Joomla 4.1.0-beta1 to 4.1.1-rc1. See them all, or every version of this file.