[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Versioning/ -> VersionableControllerTrait.php (source)

   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\Router\Route;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('JPATH_PLATFORM') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Defines the trait for a Versionable Controller Class.
  21   *
  22   * @since  3.10.0
  23   */
  24  trait VersionableControllerTrait
  25  {
  26      /**
  27       * Method to load a row from version history
  28       *
  29       * @return  boolean  True if the record can be loaded, False if it cannot.
  30       *
  31       * @since   4.0.0
  32       */
  33      public function loadhistory()
  34      {
  35          $model = $this->getModel();
  36          $table = $model->getTable();
  37          $historyId = $this->input->getInt('version_id', null);
  38  
  39          if (!$model->loadhistory($historyId, $table)) {
  40              $this->setMessage($model->getError(), 'error');
  41  
  42              $this->setRedirect(
  43                  Route::_(
  44                      'index.php?option=' . $this->option . '&view=' . $this->view_list
  45                      . $this->getRedirectToListAppend(),
  46                      false
  47                  )
  48              );
  49  
  50              return false;
  51          }
  52  
  53          // Determine the name of the primary key for the data.
  54          if (empty($key)) {
  55              $key = $table->getKeyName();
  56          }
  57  
  58          $recordId = $table->$key;
  59  
  60          // To avoid data collisions the urlVar may be different from the primary key.
  61          $urlVar = empty($this->urlVar) ? $key : $this->urlVar;
  62  
  63          // Access check.
  64          if (!$this->allowEdit(array($key => $recordId), $key)) {
  65              $this->setMessage(Text::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'), 'error');
  66  
  67              $this->setRedirect(
  68                  Route::_(
  69                      'index.php?option=' . $this->option . '&view=' . $this->view_list
  70                      . $this->getRedirectToListAppend(),
  71                      false
  72                  )
  73              );
  74              $table->checkIn();
  75  
  76              return false;
  77          }
  78  
  79          $this->setRedirect(
  80              Route::_(
  81                  'index.php?option=' . $this->option . '&view=' . $this->view_item
  82                  . $this->getRedirectToItemAppend($recordId, $urlVar),
  83                  false
  84              )
  85          );
  86  
  87          if (!$table->check() || !$table->store()) {
  88              $this->setMessage($table->getError(), 'error');
  89  
  90              return false;
  91          }
  92  
  93          $this->setMessage(
  94              Text::sprintf(
  95                  'JLIB_APPLICATION_SUCCESS_LOAD_HISTORY',
  96                  $model->getState('save_date'),
  97                  $model->getState('version_note')
  98              )
  99          );
 100  
 101          // Invoke the postSave method to allow for the child class to access the model.
 102          $this->postSaveHook($model);
 103  
 104          return true;
 105      }
 106  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer