[ Index ] |
PHP Cross Reference of phpBB-3.1.12-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 19 class fix_left_right_ids extends \phpbb\console\command\command 20 { 21 /** @var \phpbb\user */ 22 protected $user; 23 24 /** @var \phpbb\db\driver\driver_interface */ 25 protected $db; 26 27 /** @var \phpbb\cache\driver\driver_interface */ 28 protected $cache; 29 30 /** 31 * Constructor 32 * 33 * @param \phpbb\user $user User instance 34 * @param \phpbb\db\driver\driver_interface $db Database connection 35 * @param \phpbb\cache\driver\driver_interface $cache Cache instance 36 */ 37 public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache) 38 { 39 $this->user = $user; 40 $this->db = $db; 41 $this->cache = $cache; 42 43 parent::__construct($user); 44 } 45 46 /** 47 * {@inheritdoc} 48 */ 49 protected function configure() 50 { 51 $this 52 ->setName('fixup:fix-left-right-ids') 53 ->setDescription($this->user->lang('CLI_DESCRIPTION_FIX_LEFT_RIGHT_IDS')) 54 ; 55 } 56 57 /** 58 * Executes the command fixup:fix-left-right-ids. 59 * 60 * Repairs the tree structure of the forums and modules. 61 * The code is mainly borrowed from Support toolkit for phpBB Olympus 62 * 63 * @param InputInterface $input An InputInterface instance 64 * @param OutputInterface $output An OutputInterface instance 65 * 66 * @return void 67 */ 68 protected function execute(InputInterface $input, OutputInterface $output) 69 { 70 // Fix Left/Right IDs for the modules table 71 $result = $this->db->sql_query('SELECT DISTINCT(module_class) FROM ' . MODULES_TABLE); 72 while ($row = $this->db->sql_fetchrow($result)) 73 { 74 $i = 1; 75 $where = array("module_class = '" . $this->db->sql_escape($row['module_class']) . "'"); 76 $this->fix_ids_tree($i, 'module_id', MODULES_TABLE, 0, $where); 77 } 78 $this->db->sql_freeresult($result); 79 80 // Fix the Left/Right IDs for the forums table 81 $i = 1; 82 $this->fix_ids_tree($i, 'forum_id', FORUMS_TABLE); 83 84 $this->cache->purge(); 85 86 $output->writeln('<info>' . $this->user->lang('CLI_FIXUP_FIX_LEFT_RIGHT_IDS_SUCCESS') . '</info>'); 87 } 88 89 /** 90 * Item's tree structure rebuild helper 91 * The item is either forum or ACP/MCP/UCP module 92 * 93 * @param int $i Item id offset index 94 * @param string $field The key field to fix, forum_id|module_id 95 * @param string $table The table name to perform, FORUMS_TABLE|MODULES_TABLE 96 * @param int $parent_id Parent item id 97 * @param array $where Additional WHERE clause condition 98 * 99 * @return bool True on rebuild success, false otherwise 100 */ 101 protected function fix_ids_tree(&$i, $field, $table, $parent_id = 0, $where = array()) 102 { 103 $changes_made = false; 104 $sql = 'SELECT * FROM ' . $table . ' 105 WHERE parent_id = ' . (int) $parent_id . 106 ((!empty($where)) ? ' AND ' . implode(' AND ', $where) : '') . ' 107 ORDER BY left_id ASC'; 108 $result = $this->db->sql_query($sql); 109 while ($row = $this->db->sql_fetchrow($result)) 110 { 111 // Update the left_id for the item 112 if ($row['left_id'] != $i) 113 { 114 $this->db->sql_query('UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('left_id' => $i)) . " WHERE $field = " . (int) $row[$field]); 115 $changes_made = true; 116 } 117 $i++; 118 119 // Go through children and update their left/right IDs 120 $changes_made = (($this->fix_ids_tree($i, $field, $table, $row[$field], $where)) || $changes_made) ? true : false; 121 122 // Update the right_id for the item 123 if ($row['right_id'] != $i) 124 { 125 $this->db->sql_query('UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('right_id' => $i)) . " WHERE $field = " . (int) $row[$field]); 126 $changes_made = true; 127 } 128 $i++; 129 } 130 $this->db->sql_freeresult($result); 131 132 return $changes_made; 133 } 134 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |