[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
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\console\command\fixup; 15 16 use Symfony\Component\Console\Input\InputInterface; 17 use Symfony\Component\Console\Output\OutputInterface; 18 use Symfony\Component\Console\Style\SymfonyStyle; 19 20 class fix_left_right_ids extends \phpbb\console\command\command 21 { 22 /** @var \phpbb\user */ 23 protected $user; 24 25 /** @var \phpbb\db\driver\driver_interface */ 26 protected $db; 27 28 /** @var \phpbb\cache\driver\driver_interface */ 29 protected $cache; 30 31 /** 32 * Constructor 33 * 34 * @param \phpbb\user $user User instance 35 * @param \phpbb\db\driver\driver_interface $db Database connection 36 * @param \phpbb\cache\driver\driver_interface $cache Cache instance 37 */ 38 public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache) 39 { 40 $this->user = $user; 41 $this->db = $db; 42 $this->cache = $cache; 43 44 parent::__construct($user); 45 } 46 47 /** 48 * {@inheritdoc} 49 */ 50 protected function configure() 51 { 52 $this 53 ->setName('fixup:fix-left-right-ids') 54 ->setDescription($this->user->lang('CLI_DESCRIPTION_FIX_LEFT_RIGHT_IDS')) 55 ; 56 } 57 58 /** 59 * Executes the command fixup:fix-left-right-ids. 60 * 61 * Repairs the tree structure of the forums and modules. 62 * The code is mainly borrowed from Support toolkit for phpBB Olympus 63 * 64 * @param InputInterface $input An InputInterface instance 65 * @param OutputInterface $output An OutputInterface instance 66 * 67 * @return void 68 */ 69 protected function execute(InputInterface $input, OutputInterface $output) 70 { 71 $io = new SymfonyStyle($input, $output); 72 73 // Fix Left/Right IDs for the modules table 74 $result = $this->db->sql_query('SELECT DISTINCT(module_class) FROM ' . MODULES_TABLE); 75 while ($row = $this->db->sql_fetchrow($result)) 76 { 77 $i = 1; 78 $where = array("module_class = '" . $this->db->sql_escape($row['module_class']) . "'"); 79 $this->fix_ids_tree($i, 'module_id', MODULES_TABLE, 0, $where); 80 } 81 $this->db->sql_freeresult($result); 82 83 // Fix the Left/Right IDs for the forums table 84 $i = 1; 85 $this->fix_ids_tree($i, 'forum_id', FORUMS_TABLE); 86 87 $this->cache->purge(); 88 89 $io->success($this->user->lang('CLI_FIXUP_FIX_LEFT_RIGHT_IDS_SUCCESS')); 90 } 91 92 /** 93 * Item's tree structure rebuild helper 94 * The item is either forum or ACP/MCP/UCP module 95 * 96 * @param int $i Item id offset index 97 * @param string $field The key field to fix, forum_id|module_id 98 * @param string $table The table name to perform, FORUMS_TABLE|MODULES_TABLE 99 * @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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |