- md5
- e7912b0973aa96630310c91582e62307
- sha1
- f6d1baaff5d5fa8a3b6c7f29c8dea91a863585c9
- sha256
- 67ee15b91b7df6a57685d3d0ebf42ff60b176453d742911a97500727795b3038
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
<?php
/**
* @package Joomla.Plugin
* @subpackage Versionable
*
* @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event as CmsEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Helper\CMSHelper;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Versioning\VersionableTableInterface;
use Joomla\CMS\Versioning\Versioning;
use Joomla\Event\DispatcherInterface;
/**
* Implements the Versionable behaviour which allows extensions to automatically support content history for their content items.
*
* This plugin supersedes JTableObserverContenthistory.
*
* @since 4.0.0
*/
class PlgBehaviourVersionable extends CMSPlugin
{
/**
* Constructor
*
* @param DispatcherInterface &$subject The object to observe
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'group', 'params', 'language'
* (this list is not meant to be comprehensive).
*
* @since 4.0.0
*/
public function __construct(&$subject, $config = array())
{
$this->allowLegacyListeners = false;
parent::__construct($subject, $config);
}
/**
* Post-processor for $table->store($updateNulls)
*
* @param CmsEvent\Table\AfterStoreEvent $event The event to handle
*
* @return void
*
* @since 4.0.0
*/
public function onTableAfterStore(CmsEvent\Table\AfterStoreEvent $event)
{
// Extract arguments
/** @var VersionableTableInterface $table */
$table = $event['subject'];
$result = $event['result'];
if (!$result)
{
return;
}
if (!(is_object($table) && $table instanceof VersionableTableInterface))
{
return;
}
// Get the Tags helper and assign the parsed alias
$typeAlias = $table->getTypeAlias();
$aliasParts = explode('.', $typeAlias);
if ($aliasParts[0] === '' || !ComponentHelper::getParams($aliasParts[0])->get('save_history', 0))
{
return;
}
$id = $table->getId();
$helper = new CMSHelper;
$data = $helper->getDataObject($table);
$input = Factory::getApplication()->input;
$jform = $input->get('jform', array(), 'array');
$versionNote = '';
if (isset($jform['version_note']))
{
$versionNote = InputFilter::getInstance()->clean($jform['version_note'], 'string');
}
Versioning::store($typeAlias, $id, $data, $versionNote);
}
/**
* Pre-processor for $table->delete($pk)
*
* @param CmsEvent\Table\BeforeDeleteEvent $event The event to handle
*
* @return void
*
* @since 4.0.0
*/
public function onTableBeforeDelete(CmsEvent\Table\BeforeDeleteEvent $event)
{
// Extract arguments
/** @var VersionableTableInterface $table */
$table = $event['subject'];
if (!(is_object($table) && $table instanceof VersionableTableInterface))
{
return;
}
$typeAlias = $table->getTypeAlias();
$aliasParts = explode('.', $typeAlias);
if ($aliasParts[0] && ComponentHelper::getParams($aliasParts[0])->get('save_history', 0))
{
Versioning::delete($typeAlias, $table->getId());
}
}
}
The same content is in 50 releases, Joomla 4.0.0-beta6 to 4.2.0-beta1. See them all, or every version of this file.