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

update_extensions.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 6.69 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\update_database\task;
 015   
 016  use phpbb\install\exception\resource_limit_reached_exception;
 017  use phpbb\install\helper\container_factory;
 018  use phpbb\install\helper\config;
 019  use phpbb\install\helper\iohandler\iohandler_interface;
 020  use phpbb\install\helper\update_helper;
 021  use phpbb\install\task_base;
 022  use Symfony\Component\Finder\Finder;
 023   
 024  /**
 025   * Installs extensions that exist in ext folder upon install
 026   */
 027  class update_extensions extends task_base
 028  {
 029      /**
 030       * @var \phpbb\cache\driver\driver_interface
 031       */
 032      protected $cache;
 033   
 034      /**
 035       * @var config
 036       */
 037      protected $install_config;
 038   
 039      /**
 040       * @var iohandler_interface
 041       */
 042      protected $iohandler;
 043   
 044      /** @var update_helper */
 045      protected $update_helper;
 046   
 047      /**
 048       * @var \phpbb\config\db
 049       */
 050      protected $config;
 051   
 052      /**
 053       * @var \phpbb\log\log_interface
 054       */
 055      protected $log;
 056   
 057      /**
 058       * @var \phpbb\user
 059       */
 060      protected $user;
 061   
 062      /** @var \phpbb\extension\manager */
 063      protected $extension_manager;
 064   
 065      /** @var Finder */
 066      protected $finder;
 067   
 068      /** @var string Extension table */
 069      protected $extension_table;
 070   
 071      /** @var \phpbb\db\driver\driver_interface */
 072      protected $db;
 073   
 074      /**
 075       * @var array    List of default extensions to update, grouped by version
 076       *                they were added
 077       */
 078      static public $default_extensions_update = [
 079          '3.2.0-RC2' => ['phpbb/viglink']
 080      ];
 081   
 082      /**
 083       * Constructor
 084       *
 085       * @param container_factory            $container
 086       * @param config                    $install_config
 087       * @param iohandler_interface        $iohandler
 088       * @param $update_helper            $update_helper
 089       * @param string                    $phpbb_root_path phpBB root path
 090       */
 091      public function __construct(container_factory $container, config $install_config, iohandler_interface $iohandler, update_helper $update_helper, $phpbb_root_path)
 092      {
 093          $this->install_config    = $install_config;
 094          $this->iohandler        = $iohandler;
 095          $this->extension_table = $container->get_parameter('tables.ext');
 096   
 097          $this->log                = $container->get('log');
 098          $this->user                = $container->get('user');
 099          $this->extension_manager = $container->get('ext.manager');
 100          $this->cache                = $container->get('cache.driver');
 101          $this->config            = $container->get('config');
 102          $this->db                = $container->get('dbal.conn');
 103          $this->update_helper = $update_helper;
 104          $this->finder = new Finder();
 105          $this->finder->in($phpbb_root_path . 'ext/')
 106              ->ignoreUnreadableDirs()
 107              ->depth('< 3')
 108              ->files()
 109              ->name('composer.json');
 110   
 111          // Make sure asset version exists in config. Otherwise we might try to
 112          // insert the assets_version setting into the database and cause a
 113          // duplicate entry error.
 114          if (!isset($this->config['assets_version']))
 115          {
 116              $this->config['assets_version'] = 0;
 117          }
 118   
 119          parent::__construct(true);
 120      }
 121   
 122      /**
 123       * {@inheritdoc}
 124       */
 125      public function run()
 126      {
 127          $this->user->session_begin();
 128          $this->user->setup(array('common', 'acp/common', 'cli'));
 129   
 130          $update_info = $this->install_config->get('update_info_unprocessed', []);
 131          $version_from = !empty($update_info) ? $update_info['version']['from'] : $this->config['version_update_from'];
 132   
 133          if (!empty($version_from))
 134          {
 135              $update_extensions = $this->iohandler->get_input('update-extensions', []);
 136   
 137              // Create list of default extensions that need to be enabled in update
 138              $default_update_extensions = [];
 139              foreach (self::$default_extensions_update as $version => $extensions)
 140              {
 141                  if ($this->update_helper->phpbb_version_compare($version_from, $version, '<'))
 142                  {
 143                      $default_update_extensions = array_merge($default_update_extensions, $extensions);
 144                  }
 145              }
 146   
 147              $all_available_extensions = $this->extension_manager->all_available();
 148              $i = $this->install_config->get('update_extensions_index', 0);
 149              $available_extensions = array_slice($all_available_extensions, $i);
 150   
 151              // Update available extensions
 152              foreach ($available_extensions as $ext_name => $ext_path)
 153              {
 154                  // Update extensions if:
 155                  //    1) Extension is currently enabled
 156                  //    2) Extension was implicitly defined as needing an update
 157                  //    3) Extension was newly added as default phpBB extension in
 158                  //        this update and should be enabled by default.
 159                  if ($this->extension_manager->is_enabled($ext_name) ||
 160                      in_array($ext_name, $update_extensions) ||
 161                      in_array($ext_name, $default_update_extensions)
 162                  )
 163                  {
 164                      try
 165                      {
 166                          $extension_enabled = $this->extension_manager->is_enabled($ext_name);
 167                          if ($extension_enabled)
 168                          {
 169                              $this->extension_manager->disable($ext_name);
 170                          }
 171                          $this->extension_manager->enable($ext_name);
 172                          $extensions = $this->get_extensions();
 173   
 174                          if (isset($extensions[$ext_name]) && $extensions[$ext_name]['ext_active'])
 175                          {
 176                              // Create log
 177                              $this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_UPDATE', time(), array($ext_name));
 178                              $this->iohandler->add_success_message(array('CLI_EXTENSION_UPDATE_SUCCESS', $ext_name));
 179                          }
 180                          else
 181                          {
 182                              $this->iohandler->add_log_message('CLI_EXTENSION_UPDATE_FAILURE', array($ext_name));
 183                          }
 184   
 185                          // Disable extensions if it was disabled by the admin before
 186                          if (!$extension_enabled && !in_array($ext_name, $default_update_extensions))
 187                          {
 188                              $this->extension_manager->disable($ext_name);
 189                          }
 190                      }
 191                      catch (\Exception $e)
 192                      {
 193                          // Add fail log and continue
 194                          $this->iohandler->add_log_message('CLI_EXTENSION_UPDATE_FAILURE', array($ext_name));
 195                      }
 196                  }
 197   
 198                  $i++;
 199   
 200                  // Stop execution if resource limit is reached
 201                  if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)
 202                  {
 203                      break;
 204                  }
 205              }
 206   
 207              $this->install_config->set('update_extensions_index', $i);
 208   
 209              if ($i < sizeof($all_available_extensions))
 210              {
 211                  throw new resource_limit_reached_exception();
 212              }
 213          }
 214   
 215          $this->config->delete('version_update_from');
 216   
 217          $this->cache->purge();
 218   
 219          $this->config->increment('assets_version', 1);
 220      }
 221   
 222      /**
 223       * {@inheritdoc}
 224       */
 225      static public function get_step_count()
 226      {
 227          return 1;
 228      }
 229   
 230      /**
 231       * {@inheritdoc}
 232       */
 233      public function get_task_lang_name()
 234      {
 235          return 'TASK_UPDATE_EXTENSIONS';
 236      }
 237   
 238      /**
 239       * Get extensions from database
 240       *
 241       * @return array List of extensions
 242       */
 243      private function get_extensions()
 244      {
 245          $sql = 'SELECT *
 246              FROM ' . $this->extension_table;
 247   
 248          $result = $this->db->sql_query($sql);
 249          $extensions_row = $this->db->sql_fetchrowset($result);
 250          $this->db->sql_freeresult($result);
 251   
 252          $extensions = array();
 253   
 254          foreach ($extensions_row as $extension)
 255          {
 256              $extensions[$extension['ext_name']] = $extension;
 257          }
 258   
 259          ksort($extensions);
 260   
 261          return $extensions;
 262      }
 263  }
 264