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`)'); } }
private function create_test_table() { $options_sample = array('primary' => array('id')); $fields_sample = array('id' => array('type' => 'integer', 'autoincrement' => true), 'value' => array('type' => 'string', 'length' => 255)); $this->dbms_utils->create_table($this->test_table, $fields_sample, $options_sample); }
public function test_create_table() { $options_sample = array('primary' => array('id'), 'character_set' => 'utf8', 'collate' => 'utf8_unicode_ci', 'foreignKeys' => array('fk_name' => array('local' => 'ext_id_fk', 'foreign' => 'id', 'foreignTable' => 'events'), 'onDelete' => 'CASCADE')); $fields_sample = array('id' => array('type' => 'integer', 'primary' => true, 'autoincrement' => true), 'name' => array('type' => 'string', 'length' => 255, 'full_text' => true), 'datetime' => array('version' => false, 'type' => 'datetime'), 'ext_id_fk' => array('type' => 'integer')); self::$dbms_utils->create_table('test_table42', $fields_sample, $options_sample); }
private function create_upload_cat_table() { $fields = array('id' => array('type' => 'integer', 'length' => 11, 'autoincrement' => true, 'notnull' => 1), 'id_parent' => array('type' => 'integer', 'length' => 11, 'notnull' => 1, 'default' => 0), 'user_id' => array('type' => 'integer', 'length' => 11, 'notnull' => 1, 'default' => 0), 'name' => array('type' => 'string', 'length' => 150, 'default' => "''")); $options = array('primary' => array('id')); self::$db_utils->create_table(self::$upload_cat_table, $fields, $options); }