Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

fix_left_right_ids.php

Zuletzt modifiziert: 01.05.2026, 11:26 - Dateigröße: 3.99 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\console\command\fixup;
 015   
 016  use Symfony\Component\Console\Input\InputInterface;
 017  use Symfony\Component\Console\Output\OutputInterface;
 018  use Symfony\Component\Console\Style\SymfonyStyle;
 019   
 020  class fix_left_right_ids extends \phpbb\console\command\command
 021  {
 022      /** @var \phpbb\user */
 023      protected $user;
 024   
 025      /** @var \phpbb\db\driver\driver_interface */
 026      protected $db;
 027   
 028      /** @var \phpbb\cache\driver\driver_interface */
 029      protected $cache;
 030   
 031      /**
 032      * Constructor
 033      *
 034      * @param \phpbb\user                            $user    User instance
 035      * @param \phpbb\db\driver\driver_interface        $db        Database connection
 036      * @param \phpbb\cache\driver\driver_interface    $cache    Cache instance
 037      */
 038      public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache)
 039      {
 040          $this->user = $user;
 041          $this->db = $db;
 042          $this->cache = $cache;
 043   
 044          parent::__construct($user);
 045      }
 046   
 047      /**
 048      * {@inheritdoc}
 049      */
 050      protected function configure()
 051      {
 052          $this
 053              ->setName('fixup:fix-left-right-ids')
 054              ->setDescription($this->user->lang('CLI_DESCRIPTION_FIX_LEFT_RIGHT_IDS'))
 055          ;
 056      }
 057   
 058      /**
 059      * Executes the command fixup:fix-left-right-ids.
 060      *
 061      * Repairs the tree structure of the forums and modules.
 062      * The code is mainly borrowed from Support toolkit for phpBB Olympus
 063      *
 064      * @param InputInterface  $input  An InputInterface instance
 065      * @param OutputInterface $output An OutputInterface instance
 066      *
 067      * @return void
 068      */
 069      protected function execute(InputInterface $input, OutputInterface $output)
 070      {
 071          $io = new SymfonyStyle($input, $output);
 072   
 073          // Fix Left/Right IDs for the modules table
 074          $result = $this->db->sql_query('SELECT DISTINCT(module_class) FROM ' . MODULES_TABLE);
 075          while ($row = $this->db->sql_fetchrow($result))
 076          {
 077              $i = 1;
 078              $where = array("module_class = '" . $this->db->sql_escape($row['module_class']) . "'");
 079              $this->fix_ids_tree($i, 'module_id', MODULES_TABLE, 0, $where);
 080          }
 081          $this->db->sql_freeresult($result);
 082   
 083          // Fix the Left/Right IDs for the forums table
 084          $i = 1;
 085          $this->fix_ids_tree($i, 'forum_id', FORUMS_TABLE);
 086   
 087          $this->cache->purge();
 088   
 089          $io->success($this->user->lang('CLI_FIXUP_FIX_LEFT_RIGHT_IDS_SUCCESS'));
 090      }
 091   
 092      /**
 093       * Item's tree structure rebuild helper
 094       * The item is either forum or ACP/MCP/UCP module
 095       *
 096       * @param int        $i            Item id offset index
 097       * @param string    $field        The key field to fix, forum_id|module_id
 098       * @param string    $table        The table name to perform, FORUMS_TABLE|MODULES_TABLE
 099       * @param int        $parent_id    Parent item id
 100       * @param array        $where        Additional WHERE clause condition
 101       *
 102       * @return bool    True on rebuild success, false otherwise
 103       */
 104      protected function fix_ids_tree(&$i, $field, $table, $parent_id = 0, $where = array())
 105      {
 106          $changes_made = false;
 107          $sql = 'SELECT * FROM ' . $table . '
 108              WHERE parent_id = ' . (int) $parent_id .
 109              ((!empty($where)) ? ' AND ' . implode(' AND ', $where) : '') . '
 110              ORDER BY left_id ASC';
 111          $result = $this->db->sql_query($sql);
 112          while ($row = $this->db->sql_fetchrow($result))
 113          {
 114              // Update the left_id for the item
 115              if ($row['left_id'] != $i)
 116              {
 117                  $this->db->sql_query('UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('left_id' => $i)) . " WHERE $field = " . (int) $row[$field]);
 118                  $changes_made = true;
 119              }
 120              $i++;
 121   
 122              // Go through children and update their left/right IDs
 123              $changes_made = (($this->fix_ids_tree($i, $field, $table, $row[$field], $where)) || $changes_made) ? true : false;
 124   
 125              // Update the right_id for the item
 126              if ($row['right_id'] != $i)
 127              {
 128                  $this->db->sql_query('UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('right_id' => $i)) . " WHERE $field = " . (int) $row[$field]);
 129                  $changes_made = true;
 130              }
 131              $i++;
 132          }
 133          $this->db->sql_freeresult($result);
 134   
 135          return $changes_made;
 136      }
 137  }
 138