/** delete the database tables for this bean */ function drop_tables() { global $dictionary; $key = $this->getObjectName(); if (!array_key_exists($key, $dictionary)) { $GLOBALS['log']->fatal("drop_tables: Metadata for table " . $this->table_name . " does not exist"); echo "meta data absent for table " . $this->table_name . "<br>\n"; } else { if ($this->db->tableExists($this->table_name)) { $this->dbManager->dropTable($this); } if ($this->db->tableExists($this->table_name . '_cstm')) { $this->dbManager->dropTableName($this->table_name . '_cstm'); DynamicField::deleteCache(); } } }
protected function indexExistsImpl($table, $index_name, $db) { global $mysqlMainDb; if ($db == null) $db = $mysqlMainDb; if (!DBHelper::tableExists($table, $db)) return 0; return count(Database::get()->queryArray("SHOW INDEX FROM `$db`.`$table` WHERE Key_name = ?s", $index_name)) > 0; }
Database::get()->query("ALTER TABLE `logins` CHANGE COLUMN `ip` `ip` VARCHAR(45)"); // There is a special case with user_request storing its IP in numeric format $fields_user_request = Database::get()->queryArray("SHOW COLUMNS FROM user_request"); foreach ($fields_user_request as $row2) { if ($row2->Field == "ip_address") { Database::get()->query("ALTER TABLE `user_request` ADD `request_ip` varchar(45) NOT NULL DEFAULT ''"); Database::get()->queryFunc("SELECT id,INET_NTOA(ip_address) as ip_addr FROM user_request", function ($row) { Database::get()->query("UPDATE `user_request` SET `request_ip` = ?s WHERE `id` = ?s", $row->ip_addr, $row->id); }); Database::get()->query("ALTER TABLE `user_request` DROP `ip_address`"); break; } } } // Rename table `cours` to `course` and `cours_user` to `course_user` if (!DBHelper::tableExists('course')) { DBHelper::fieldExists('cours', 'expand_glossary') or Database::get()->query("ALTER TABLE `cours` ADD `expand_glossary` BOOL NOT NULL DEFAULT 0"); DBHelper::fieldExists('cours', 'glossary_index') or Database::get()->query("ALTER TABLE `cours` ADD `glossary_index` BOOL NOT NULL DEFAULT 1"); Database::get()->query("RENAME TABLE `cours` TO `course`"); Database::get()->query("UPDATE course SET description = '' WHERE description IS NULL"); Database::get()->query("UPDATE course SET course_keywords = '' WHERE course_keywords IS NULL"); if (DBHelper::fieldExists('course', 'course_objectives')) { Database::get()->query("ALTER TABLE course DROP COLUMN `course_objectives`,\n DROP COLUMN `course_prerequisites`,\n DROP COLUMN `course_references`"); } Database::get()->query("ALTER TABLE course CHANGE `cours_id` `id` INT(11) NOT NULL AUTO_INCREMENT,\n CHANGE `languageCourse` `lang` VARCHAR(16) DEFAULT 'el',\n CHANGE `intitule` `title` VARCHAR(250) NOT NULL DEFAULT '',\n CHANGE `description` `description` MEDIUMTEXT NOT NULL,\n CHANGE `course_keywords` `keywords` TEXT NOT NULL,\n DROP COLUMN `course_addon`,\n CHANGE `titulaires` `prof_names` varchar(200) NOT NULL DEFAULT '',\n CHANGE `fake_code` `public_code` varchar(20) NOT NULL DEFAULT '',\n DROP COLUMN `departmentUrlName`,\n DROP COLUMN `departmentUrl`,\n DROP COLUMN `lastVisit`,\n DROP COLUMN `lastEdit`,\n DROP COLUMN `expirationDate`,\n DROP COLUMN `type`,\n DROP COLUMN `faculteid`,\n CHANGE `first_create` `created` datetime NOT NULL default '0000-00-00 00:00:00',\n CHANGE `expand_glossary` `glossary_expand` BOOL NOT NULL DEFAULT 0,\n ADD `view_type` VARCHAR(255) NOT NULL DEFAULT 'units',\n ADD `start_date` DATE NOT NULL default '0000-00-00',\n ADD `finish_date` DATE NOT NULL default '0000-00-00',\n DROP INDEX cours"); Database::get()->queryFunc("SELECT DISTINCT lang from course", function ($old_lang) { Database::get()->query("UPDATE course SET lang = ?s WHERE lang = ?s", langname_to_code($old_lang->lang), $old_lang->lang); }); Database::get()->query("RENAME TABLE `cours_user` TO `course_user`"); Database::get()->query('ALTER TABLE `course_user` CHANGE `statut` `status` TINYINT(4) NOT NULL DEFAULT 0,
/** * @brief upgrade to 2.4 * @global type $langUpgCourse * @global type $mysqlMainDb * @global type $global_messages * @global type $webDir * @param type $code * @param type $lang * @param type $extramessage */ function upgrade_course_2_4($code, $course_id, $lang) { global $langUpgCourse, $mysqlMainDb, $global_messages, $webDir; Database::get()->query("USE `$code`"); // not needed anymore delete_table('stat_accueil'); delete_table('users'); Database::get()->query("UPDATE accueil SET lien = '../../modules/course_info/infocours.php' WHERE id = 14 AND define_var = 'MODULE_ID_COURSEINFO'"); Database::get()->query("UPDATE accueil SET rubrique = " . quote($global_messages['langCourseDescription'][$lang]) . " WHERE id = 20 AND define_var = 'MODULE_ID_DESCRIPTION'"); Database::get()->query("UPDATE accueil SET lien = REPLACE(lien, ' \"target=_blank', '') WHERE lien LIKE '% \"target=_blank'"); Database::get()->query("ALTER TABLE `poll_answer_record` CHANGE `answer_text` `answer_text` TEXT"); // move main documents to central table and if successful drop table if (DBHelper::tableExists('document', $code)) { $doc_id = Database::get()->querySingle("SELECT MAX(id) as max FROM `$mysqlMainDb`.document")->max; if (!$doc_id) { $doc_id = 1; } Database::get()->query("UPDATE `document` SET visibility = '1' WHERE visibility = 'v'"); Database::get()->query("UPDATE `document` SET visibility = '0' WHERE visibility = 'i'"); Database::get()->query("ALTER TABLE `document` CHANGE `visibility` `visible` TINYINT(4) NOT NULL DEFAULT 1"); Database::get()->query("INSERT INTO `$mysqlMainDb`.document (`id`, `course_id`, `subsystem`, `subsystem_id`, `path`, `filename`, `visible`, `comment`, `category`, `title`, `creator`, `date`, `date_modified`, `subject`, `description`, `author`, `format`, `language`, `copyrighted`) SELECT $doc_id + id, $course_id, 0, NULL, `path`, `filename`, `visible`, `comment`, 0 + `category`, `title`, `creator`, `date`, `date_modified`, `subject`, `description`, `author`, `format`, `language`, 0 + `copyrighted` FROM document") and Database::get()->query("DROP TABLE document"); Database::get()->query("UPDATE `$mysqlMainDb`.course_units AS units, `$mysqlMainDb`.unit_resources AS res SET res_id = res_id + $doc_id WHERE units.id = res.unit_id AND course_id = $course_id AND type = 'doc'"); } // move user group information to central tables and if successful drop original tables if (DBHelper::tableExists('group_properties', $code)) { $ok = (Database::get()->query("INSERT INTO `$mysqlMainDb`.`group_properties` (`course_id`, `self_registration`, `private_forum`, `forum`, `documents`, `wiki`, `agenda`) SELECT $course_id, `self_registration`, `private`, `forum`, `document`, `wiki`, `agenda` FROM group_properties") != null); if ($ok) { Database::get()->query("DROP TABLE group_properties"); } $ok = (Database::get()->query("INSERT INTO `$mysqlMainDb`.`group` (`course_id`, `name`, `description`, `forum_id`, `max_members`, `secret_directory`) SELECT $course_id, `name`, `description`, `forumId`, `maxStudent`, `secretDirectory` FROM student_group") != null); Database::get()->query("CREATE TEMPORARY TABLE group_map AS SELECT old.id AS old_id, new.id AS new_id FROM student_group AS old, `$mysqlMainDb`.`group` AS new WHERE new.course_id = $course_id AND old.secretDirectory = new.secret_directory"); $ok = (Database::get()->query("INSERT INTO `$mysqlMainDb`.group_members (group_id, user_id, is_tutor, description) SELECT DISTINCT new_id, tutor, 1, '' FROM student_group, group_map WHERE student_group.id = group_map.old_id AND tutor IS NOT NULL") != null) && $ok; $ok = (Database::get()->query("INSERT INTO `$mysqlMainDb`.group_members (group_id, user_id, is_tutor, description) SELECT DISTINCT new_id, user, 0, '' FROM user_group, group_map WHERE user_group.team = group_map.old_id") != null) && $ok; Database::get()->query("DROP TEMPORARY TABLE group_map"); $ok = move_group_documents_to_main_db($code, $course_id) && $ok; if ($ok) { Database::get()->query("DROP TABLE student_group"); Database::get()->query("DROP TABLE user_group"); Database::get()->query("DROP TABLE group_documents"); } } // move links to central tables and if successful drop original tables if (DBHelper::tableExists('liens', $code)) { Database::get()->query("INSERT INTO `$mysqlMainDb`.link (`id`, `course_id`, `url`, `title`, `description`, `category`, `order`) SELECT `id`, $course_id, `url`, `titre`, `description`, `category`, `ordre` FROM liens") and Database::get()->query("DROP TABLE liens"); Database::get()->query("INSERT INTO `$mysqlMainDb`.link_category (`id`, `course_id`, `name`, `description`, `order`) SELECT `id`, $course_id, `categoryname`, `description`, `ordre` FROM link_categories") and Database::get()->query("DROP TABLE link_categories"); } // upgrade acceuil for glossary if (accueil_tool_missing($code, 'MODULE_ID_GLOSSARY')) { Database::get()->query("INSERT IGNORE INTO accueil VALUES ( '17', '{$global_messages['langGlossary'][$lang]}', '../../modules/glossary/glossary.php', 'glossary', '0', '0', '', 'MODULE_ID_GLOSSARY')"); } // upgrade acceuil for glossary if (accueil_tool_missing($code, 'MODULE_ID_EBOOK')) { Database::get()->query("INSERT IGNORE INTO accueil VALUES ( '18', '{$global_messages['langEBook'][$lang]}', '../../modules/ebook/index.php', 'ebook', '0', '0', '', 'MODULE_ID_EBOOK')"); } // upgrade poll_question Database::get()->query("ALTER TABLE `poll_question` CHANGE `pqid` `pqid` BIGINT(12) NOT NULL AUTO_INCREMENT"); // move old chat files $courses_dir = "$webDir/courses/"; foreach (array('chat.txt', 'tmpChatArchive.txt') as $f) { $old_chat = $courses_dir . $code . '.' . $f; if (file_exists($old_chat)) { rename($old_chat, $courses_dir . $code . '/' . $f); } } }