[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Versioning; 11 12 use Joomla\CMS\Language\Text; 13 use Joomla\CMS\Table\Table; 14 use Joomla\Utilities\ArrayHelper; 15 16 // phpcs:disable PSR1.Files.SideEffects 17 \defined('JPATH_PLATFORM') or die; 18 // phpcs:enable PSR1.Files.SideEffects 19 20 /** 21 * Defines the trait for a Versionable Model Class. 22 * 23 * @since 3.10.0 24 */ 25 trait VersionableModelTrait 26 { 27 /** 28 * Method to load a row for editing from the version history table. 29 * 30 * @param integer $versionId Key to the version history table. 31 * @param Table $table Content table object being loaded. 32 * 33 * @return boolean False on failure or error, true otherwise. 34 * 35 * @since 4.0.0 36 */ 37 public function loadHistory($versionId, Table &$table) 38 { 39 // Only attempt to check the row in if it exists, otherwise do an early exit. 40 if (!$versionId) { 41 return false; 42 } 43 44 // Get an instance of the row to checkout. 45 $historyTable = Table::getInstance('Contenthistory'); 46 47 if (!$historyTable->load($versionId)) { 48 $this->setError($historyTable->getError()); 49 50 return false; 51 } 52 53 $typeAlias = explode('.', $historyTable->item_id); 54 array_pop($typeAlias); 55 56 $rowArray = ArrayHelper::fromObject(json_decode($historyTable->version_data)); 57 58 $key = $table->getKeyName(); 59 60 if (implode('.', $typeAlias) != $this->typeAlias) { 61 $this->setError(Text::_('JLIB_APPLICATION_ERROR_HISTORY_ID_MISMATCH')); 62 63 if (isset($rowArray[$key])) { 64 $table->checkIn($rowArray[$key]); 65 } 66 67 return false; 68 } 69 70 $this->setState('save_date', $historyTable->save_date); 71 $this->setState('version_note', $historyTable->version_note); 72 73 /** 74 * Load data from current version before replacing it with data from history to avoid error 75 * if there are some required keys missing in the history data 76 */ 77 78 if (isset($rowArray[$key])) { 79 $table->load($rowArray[$key]); 80 } 81 82 return $table->bind($rowArray); 83 } 84 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |