- md5
- d94b75f4bc7312d8396e2fca6fb70b41
- sha1
- 1aca4a21cea8c7d064d15a04eacb3b540773f178
- sha256
- f22f1358c4e6393f34c033d055ac28850b35bedb656a61fa6ca48c2e472b659d
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Versioning;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
// phpcs:disable PSR1.Files.SideEffects
\defined('JPATH_PLATFORM') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Defines the trait for a Versionable Controller Class.
*
* @since 3.10.0
*/
trait VersionableControllerTrait
{
/**
* Method to load a row from version history
*
* @return boolean True if the record can be loaded, False if it cannot.
*
* @since 4.0.0
*/
public function loadhistory()
{
$model = $this->getModel();
$table = $model->getTable();
$historyId = $this->input->getInt('version_id', null);
if (!$model->loadhistory($historyId, $table)) {
$this->setMessage($model->getError(), 'error');
$this->setRedirect(
Route::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToListAppend(),
false
)
);
return false;
}
// Determine the name of the primary key for the data.
if (empty($key)) {
$key = $table->getKeyName();
}
$recordId = $table->$key;
// To avoid data collisions the urlVar may be different from the primary key.
$urlVar = empty($this->urlVar) ? $key : $this->urlVar;
// Access check.
if (!$this->allowEdit([$key => $recordId], $key)) {
$this->setMessage(Text::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'), 'error');
$this->setRedirect(
Route::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToListAppend(),
false
)
);
$table->checkIn();
return false;
}
$this->setRedirect(
Route::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend($recordId, $urlVar),
false
)
);
if (!$table->check() || !$table->store()) {
$this->setMessage($table->getError(), 'error');
return false;
}
$this->setMessage(
Text::sprintf(
'JLIB_APPLICATION_SUCCESS_LOAD_HISTORY',
$model->getState('save_date'),
$model->getState('version_note')
)
);
// Invoke the postSave method to allow for the child class to access the model.
$this->postSaveHook($model);
return true;
}
}
The same content is in 6 releases, Joomla 4.2.7-rc1 to 4.3.0-alpha3. See them all, or every version of this file.