File manager - Edit - /home/opticamezl/www/newok/Versioning.tar
Back
VersionableControllerTrait.php 0000644 00000005575 15173024415 0012614 0 ustar 00 <?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; } } VersionableTableInterface.php 0000644 00000001516 15173024415 0012324 0 ustar 00 <?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\Table\TableInterface; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * Interface for a versionable Table class * * @since 3.10.0 */ interface VersionableTableInterface extends TableInterface { /** * Get the type alias for the history table * * The type alias generally is the internal component name with the * content type. Ex.: com_content.article * * @return string The alias as described above * * @since 3.10.0 */ public function getTypeAlias(); } VersionableModelTrait.php 0000644 00000004460 15173024415 0011521 0 ustar 00 <?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; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * 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); } } Versioning.php 0000644 00000012365 15173024415 0007411 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2020 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\Component\ComponentHelper; use Joomla\CMS\Event\AbstractEvent; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Table\Table; use Joomla\CMS\Workflow\WorkflowServiceInterface; use Joomla\Database\ParameterType; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * Handle the versioning of content items * * @since 4.0.0 */ class Versioning { /** * Method to get a list of available versions of this item. * * @param string $typeAlias Typealias of the component * @param integer $id ID of the content item to get * * @return object[] A list of history items * * @since 4.0.0 */ public static function get($typeAlias, $id) { $db = Factory::getDbo(); $itemid = $typeAlias . '.' . $id; $query = $db->getQuery(true); $query->select($db->quoteName('h.version_note') . ',' . $db->quoteName('h.save_date') . ',' . $db->quoteName('u.name')) ->from($db->quoteName('#__history', 'h')) ->leftJoin($db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('h.editor_user_id')) ->where($db->quoteName('item_id') . ' = :item_id') ->bind(':item_id', $itemid, ParameterType::STRING) ->order($db->quoteName('save_date') . ' DESC '); $db->setQuery($query); return $db->loadObjectList(); } /** * Method to delete the history for an item. * * @param string $typeAlias Typealias of the component * @param integer $id ID of the content item to delete * * @return boolean true on success, otherwise false. * * @since 4.0.0 */ public static function delete($typeAlias, $id) { $db = Factory::getDbo(); $itemid = $typeAlias . '.' . $id; $query = $db->getQuery(true); $query->delete($db->quoteName('#__history')) ->where($db->quoteName('item_id') . ' = :item_id') ->bind(':item_id', $itemid, ParameterType::STRING); $db->setQuery($query); return $db->execute(); } /** * Method to save a version snapshot to the content history table. * * @param string $typeAlias Typealias of the content type * @param integer $id ID of the content item * @param mixed $data Array or object of data that can be * en- and decoded into JSON * @param string $note Note for the version to store * * @return boolean True on success, otherwise false. * * @since 4.0.0 */ public static function store($typeAlias, $id, $data, $note = '') { $typeTable = Table::getInstance('Contenttype', 'JTable'); $typeTable->load(['type_alias' => $typeAlias]); $historyTable = Table::getInstance('Contenthistory', 'JTable'); $historyTable->item_id = $typeAlias . '.' . $id; $aliasParts = explode('.', $typeAlias); // Don't store unless we have a non-zero item id if (!$historyTable->item_id) { return true; } // We should allow workflow items interact with the versioning $component = Factory::getApplication()->bootComponent($aliasParts[0]); if ($component instanceof WorkflowServiceInterface && $component->isWorkflowActive($typeAlias)) { PluginHelper::importPlugin('workflow'); // Pre-processing by observers $event = AbstractEvent::create( 'onContentVersioningPrepareTable', [ 'subject' => $historyTable, 'extension' => $typeAlias, ] ); Factory::getApplication()->getDispatcher()->dispatch('onContentVersioningPrepareTable', $event); } $historyTable->version_data = json_encode($data); $historyTable->version_note = $note; // Don't save if hash already exists and same version note $historyTable->sha1_hash = $historyTable->getSha1($data, $typeTable); if ($historyRow = $historyTable->getHashMatch()) { if (!$note || ($historyRow->version_note === $note)) { return true; } else { // Update existing row to set version note $historyTable->version_id = $historyRow->version_id; } } $result = $historyTable->store(); // Load history_limit config from extension. $context = $aliasParts[1] ?? ''; $maxVersionsContext = ComponentHelper::getParams($aliasParts[0])->get('history_limit_' . $context, 0); if ($maxVersionsContext) { $historyTable->deleteOldVersions($maxVersionsContext); } elseif ($maxVersions = ComponentHelper::getParams($aliasParts[0])->get('history_limit', 0)) { $historyTable->deleteOldVersions($maxVersions); } return $result; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings