- md5
- ea649f5058661fe640ce626cead099ec
- sha1
- 79a3ffb5b6c8b7006e6a275412948cb17845ad2e
- sha256
- c5b58148870a30d9bdb22e3c6e0da2d5c5010e24f7fe8f5ac62c1e8c6c6b5d0c
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
<?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\Table\Table;
use Joomla\Utilities\ArrayHelper;
/**
* Defines the trait for a Versionable Model Class.
*
* @since 3.10.0
*/
trait VersionableModelTrait
{
/**
* Method to load a row for editing from the version history table.
*
* @param integer $versionId Key to the version history table.
* @param Table $table Content table object being loaded.
*
* @return boolean False on failure or error, true otherwise.
*
* @since 4.0.0
*/
public function loadHistory($versionId, Table &$table)
{
// Only attempt to check the row in if it exists, otherwise do an early exit.
if (!$versionId) {
return false;
}
// Get an instance of the row to checkout.
$historyTable = Table::getInstance('Contenthistory');
if (!$historyTable->load($versionId)) {
$this->setError($historyTable->getError());
return false;
}
$typeAlias = explode('.', $historyTable->item_id);
array_pop($typeAlias);
$rowArray = ArrayHelper::fromObject(json_decode($historyTable->version_data));
$key = $table->getKeyName();
if (implode('.', $typeAlias) != $this->typeAlias) {
$this->setError(Text::_('JLIB_APPLICATION_ERROR_HISTORY_ID_MISMATCH'));
if (isset($rowArray[$key])) {
$table->checkIn($rowArray[$key]);
}
return false;
}
$this->setState('save_date', $historyTable->save_date);
$this->setState('version_note', $historyTable->version_note);
/**
* Load data from current version before replacing it with data from history to avoid error
* if there are some required keys missing in the history data
*/
if (isset($rowArray[$key])) {
$table->load($rowArray[$key]);
}
return $table->bind($rowArray);
}
}
The same content is in 5 releases, Joomla 4.2.0-beta3 to 4.2.1-rc2. See them all, or every version of this file.