Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

install_extensions.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 4.81 KiB


001  <?php
002  /**
003   *
004   * This file is part of the phpBB Forum Software package.
005   *
006   * @copyright (c) phpBB Limited <https://www.phpbb.com>
007   * @license GNU General Public License, version 2 (GPL-2.0)
008   *
009   * For full copyright and license information, please see
010   * the docs/CREDITS.txt file.
011   *
012   */
013   
014  namespace phpbb\install\module\install_finish\task;
015   
016  use phpbb\install\exception\resource_limit_reached_exception;
017   
018  /**
019   * Installs extensions that exist in ext folder upon install
020   */
021  class install_extensions extends \phpbb\install\task_base
022  {
023      /**
024       * @var \phpbb\install\helper\config
025       */
026      protected $install_config;
027   
028      /**
029       * @var \phpbb\install\helper\iohandler\iohandler_interface
030       */
031      protected $iohandler;
032   
033      /**
034       * @var \phpbb\config\db
035       */
036      protected $config;
037   
038      /**
039       * @var \phpbb\log\log_interface
040       */
041      protected $log;
042   
043      /**
044       * @var \phpbb\user
045       */
046      protected $user;
047   
048      /** @var \phpbb\extension\manager */
049      protected $extension_manager;
050   
051      /** @var \Symfony\Component\Finder\Finder */
052      protected $finder;
053   
054      /** @var string Extension table */
055      protected $extension_table;
056   
057      /** @var \phpbb\db\driver\driver_interface */
058      protected $db;
059   
060      /**
061       * Constructor
062       *
063       * @param \phpbb\install\helper\container_factory                $container
064       * @param \phpbb\install\helper\config                            $install_config
065       * @param \phpbb\install\helper\iohandler\iohandler_interface    $iohandler
066       * @param string                                                $phpbb_root_path phpBB root path
067       */
068      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)
069      {
070          $this->install_config    = $install_config;
071          $this->iohandler        = $iohandler;
072          $this->extension_table = $container->get_parameter('tables.ext');
073   
074          $this->log                = $container->get('log');
075          $this->user                = $container->get('user');
076          $this->extension_manager = $container->get('ext.manager');
077          $this->config            = $container->get('config');
078          $this->db                = $container->get('dbal.conn');
079          $this->finder = new \Symfony\Component\Finder\Finder();
080          $this->finder->in($phpbb_root_path . 'ext/')
081              ->ignoreUnreadableDirs()
082              ->depth('< 3')
083              ->files()
084              ->name('composer.json');
085   
086          // Make sure asset version exists in config. Otherwise we might try to
087          // insert the assets_version setting into the database and cause a
088          // duplicate entry error.
089          if (!isset($this->config['assets_version']))
090          {
091              $this->config['assets_version'] = 0;
092          }
093   
094          parent::__construct(true);
095      }
096   
097      /**
098       * {@inheritdoc}
099       */
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                  $this->extension_manager->enable($ext_name);
122                  $extensions = $this->get_extensions();
123   
124                  if (isset($extensions[$ext_name]) && $extensions[$ext_name]['ext_active'])
125                  {
126                      // Create log
127                      $this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_ENABLE', time(), array($ext_name));
128                      $this->iohandler->add_success_message(array('CLI_EXTENSION_ENABLE_SUCCESS', $ext_name));
129                  }
130                  else
131                  {
132                      $this->iohandler->add_log_message(array('CLI_EXTENSION_ENABLE_FAILURE', $ext_name));
133                  }
134              }
135              catch (\Exception $e)
136              {
137                  // Add fail log and continue
138                  $this->iohandler->add_log_message(array('CLI_EXTENSION_ENABLE_FAILURE', $ext_name));
139              }
140   
141              $i++;
142   
143              // Stop execution if resource limit is reached
144              if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)
145              {
146                  break;
147              }
148          }
149   
150          $this->install_config->set('install_extensions_index', $i);
151   
152          if ($i < sizeof($all_available_extensions))
153          {
154              throw new resource_limit_reached_exception();
155          }
156      }
157   
158      /**
159       * {@inheritdoc}
160       */
161      static public function get_step_count()
162      {
163          return 1;
164      }
165   
166      /**
167       * {@inheritdoc}
168       */
169      public function get_task_lang_name()
170      {
171          return 'TASK_INSTALL_EXTENSIONS';
172      }
173   
174      /**
175       * Get extensions from database
176       *
177       * @return array List of extensions
178       */
179      private function get_extensions()
180      {
181          $sql = 'SELECT *
182              FROM ' . $this->extension_table;
183   
184          $result = $this->db->sql_query($sql);
185          $extensions_row = $this->db->sql_fetchrowset($result);
186          $this->db->sql_freeresult($result);
187   
188          $extensions = array();
189   
190          foreach ($extensions_row as $extension)
191          {
192              $extensions[$extension['ext_name']] = $extension;
193          }
194   
195          ksort($extensions);
196   
197          return $extensions;
198      }
199  }
200