private function add_row_in_test_table($value, $id = 0) { $parameters = array('value' => $value); $query = 'INSERT INTO ' . $this->test_table . '('; if ($id > 0) { $query .= 'id, '; $parameters['id'] = $id; } $query .= 'value) VALUES ('; if ($id > 0) { $query .= ':id, '; } $query .= ':value)'; $this->querier->inject($query, $parameters); }
/** * @desc Move a menu into a block and save it. Enable or disable it according to the destination block * @param Menu $menu the menu to move * @param int $block the destination block * @param int $position the destination block position * @param bool $save if true, save also the menu */ public static function move(Menu $menu, $block, $position = 0, $save = true) { if ($menu->get_id() > 0 && $menu->is_enabled()) { // Updates the previous block position counter // Only for already existing menu that are enabled, not for new ones $parameters = array('block' => $menu->get_block(), 'position' => $menu->get_block_position()); self::$querier->inject('UPDATE ' . DB_TABLE_MENUS . ' SET position=position - 1 WHERE block=:block AND position > :position', $parameters); } // Disables the menu if the destination block is the NOT_ENABLED block position $menu->enabled($block == Menu::BLOCK_POSITION__NOT_ENABLED ? Menu::MENU_NOT_ENABLED : Menu::MENU_ENABLED); // If not enabled, we do not move it so we can restore its position by reactivating it if ($menu->is_enabled()) { // Moves the menu into the destination block $menu->set_block($block); // Computes the new block position for the menu if (empty($position)) { $position_query = self::get_next_position($menu->get_block()); $menu->set_block_position($position_query); } } if ($save) { self::save($menu); } }
private function update_kernel_tables() { // Création des nouvelles tables pour l'authentification $tables = self::$db_utils->list_tables(true); // Modification de la table member $columns = self::$db_utils->desc_table(PREFIX . 'member'); if (!in_array(PREFIX . 'authentication_method', $tables) || isset($columns['login'])) { self::$db_utils->drop(array(PREFIX . 'authentication_method')); $fields = array('user_id' => array('type' => 'integer', 'length' => 11, 'notnull' => 1), 'method' => array('type' => 'string', 'length' => 32, 'default' => "''"), 'identifier' => array('type' => 'string', 'length' => 128, 'default' => "''"), 'data' => array('type' => 'text', 'length' => 65000)); $options = array('indexes' => array('method' => array('type' => 'unique', 'fields' => array('method', 'identifier')))); self::$db_utils->create_table(PREFIX . 'authentication_method', $fields, $options); } if (!in_array(PREFIX . 'internal_authentication', $tables) || isset($columns['login'])) { self::$db_utils->drop(array(PREFIX . 'internal_authentication')); $fields = array('user_id' => array('type' => 'integer', 'length' => 11, 'autoincrement' => true, 'notnull' => 1), 'login' => array('type' => 'string', 'length' => 255, 'default' => "''"), 'password' => array('type' => 'string', 'length' => 64, 'default' => "''"), 'registration_pass' => array('type' => 'string', 'length' => 30, 'notnull' => 1, 'default' => 0), 'change_password_pass' => array('type' => 'string', 'length' => 64, 'notnull' => 1, 'default' => "''"), 'connection_attemps' => array('type' => 'boolean', 'length' => 4, 'notnull' => 1, 'default' => 0), 'last_connection' => array('type' => 'integer', 'length' => 11, 'notnull' => 1, 'default' => 0), 'approved' => array('type' => 'boolean', 'length' => 1, 'notnull' => 1, 'default' => 0)); $options = array('primary' => array('user_id'), 'indexes' => array('login' => array('type' => 'unique', 'fields' => 'login'))); self::$db_utils->create_table(PREFIX . 'internal_authentication', $fields, $options); } if (!in_array(PREFIX . 'internal_authentication_failures', $tables) || isset($columns['login'])) { self::$db_utils->drop(array(PREFIX . 'internal_authentication_failures')); $fields = array('id' => array('type' => 'integer', 'length' => 11, 'autoincrement' => true, 'notnull' => 1), 'session_id' => array('type' => 'string', 'length' => 64, 'default' => "''"), 'login' => array('type' => 'string', 'length' => 255, 'default' => "''"), 'connection_attemps' => array('type' => 'boolean', 'length' => 4, 'notnull' => 1, 'default' => 0), 'last_connection' => array('type' => 'integer', 'length' => 11, 'notnull' => 1, 'default' => 0)); $options = array('primary' => array('id'), 'indexes' => array('session_id' => array('type' => 'key', 'fields' => 'session_id'))); self::$db_utils->create_table(PREFIX . 'internal_authentication_failures', $fields, $options); } // Insertions des mots de passe des membres actuels dans la nouvelle table if (isset($columns['login'])) { $result = self::$db_querier->select_rows(PREFIX . 'member', array('user_id', 'login', 'password', 'approbation_pass', 'change_password_pass', 'last_connect', 'user_aprob')); while ($row = $result->fetch()) { self::$db_querier->insert(PREFIX . 'authentication_method', array('user_id' => $row['user_id'], 'method' => PHPBoostAuthenticationMethod::AUTHENTICATION_METHOD, 'identifier' => $row['user_id'])); self::$db_querier->insert(PREFIX . 'internal_authentication', array('user_id' => $row['user_id'], 'login' => $row['login'], 'password' => $row['password'], 'registration_pass' => $row['approbation_pass'], 'change_password_pass' => $row['change_password_pass'], 'connection_attemps' => 0, 'last_connection' => $row['last_connect'], 'approved' => $row['user_aprob'])); } $result->dispose(); } $rows_change = array('login' => 'display_name VARCHAR(255)', 'timestamp' => 'registration_date INT(11)', 'user_groups' => 'groups TEXT', 'user_lang' => 'locale VARCHAR(25)', 'user_theme' => 'theme VARCHAR(50)', 'user_mail' => 'email VARCHAR(50)', 'user_show_mail' => 'show_email INT(4)', 'user_editor' => 'editor VARCHAR(15)', 'user_timezone' => 'timezone VARCHAR(50)', 'user_msg' => 'posted_msg INT(6)', 'user_pm' => 'unread_pm INT(6)', 'user_warning' => 'warning_percentage INT(6)', 'user_readonly' => 'delay_readonly INT(11)', 'user_ban' => 'delay_banned INT(11)', 'last_connect' => 'last_connection_date INT(11)'); foreach ($rows_change as $old_name => $new_name) { if (isset($columns[$old_name])) { self::$db_querier->inject('ALTER TABLE ' . PREFIX . 'member CHANGE ' . $old_name . ' ' . $new_name); } } if (isset($columns['password'])) { self::$db_utils->drop_column(PREFIX . 'member', 'password'); } if (isset($columns['test_connect'])) { self::$db_utils->drop_column(PREFIX . 'member', 'test_connect'); } if (isset($columns['approbation_pass'])) { self::$db_utils->drop_column(PREFIX . 'member', 'approbation_pass'); } if (isset($columns['change_password_pass'])) { self::$db_utils->drop_column(PREFIX . 'member', 'change_password_pass'); } if (isset($columns['user_aprob'])) { self::$db_utils->drop_column(PREFIX . 'member', 'user_aprob'); } if (!isset($columns['autoconnect_key'])) { self::$db_utils->add_column(PREFIX . 'member', 'autoconnect_key', array('type' => 'string', 'length' => 64, 'default' => "''")); } if (isset($columns['login'])) { self::$db_querier->inject('ALTER TABLE ' . PREFIX . 'member DROP KEY `user_id`'); } if (isset($columns['display_name']) && !$columns['display_name']['key'] || !isset($columns['display_name'])) { self::$db_querier->inject('ALTER TABLE ' . PREFIX . 'member ADD UNIQUE KEY `display_name` (`display_name`)'); } if (isset($columns['email']) && !$columns['email']['key'] || !isset($columns['email'])) { self::$db_querier->inject('ALTER TABLE ' . PREFIX . 'member ADD UNIQUE KEY `email` (`email`)'); } // Modification des tables extended fields $columns = self::$db_utils->desc_table(PREFIX . 'member_extended_fields'); if (!isset($columns['user_pmtomail'])) { self::$db_utils->add_column(PREFIX . 'member_extended_fields', 'user_pmtomail', array('type' => 'text', 'notnull' => 1)); self::$db_querier->insert(PREFIX . 'member_extended_fields_list', array('position' => 1, 'name' => LangLoader::get_message('type.user_pmtomail', 'admin-user-common'), 'field_name' => 'user_pmtomail', 'description' => '', 'field_type' => 'MemberUserPMToMailExtendedField', 'possible_values' => 's:0:"";', 'default_value' => '', 'required' => 0, 'display' => 0, 'regex' => 0, 'freeze' => 1, 'auth' => serialize(array('r-1' => 2, 'r0' => 2, 'r1' => 3)))); } // Modification de la table sessions $columns = self::$db_utils->desc_table(PREFIX . 'sessions'); $rows_change = array('session_ip' => 'ip VARCHAR(64)', 'session_time' => 'timestamp INT(11)', 'session_script' => 'location_script VARCHAR(100)', 'session_script_title' => 'location_title VARCHAR(100)', 'modules_parameters' => 'cached_data TEXT'); foreach ($rows_change as $old_name => $new_name) { if (isset($columns[$old_name])) { self::$db_querier->inject('ALTER TABLE ' . PREFIX . 'sessions CHANGE ' . $old_name . ' ' . $new_name); } } if (isset($columns['level'])) { self::$db_utils->drop_column(PREFIX . 'sessions', 'level'); } if (isset($columns['session_script_get'])) { self::$db_utils->drop_column(PREFIX . 'sessions', 'session_script_get'); } if (isset($columns['session_flag'])) { self::$db_utils->drop_column(PREFIX . 'sessions', 'session_flag'); } if (isset($columns['user_theme'])) { self::$db_utils->drop_column(PREFIX . 'sessions', 'user_theme'); } if (isset($columns['user_lang'])) { self::$db_utils->drop_column(PREFIX . 'sessions', 'user_lang'); } if (!isset($columns['data'])) { self::$db_utils->add_column(PREFIX . 'sessions', 'data', array('type' => 'text', 'length' => 65000)); } self::$db_querier->inject('ALTER TABLE ' . PREFIX . 'sessions DROP KEY `user_id`'); self::$db_querier->inject('ALTER TABLE ' . PREFIX . 'sessions ADD KEY `user_id` (`user_id`)'); if (isset($columns['timestamp']) && !$columns['timestamp']['key'] || !isset($columns['timestamp'])) { self::$db_querier->inject('ALTER TABLE ' . PREFIX . 'sessions ADD KEY `timestamp` (`timestamp`)'); } }