- md5
- 8659e5266fdd182a9e3cbae6f7e03d4f
- sha1
- 0da2bcfb8db3a61be319b6e4e46345b0f24c5388
- sha256
- 14197107a93f6d4bbe65cbb41580868a98cfad2d3c35101e08bb55b6d2af828a
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Versioning;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Table\Table;
use Joomla\Utilities\ArrayHelper;
/**
* Defines the trait for a Versionable Model Class.
*
* @since 4.0.0
*/
trait VersionableModelTrait
{
/**
* Method to load a row for editing from the version history table.
*
* @param integer $version_id 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($version_id, Table &$table)
{
// Only attempt to check the row in if it exists, otherwise do an early exit.
if (!$version_id)
{
return false;
}
// Get an instance of the row to checkout.
$historyTable = Table::getInstance('Contenthistory');
if (!$historyTable->load($version_id))
{
$this->setError($historyTable->getError());
return false;
}
$typeAlias = explode('.', $historyTable->item_id);
array_pop($typeAlias);
$rowArray = ArrayHelper::fromObject(json_decode($historyTable->version_data));
if (implode('.', $typeAlias) != $this->typeAlias)
{
$this->setError(Text::_('JLIB_APPLICATION_ERROR_HISTORY_ID_MISMATCH'));
$key = $table->getKeyName();
if (isset($rowArray[$key]))
{
$table->checkIn($rowArray[$key]);
}
return false;
}
$this->setState('save_date', $historyTable->save_date);
$this->setState('version_note', $historyTable->version_note);
return $table->bind($rowArray);
}
}
The same content is in 5 releases, Joomla 4.0.0-beta to 4.0.0-beta5. See them all, or every version of this file.