[ Index ]

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


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1