- md5
- b4be24b840c969145d5350a956d6d404
- sha1
- f1a1d8920fd0b1a0cf740164c8d51e31b115b64f
- sha256
- 801765e5460f8c5417be6336bdc8396e3e2968bacede677d0a908dc040f8b918
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Table\Observer;
defined('JPATH_PLATFORM') or die;
/**
* Table class supporting modified pre-order tree traversal behavior.
*
* @since 3.2
*/
class ContentHistory extends AbstractObserver
{
/**
* Helper object for storing and deleting version history information associated with this table observer
*
* @var \JHelperContenthistory
* @since 3.2
*/
protected $contenthistoryHelper;
/**
* The pattern for this table's TypeAlias
*
* @var string
* @since 3.2
*/
protected $typeAliasPattern = null;
/**
* Not public, so marking private and deprecated, but needed internally in parseTypeAlias for
* PHP < 5.4.0 as it's not passing context $this to closure function.
*
* @var ContentHistory
* @since 3.2
* @deprecated Never use this
* @private
*/
public static $_myTableForPregreplaceOnly;
/**
* Creates the associated observer instance and attaches it to the $observableObject
* Creates the associated content history helper class instance
* $typeAlias can be of the form "{variableName}.type", automatically replacing {variableName} with table-instance variables variableName
*
* @param \JObservableInterface $observableObject The subject object to be observed
* @param array $params ( 'typeAlias' => $typeAlias )
*
* @return ContentHistory
*
* @since 3.2
*/
public static function createObserver(\JObservableInterface $observableObject, $params = array())
{
$typeAlias = $params['typeAlias'];
$observer = new self($observableObject);
$observer->contenthistoryHelper = new \JHelperContenthistory($typeAlias);
$observer->typeAliasPattern = $typeAlias;
return $observer;
}
/**
* Post-processor for $table->store($updateNulls)
*
* @param boolean &$result The result of the load
*
* @return void
*
* @since 3.2
*/
public function onAfterStore(&$result)
{
if ($result)
{
$this->parseTypeAlias();
$aliasParts = explode('.', $this->contenthistoryHelper->typeAlias);
if (\JComponentHelper::getParams($aliasParts[0])->get('save_history', 0))
{
$this->contenthistoryHelper->store($this->table);
}
}
}
/**
* Pre-processor for $table->delete($pk)
*
* @param mixed $pk An optional primary key value to delete. If not set the instance property value is used.
*
* @return void
*
* @since 3.2
* @throws \UnexpectedValueException
*/
public function onBeforeDelete($pk)
{
$this->parseTypeAlias();
$aliasParts = explode('.', $this->contenthistoryHelper->typeAlias);
if (\JComponentHelper::getParams($aliasParts[0])->get('save_history', 0))
{
$this->parseTypeAlias();
$this->contenthistoryHelper->deleteHistory($this->table);
}
}
/**
* Internal method
* Parses a TypeAlias of the form "{variableName}.type", replacing {variableName} with table-instance variables variableName
* Storing result into $this->contenthistoryHelper->typeAlias
*
* @return void
*
* @since 3.2
*/
protected function parseTypeAlias()
{
// Needed for PHP < 5.4.0 as it's not passing context $this to closure function
static::$_myTableForPregreplaceOnly = $this->table;
$this->contenthistoryHelper->typeAlias = preg_replace_callback('/{([^}]+)}/',
function($matches)
{
return ContentHistory::$_myTableForPregreplaceOnly->{$matches[1]};
},
$this->typeAliasPattern
);
}
}
The same content is in 26 releases, Joomla 3.9.2-rc to 3.9.14. See them all, or every version of this file.