[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_finder/src/Response/ -> Response.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_finder
   6   *
   7   * @copyright   (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Finder\Administrator\Response;
  12  
  13  use Joomla\CMS\Component\ComponentHelper;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\Log\Log;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * Finder Indexer JSON Response Class
  24   *
  25   * @since  2.5
  26   */
  27  class Response
  28  {
  29      /**
  30       * Class Constructor
  31       *
  32       * @param   mixed  $state  The processing state for the indexer
  33       *
  34       * @since   2.5
  35       */
  36      public function __construct($state)
  37      {
  38          $params = ComponentHelper::getParams('com_finder');
  39  
  40          if ($params->get('enable_logging', '0')) {
  41              $options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
  42              $options['text_file'] = 'indexer.php';
  43              Log::addLogger($options);
  44          }
  45  
  46          // Check if we are dealing with an error.
  47          if ($state instanceof \Exception) {
  48              // Log the error
  49              try {
  50                  Log::add($state->getMessage(), Log::ERROR);
  51              } catch (\RuntimeException $exception) {
  52                  // Informational log only
  53              }
  54  
  55              // Prepare the error response.
  56              $this->error = true;
  57              $this->header = Text::_('COM_FINDER_INDEXER_HEADER_ERROR');
  58              $this->message = $state->getMessage();
  59          } else {
  60              // Prepare the response data.
  61              $this->batchSize = (int) $state->batchSize;
  62              $this->batchOffset = (int) $state->batchOffset;
  63              $this->totalItems = (int) $state->totalItems;
  64              $this->pluginState = $state->pluginState;
  65  
  66              $this->startTime = $state->startTime;
  67              $this->endTime = Factory::getDate()->toSql();
  68  
  69              $this->start = !empty($state->start) ? (int) $state->start : 0;
  70              $this->complete = !empty($state->complete) ? (int) $state->complete : 0;
  71  
  72              // Set the appropriate messages.
  73              if ($this->totalItems <= 0 && $this->complete) {
  74                  $this->header = Text::_('COM_FINDER_INDEXER_HEADER_COMPLETE');
  75                  $this->message = Text::_('COM_FINDER_INDEXER_MESSAGE_COMPLETE');
  76              } elseif ($this->totalItems <= 0) {
  77                  $this->header = Text::_('COM_FINDER_INDEXER_HEADER_OPTIMIZE');
  78                  $this->message = Text::_('COM_FINDER_INDEXER_MESSAGE_OPTIMIZE');
  79              } else {
  80                  $this->header = Text::_('COM_FINDER_INDEXER_HEADER_RUNNING');
  81                  $this->message = Text::_('COM_FINDER_INDEXER_MESSAGE_RUNNING');
  82              }
  83          }
  84      }
  85  }


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