[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/phpbb/install/module/install_finish/task/ -> install_extensions.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\install\module\install_finish\task;
  15  
  16  use phpbb\config\db;
  17  use phpbb\install\exception\resource_limit_reached_exception;
  18  
  19  /**
  20   * Installs extensions that exist in ext folder upon install
  21   */
  22  class install_extensions extends \phpbb\install\task_base
  23  {
  24      /**
  25       * @var \phpbb\install\helper\config
  26       */
  27      protected $install_config;
  28  
  29      /**
  30       * @var \phpbb\install\helper\iohandler\iohandler_interface
  31       */
  32      protected $iohandler;
  33  
  34      /**
  35       * @var db
  36       */
  37      protected $config;
  38  
  39      /**
  40       * @var \phpbb\log\log_interface
  41       */
  42      protected $log;
  43  
  44      /**
  45       * @var \phpbb\user
  46       */
  47      protected $user;
  48  
  49      /** @var \phpbb\extension\manager */
  50      protected $extension_manager;
  51  
  52      /** @var \Symfony\Component\Finder\Finder */
  53      protected $finder;
  54  
  55      /** @var string Extension table */
  56      protected $extension_table;
  57  
  58      /** @var \phpbb\db\driver\driver_interface */
  59      protected $db;
  60  
  61      /**
  62       * Constructor
  63       *
  64       * @param \phpbb\install\helper\container_factory                $container
  65       * @param \phpbb\install\helper\config                            $install_config
  66       * @param \phpbb\install\helper\iohandler\iohandler_interface    $iohandler
  67       * @param string                                                $phpbb_root_path phpBB root path
  68       */
  69  	public function __construct(\phpbb\install\helper\container_factory $container, \phpbb\install\helper\config $install_config, \phpbb\install\helper\iohandler\iohandler_interface $iohandler, $phpbb_root_path)
  70      {
  71          $this->install_config    = $install_config;
  72          $this->iohandler        = $iohandler;
  73          $this->extension_table = $container->get_parameter('tables.ext');
  74  
  75          $this->log                = $container->get('log');
  76          $this->config            = $container->get('config');
  77          $this->user                = $container->get('user');
  78          $this->extension_manager = $container->get('ext.manager');
  79          $this->db                = $container->get('dbal.conn');
  80          $this->finder = new \Symfony\Component\Finder\Finder();
  81          $this->finder->in($phpbb_root_path . 'ext/')
  82              ->ignoreUnreadableDirs()
  83              ->depth('< 3')
  84              ->files()
  85              ->name('composer.json');
  86  
  87          /** @var \phpbb\cache\driver\driver_interface $cache */
  88          $cache = $container->get('cache.driver');
  89          $cache->destroy('config');
  90  
  91          global $config;
  92          $config = new db(
  93              $this->db,
  94              $cache,
  95              $container->get_parameter('tables.config')
  96          );
  97  
  98          // Make sure asset version exists in config. Otherwise we might try to
  99          // insert the assets_version setting into the database and cause a
 100          // duplicate entry error.
 101          if (!isset($this->config['assets_version']))
 102          {
 103              $this->config['assets_version'] = 0;
 104          }
 105  
 106          parent::__construct(true);
 107      }
 108  
 109      /**
 110       * {@inheritdoc}
 111       */
 112  	public function run()
 113      {
 114          $this->user->session_begin();
 115          $this->user->setup(array('common', 'acp/common', 'cli'));
 116  
 117          $install_extensions = $this->iohandler->get_input('install-extensions', array());
 118  
 119          $all_available_extensions = $this->extension_manager->all_available();
 120          $i = $this->install_config->get('install_extensions_index', 0);
 121          $available_extensions = array_slice($all_available_extensions, $i);
 122  
 123          // Install extensions
 124          foreach ($available_extensions as $ext_name => $ext_path)
 125          {
 126              if (!empty($install_extensions) && $install_extensions !== ['all'] && !in_array($ext_name, $install_extensions))
 127              {
 128                  continue;
 129              }
 130  
 131              try
 132              {
 133                  $extension = $this->extension_manager->get_extension($ext_name);
 134  
 135                  if (!$extension->is_enableable())
 136                  {
 137                      $this->iohandler->add_log_message(array('CLI_EXTENSION_NOT_ENABLEABLE', $ext_name));
 138                      continue;
 139                  }
 140  
 141                  $this->extension_manager->enable($ext_name);
 142                  $extensions = $this->get_extensions();
 143  
 144                  if (isset($extensions[$ext_name]) && $extensions[$ext_name]['ext_active'])
 145                  {
 146                      // Create log
 147                      $this->log->add('admin', ANONYMOUS, $this->user->ip, 'LOG_EXT_ENABLE', time(), array($ext_name));
 148                      $this->iohandler->add_success_message(array('CLI_EXTENSION_ENABLE_SUCCESS', $ext_name));
 149                  }
 150                  else
 151                  {
 152                      $this->iohandler->add_log_message(array('CLI_EXTENSION_ENABLE_FAILURE', $ext_name));
 153                  }
 154              }
 155              catch (\Exception $e)
 156              {
 157                  // Add fail log and continue
 158                  $this->iohandler->add_log_message(array('CLI_EXTENSION_ENABLE_FAILURE', $ext_name));
 159              }
 160  
 161              $i++;
 162  
 163              // Stop execution if resource limit is reached
 164              if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)
 165              {
 166                  break;
 167              }
 168          }
 169  
 170          $this->install_config->set('install_extensions_index', $i);
 171  
 172          if ($i < count($all_available_extensions))
 173          {
 174              throw new resource_limit_reached_exception();
 175          }
 176      }
 177  
 178      /**
 179       * {@inheritdoc}
 180       */
 181  	static public function get_step_count()
 182      {
 183          return 1;
 184      }
 185  
 186      /**
 187       * {@inheritdoc}
 188       */
 189  	public function get_task_lang_name()
 190      {
 191          return 'TASK_INSTALL_EXTENSIONS';
 192      }
 193  
 194      /**
 195       * Get extensions from database
 196       *
 197       * @return array List of extensions
 198       */
 199  	private function get_extensions()
 200      {
 201          $sql = 'SELECT *
 202              FROM ' . $this->extension_table;
 203  
 204          $result = $this->db->sql_query($sql);
 205          $extensions_row = $this->db->sql_fetchrowset($result);
 206          $this->db->sql_freeresult($result);
 207  
 208          $extensions = array();
 209  
 210          foreach ($extensions_row as $extension)
 211          {
 212              $extensions[$extension['ext_name']] = $extension;
 213          }
 214  
 215          ksort($extensions);
 216  
 217          return $extensions;
 218      }
 219  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1