[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/phpbb/install/module/install_data/task/ -> add_modules.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_data\task;
  15  
  16  use phpbb\install\exception\resource_limit_reached_exception;
  17  use phpbb\install\helper\config;
  18  use phpbb\install\helper\container_factory;
  19  use phpbb\install\helper\iohandler\iohandler_interface;
  20  
  21  class add_modules extends \phpbb\install\task_base
  22  {
  23      /**
  24       * @var config
  25       */
  26      protected $config;
  27  
  28      /**
  29       * @var \phpbb\db\driver\driver_interface
  30       */
  31      protected $db;
  32  
  33      /**
  34       * @var \phpbb\extension\manager
  35       */
  36      protected $extension_manager;
  37  
  38      /**
  39       * @var \phpbb\install\helper\iohandler\iohandler_interface
  40       */
  41      protected $iohandler;
  42  
  43      /**
  44       * @var \phpbb\module\module_manager
  45       */
  46      protected $module_manager;
  47  
  48      /**
  49       * Define the module structure so that we can populate the database without
  50       * needing to hard-code module_id values
  51       *
  52       * @var array
  53       */
  54      protected $module_categories = array(
  55          'acp' => array(
  56              'ACP_CAT_GENERAL' => array(
  57                  'ACP_QUICK_ACCESS',
  58                  'ACP_BOARD_CONFIGURATION',
  59                  'ACP_CLIENT_COMMUNICATION',
  60                  'ACP_SERVER_CONFIGURATION',
  61              ),
  62              'ACP_CAT_FORUMS' => array(
  63                  'ACP_MANAGE_FORUMS',
  64                  'ACP_FORUM_BASED_PERMISSIONS',
  65              ),
  66              'ACP_CAT_POSTING' => array(
  67                  'ACP_MESSAGES',
  68                  'ACP_ATTACHMENTS',
  69              ),
  70              'ACP_CAT_USERGROUP' => array(
  71                  'ACP_CAT_USERS',
  72                  'ACP_GROUPS',
  73                  'ACP_USER_SECURITY',
  74              ),
  75              'ACP_CAT_PERMISSIONS' => array(
  76                  'ACP_GLOBAL_PERMISSIONS',
  77                  'ACP_FORUM_BASED_PERMISSIONS',
  78                  'ACP_PERMISSION_ROLES',
  79                  'ACP_PERMISSION_MASKS',
  80              ),
  81              'ACP_CAT_CUSTOMISE' => array(
  82                  'ACP_STYLE_MANAGEMENT',
  83                  'ACP_EXTENSION_MANAGEMENT',
  84                  'ACP_LANGUAGE',
  85              ),
  86              'ACP_CAT_MAINTENANCE' => array(
  87                  'ACP_FORUM_LOGS',
  88                  'ACP_CAT_DATABASE',
  89              ),
  90              'ACP_CAT_SYSTEM' => array(
  91                  'ACP_AUTOMATION',
  92                  'ACP_GENERAL_TASKS',
  93                  'ACP_MODULE_MANAGEMENT',
  94              ),
  95              'ACP_CAT_DOT_MODS' => null,
  96          ),
  97          'mcp' => array(
  98              'MCP_MAIN'        => null,
  99              'MCP_QUEUE'        => null,
 100              'MCP_REPORTS'    => null,
 101              'MCP_NOTES'        => null,
 102              'MCP_WARN'        => null,
 103              'MCP_LOGS'        => null,
 104              'MCP_BAN'        => null,
 105          ),
 106          'ucp' => array(
 107              'UCP_MAIN'            => null,
 108              'UCP_PROFILE'        => null,
 109              'UCP_PREFS'            => null,
 110              'UCP_PM'            => null,
 111              'UCP_USERGROUPS'    => null,
 112              'UCP_ZEBRA'            => null,
 113          ),
 114      );
 115  
 116      /**
 117       * @var array
 118       */
 119      protected $module_categories_basenames = array(
 120          'UCP_PM' => 'ucp_pm',
 121      );
 122  
 123      /**
 124       * @var array
 125       */
 126      protected $module_extras = array(
 127          'acp'    => array(
 128              'ACP_QUICK_ACCESS' => array(
 129                  'ACP_MANAGE_USERS',
 130                  'ACP_GROUPS_MANAGE',
 131                  'ACP_MANAGE_FORUMS',
 132                  'ACP_MOD_LOGS',
 133                  'ACP_BOTS',
 134                  'ACP_PHP_INFO',
 135              ),
 136              'ACP_FORUM_BASED_PERMISSIONS' => array(
 137                  'ACP_FORUM_PERMISSIONS',
 138                  'ACP_FORUM_PERMISSIONS_COPY',
 139                  'ACP_FORUM_MODERATORS',
 140                  'ACP_USERS_FORUM_PERMISSIONS',
 141                  'ACP_GROUPS_FORUM_PERMISSIONS',
 142              ),
 143          ),
 144      );
 145  
 146      /**
 147       * Constructor
 148       *
 149       * @parma config                $config        Installer's config
 150       * @param iohandler_interface    $iohandler    Installer's input-output handler
 151       * @param container_factory        $container    Installer's DI container
 152       */
 153  	public function __construct(config $config, iohandler_interface $iohandler, container_factory $container)
 154      {
 155          $this->config                = $config;
 156          $this->db                    = $container->get('dbal.conn');
 157          $this->extension_manager    = $container->get('ext.manager');
 158          $this->iohandler            = $iohandler;
 159          $this->module_manager        = $container->get('module.manager');
 160  
 161          parent::__construct(true);
 162      }
 163  
 164      /**
 165       * {@inheritdoc}
 166       */
 167  	public function run()
 168      {
 169          $this->db->sql_return_on_error(true);
 170  
 171          $module_classes = array('acp', 'mcp', 'ucp');
 172          $total = count($module_classes);
 173          $i = $this->config->get('module_class_index', 0);
 174          $module_classes = array_slice($module_classes, $i);
 175  
 176          foreach ($module_classes as $module_class)
 177          {
 178              $categories = $this->config->get('module_categories_array', array());
 179  
 180              $k = $this->config->get('module_categories_index', 0);
 181              $module_categories = array_slice($this->module_categories[$module_class], $k);
 182              $timed_out = false;
 183  
 184              foreach ($module_categories as $cat_name => $subs)
 185              {
 186                  // Check if this sub-category has a basename. If it has, use it.
 187                  $basename = (isset($this->module_categories_basenames[$cat_name])) ? $this->module_categories_basenames[$cat_name] : '';
 188  
 189                  $module_data = array(
 190                      'module_basename'    => $basename,
 191                      'module_enabled'    => 1,
 192                      'module_display'    => 1,
 193                      'parent_id'            => 0,
 194                      'module_class'        => $module_class,
 195                      'module_langname'    => $cat_name,
 196                      'module_mode'        => '',
 197                      'module_auth'        => '',
 198                  );
 199  
 200                  $this->module_manager->update_module_data($module_data);
 201  
 202                  // Check for last sql error happened
 203                  if ($this->db->get_sql_error_triggered())
 204                  {
 205                      $error = $this->db->sql_error($this->db->get_sql_error_sql());
 206                      $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
 207                  }
 208  
 209                  $categories[$cat_name]['id'] = (int) $module_data['module_id'];
 210                  $categories[$cat_name]['parent_id'] = 0;
 211  
 212                  if (is_array($subs))
 213                  {
 214                      foreach ($subs as $level2_name)
 215                      {
 216                          // Check if this sub-category has a basename. If it has, use it.
 217                          $basename = (isset($this->module_categories_basenames[$level2_name])) ? $this->module_categories_basenames[$level2_name] : '';
 218  
 219                          $module_data = array(
 220                              'module_basename'    => $basename,
 221                              'module_enabled'    => 1,
 222                              'module_display'    => 1,
 223                              'parent_id'            => (int) $categories[$cat_name]['id'],
 224                              'module_class'        => $module_class,
 225                              'module_langname'    => $level2_name,
 226                              'module_mode'        => '',
 227                              'module_auth'        => '',
 228                          );
 229  
 230                          $this->module_manager->update_module_data($module_data);
 231  
 232                          // Check for last sql error happened
 233                          if ($this->db->get_sql_error_triggered())
 234                          {
 235                              $error = $this->db->sql_error($this->db->get_sql_error_sql());
 236                              $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
 237                          }
 238  
 239                          $categories[$level2_name]['id'] = (int) $module_data['module_id'];
 240                          $categories[$level2_name]['parent_id'] = (int) $categories[$cat_name]['id'];
 241                      }
 242                  }
 243  
 244                  $k++;
 245  
 246                  // Stop execution if resource limit is reached
 247                  if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
 248                  {
 249                      $timed_out = true;
 250                      break;
 251                  }
 252              }
 253  
 254              $this->config->set('module_categories_array', $categories);
 255              $this->config->set('module_categories_index', $k);
 256  
 257              if ($timed_out)
 258              {
 259                  throw new resource_limit_reached_exception();
 260              }
 261  
 262              // Get the modules we want to add... returned sorted by name
 263              $module_info = $this->module_manager->get_module_infos($module_class);
 264  
 265              $k = $this->config->get('module_info_index', 0);
 266              $module_info = array_slice($module_info, $k);
 267  
 268              foreach ($module_info as $module_basename => $fileinfo)
 269              {
 270                  foreach ($fileinfo['modes'] as $module_mode => $row)
 271                  {
 272                      foreach ($row['cat'] as $cat_name)
 273                      {
 274                          if (!isset($categories[$cat_name]))
 275                          {
 276                              continue;
 277                          }
 278  
 279                          $module_data = array(
 280                              'module_basename'    => $module_basename,
 281                              'module_enabled'    => 1,
 282                              'module_display'    => (isset($row['display'])) ? (int) $row['display'] : 1,
 283                              'parent_id'            => (int) $categories[$cat_name]['id'],
 284                              'module_class'        => $module_class,
 285                              'module_langname'    => $row['title'],
 286                              'module_mode'        => $module_mode,
 287                              'module_auth'        => $row['auth'],
 288                          );
 289  
 290                          $this->module_manager->update_module_data($module_data);
 291  
 292                          // Check for last sql error happened
 293                          if ($this->db->get_sql_error_triggered())
 294                          {
 295                              $error = $this->db->sql_error($this->db->get_sql_error_sql());
 296                              $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
 297                          }
 298                      }
 299                  }
 300  
 301                  $k++;
 302  
 303                  // Stop execution if resource limit is reached
 304                  if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
 305                  {
 306                      $timed_out = true;
 307                      break;
 308                  }
 309              }
 310  
 311              $this->config->set('module_info_index', $k);
 312  
 313              // Stop execution if resource limit is reached
 314              if ($timed_out)
 315              {
 316                  throw new resource_limit_reached_exception();
 317              }
 318  
 319              // Move some of the modules around since the code above will put them in the wrong place
 320              if (!$this->config->get('modules_ordered', false))
 321              {
 322                  $this->order_modules($module_class);
 323                  $this->config->set('modules_ordered', true);
 324  
 325                  // Stop execution if resource limit is reached
 326                  if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
 327                  {
 328                      throw new resource_limit_reached_exception();
 329                  }
 330              }
 331  
 332              // And now for the special ones
 333              // (these are modules which appear in multiple categories and thus get added manually
 334              // to some for more control)
 335              if (isset($this->module_extras[$module_class]))
 336              {
 337                  $this->add_module_extras($module_class);
 338              }
 339  
 340              $this->module_manager->remove_cache_file($module_class);
 341  
 342              $i++;
 343  
 344              $this->config->set('module_class_index', $i);
 345              $this->config->set('module_categories_index', 0);
 346              $this->config->set('module_info_index', 0);
 347              $this->config->set('added_extra_modules', false);
 348              $this->config->set('modules_ordered', false);
 349              $this->config->set('module_categories_array', array());
 350  
 351              // Stop execution if resource limit is reached
 352              if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
 353              {
 354                  break;
 355              }
 356          }
 357  
 358          if ($i < $total)
 359          {
 360              throw new resource_limit_reached_exception();
 361          }
 362      }
 363  
 364      /**
 365       * Move modules to their correct place
 366       *
 367       * @param string    $module_class
 368       */
 369  	protected function order_modules($module_class)
 370      {
 371          if ($module_class == 'acp')
 372          {
 373              // Move main module 4 up...
 374              $sql = 'SELECT *
 375                  FROM ' . MODULES_TABLE . "
 376                  WHERE module_basename = 'acp_main'
 377                      AND module_class = 'acp'
 378                      AND module_mode = 'main'";
 379              $result = $this->db->sql_query($sql);
 380              $row = $this->db->sql_fetchrow($result);
 381              $this->db->sql_freeresult($result);
 382  
 383              $this->module_manager->move_module_by($row, 'acp', 'move_up', 4);
 384  
 385              // Move permissions intro screen module 4 up...
 386              $sql = 'SELECT *
 387                  FROM ' . MODULES_TABLE . "
 388                  WHERE module_basename = 'acp_permissions'
 389                      AND module_class = 'acp'
 390                      AND module_mode = 'intro'";
 391              $result = $this->db->sql_query($sql);
 392              $row = $this->db->sql_fetchrow($result);
 393              $this->db->sql_freeresult($result);
 394  
 395              $this->module_manager->move_module_by($row, 'acp', 'move_up', 4);
 396  
 397              // Move manage users screen module 5 up...
 398              $sql = 'SELECT *
 399                  FROM ' . MODULES_TABLE . "
 400                  WHERE module_basename = 'acp_users'
 401                      AND module_class = 'acp'
 402                      AND module_mode = 'overview'";
 403              $result = $this->db->sql_query($sql);
 404              $row = $this->db->sql_fetchrow($result);
 405              $this->db->sql_freeresult($result);
 406  
 407              $this->module_manager->move_module_by($row, 'acp', 'move_up', 5);
 408  
 409              // Move extension management module 1 up...
 410              $sql = 'SELECT *
 411                  FROM ' . MODULES_TABLE . "
 412                  WHERE module_langname = 'ACP_EXTENSION_MANAGEMENT'
 413                      AND module_class = 'acp'
 414                      AND module_mode = ''
 415                      AND module_basename = ''";
 416              $result = $this->db->sql_query($sql);
 417              $row = $this->db->sql_fetchrow($result);
 418              $this->db->sql_freeresult($result);
 419  
 420              $this->module_manager->move_module_by($row, 'acp', 'move_up', 1);
 421          }
 422  
 423          if ($module_class == 'mcp')
 424          {
 425              // Move pm report details module 3 down...
 426              $sql = 'SELECT *
 427                  FROM ' . MODULES_TABLE . "
 428                  WHERE module_basename = 'mcp_pm_reports'
 429                      AND module_class = 'mcp'
 430                      AND module_mode = 'pm_report_details'";
 431              $result = $this->db->sql_query($sql);
 432              $row = $this->db->sql_fetchrow($result);
 433              $this->db->sql_freeresult($result);
 434  
 435              $this->module_manager->move_module_by($row, 'mcp', 'move_down', 3);
 436  
 437              // Move closed pm reports module 3 down...
 438              $sql = 'SELECT *
 439                  FROM ' . MODULES_TABLE . "
 440                  WHERE module_basename = 'mcp_pm_reports'
 441                      AND module_class = 'mcp'
 442                      AND module_mode = 'pm_reports_closed'";
 443              $result = $this->db->sql_query($sql);
 444              $row = $this->db->sql_fetchrow($result);
 445              $this->db->sql_freeresult($result);
 446  
 447              $this->module_manager->move_module_by($row, 'mcp', 'move_down', 3);
 448  
 449              // Move open pm reports module 3 down...
 450              $sql = 'SELECT *
 451                  FROM ' . MODULES_TABLE . "
 452                  WHERE module_basename = 'mcp_pm_reports'
 453                      AND module_class = 'mcp'
 454                      AND module_mode = 'pm_reports'";
 455              $result = $this->db->sql_query($sql);
 456              $row = $this->db->sql_fetchrow($result);
 457              $this->db->sql_freeresult($result);
 458  
 459              $this->module_manager->move_module_by($row, 'mcp', 'move_down', 3);
 460          }
 461  
 462          if ($module_class == 'ucp')
 463          {
 464              // Move attachment module 4 down...
 465              $sql = 'SELECT *
 466                  FROM ' . MODULES_TABLE . "
 467                  WHERE module_basename = 'ucp_attachments'
 468                      AND module_class = 'ucp'
 469                      AND module_mode = 'attachments'";
 470              $result = $this->db->sql_query($sql);
 471              $row = $this->db->sql_fetchrow($result);
 472              $this->db->sql_freeresult($result);
 473  
 474              $this->module_manager->move_module_by($row, 'ucp', 'move_down', 4);
 475  
 476              // Move notification options module 4 down...
 477              $sql = 'SELECT *
 478                  FROM ' . MODULES_TABLE . "
 479                  WHERE module_basename = 'ucp_notifications'
 480                      AND module_class = 'ucp'
 481                      AND module_mode = 'notification_options'";
 482              $result = $this->db->sql_query($sql);
 483              $row = $this->db->sql_fetchrow($result);
 484              $this->db->sql_freeresult($result);
 485  
 486              $this->module_manager->move_module_by($row, 'ucp', 'move_down', 4);
 487  
 488              // Move OAuth module 5 down...
 489              $sql = 'SELECT *
 490                  FROM ' . MODULES_TABLE . "
 491                  WHERE module_basename = 'ucp_auth_link'
 492                      AND module_class = 'ucp'
 493                      AND module_mode = 'auth_link'";
 494              $result = $this->db->sql_query($sql);
 495              $row = $this->db->sql_fetchrow($result);
 496              $this->db->sql_freeresult($result);
 497  
 498              $this->module_manager->move_module_by($row, 'ucp', 'move_down', 5);
 499          }
 500      }
 501  
 502      /**
 503       * Add extra modules
 504       *
 505       * @param string    $module_class
 506       */
 507  	protected function add_module_extras($module_class)
 508      {
 509          foreach ($this->module_extras[$module_class] as $cat_name => $mods)
 510          {
 511              $sql = 'SELECT module_id, left_id, right_id
 512                  FROM ' . MODULES_TABLE . "
 513                  WHERE module_langname = '" . $this->db->sql_escape($cat_name) . "'
 514                      AND module_class = '" . $this->db->sql_escape($module_class) . "'";
 515              $result = $this->db->sql_query_limit($sql, 1);
 516              $row2 = $this->db->sql_fetchrow($result);
 517              $this->db->sql_freeresult($result);
 518  
 519              foreach ($mods as $mod_name)
 520              {
 521                  $sql = 'SELECT *
 522                      FROM ' . MODULES_TABLE . "
 523                      WHERE module_langname = '" . $this->db->sql_escape($mod_name) . "'
 524                          AND module_class = '" . $this->db->sql_escape($module_class) . "'
 525                          AND module_basename <> ''";
 526                  $result = $this->db->sql_query_limit($sql, 1);
 527                  $row = $this->db->sql_fetchrow($result);
 528                  $this->db->sql_freeresult($result);
 529  
 530                  $module_data = array(
 531                      'module_basename'    => $row['module_basename'],
 532                      'module_enabled'    => (int) $row['module_enabled'],
 533                      'module_display'    => (int) $row['module_display'],
 534                      'parent_id'            => (int) $row2['module_id'],
 535                      'module_class'        => $row['module_class'],
 536                      'module_langname'    => $row['module_langname'],
 537                      'module_mode'        => $row['module_mode'],
 538                      'module_auth'        => $row['module_auth'],
 539                  );
 540  
 541                  $this->module_manager->update_module_data($module_data);
 542  
 543                  // Check for last sql error happened
 544                  if ($this->db->get_sql_error_triggered())
 545                  {
 546                      $error = $this->db->sql_error($this->db->get_sql_error_sql());
 547                      $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
 548                  }
 549              }
 550          }
 551      }
 552  
 553      /**
 554       * {@inheritdoc}
 555       */
 556  	static public function get_step_count()
 557      {
 558          return 1;
 559      }
 560  
 561      /**
 562       * {@inheritdoc}
 563       */
 564  	public function get_task_lang_name()
 565      {
 566          return 'TASK_ADD_MODULES';
 567      }
 568  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1