function run_upgrade_sql($upgrade_sql_dir, $current_version, $tb_prefix = TABLE_PREFIX, $in_plain_msg = TRUE) { global $progress; // add the ending slash '/' to the input direc $upgrade_sql_dir = substr($upgrade_sql_dir, -1) == '/' ? $upgrade_sql_dir : $upgrade_sql_dir . '/'; // get a list of all update scripts minus sql extension $files = scandir($upgrade_sql_dir); foreach ($files as $file) { if (count($file = explode('_', $file)) == 5) { $file[4] = substr($file[4], 0, -3); $update_files[$file[2]] = $file; } } ksort($update_files); foreach ($update_files as $update_file) { if (version_compare($current_version, $update_file[4], '<')) { //update_one_ver($update_file, $_POST['tb_prefix']); $update_file = implode('_', $update_file); $sqlUtility = new SqlUtility(); $sqlUtility->queryFromFile($upgrade_sql_dir . $update_file . 'sql', $tb_prefix, $in_plain_msg); } } }
$sql = "DELETE FROM %slanguage_text WHERE `variable`<>'_c_template' AND `variable`<>'_c_msgs'"; queryDB($sql, array($_POST['tb_prefix'])); $sql = "DELETE FROM %slanguages WHERE language_code<>'en'"; queryDB($sql, array($_POST['tb_prefix'])); // make sure English exists in the language table when upgrading $sql = "REPLACE INTO `%slanguages` VALUES ('en', 'utf-8', 'ltr', 'en([-_][[:alpha:]]{2})?|english', 'English', 'English', 3)"; queryDB($sql, array($_POST['tb_prefix'])); run_upgrade_sql(AT_INCLUDE_PATH . 'install/db', $_POST['old_version'], $_POST['tb_prefix']); /* reset all the accounts to English */ $sql = "UPDATE %smembers SET language='en', creation_date=creation_date, last_login=last_login"; queryDB($sql, array($_POST['tb_prefix'])); /* set all the courses to 'en' as primary language if empty. added 1.4.1 */ $sql = "UPDATE %scourses SET primary_language='en' WHERE primary_language=''"; queryDB($sql, array($_POST['tb_prefix'])); $sqlUtility = new SqlUtility(); $sqlUtility->queryFromFile(AT_INCLUDE_PATH . 'install/db/atutor_language_text.sql', $_POST['tb_prefix']); if (!$errors) { print_progress($step); unset($_POST['submit']); store_steps(1); print_feedback($progress); echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post" name="form"> <input type="hidden" name="step" value="3" /> <input type="hidden" name="upgrade_action" value="true" />'; echo '<input type="hidden" name="db_login" value="' . urlencode($_POST['db_login']) . '" />'; echo '<input type="hidden" name="db_password" value="' . urlencode($_POST['db_password']) . '" />'; echo '<input type="hidden" name="db_host" value="' . $_POST['db_host'] . '" />'; echo '<input type="hidden" name="db_name" value="' . $_POST['db_name'] . '" />'; echo '<input type="hidden" name="db_port" value="' . $_POST['db_port'] . '" />'; echo '<input type="hidden" name="tb_prefix" value="' . $_POST['tb_prefix'] . '" />'; echo '<input type="hidden" name="old_version" value="' . $_POST['old_version'] . '" />';
/** * Run SQL defined in patch.xml * @access private * @author Cindy Qi Li */ function runSQL() { // run sql // As sqlutility.class.php reads sql from a file, write sql to module content folder $patch_sql_file = $this->module_content_dir . '/' . $this->sql_file; $fp = fopen($patch_sql_file, 'w'); fwrite($fp, trim($this->patch_array['sql'])); fclose($fp); require AC_INCLUDE_PATH . 'classes/sqlutility.class.php'; $sqlUtility = new SqlUtility(); $sqlUtility->queryFromFile($patch_sql_file, TABLE_PREFIX); @unlink($patch_sql_file); return true; }
// possible values: FALSE | AT_PRIV_ADMIN | TRUE $_admin_privilege = TRUE; // possible values: FALSE | TRUE /******** * the following code is used for creating a module-specific directory. * it generates appropriate error messages to aid in its creation. */ $directory = AT_CONTENT_DIR . 'calendar'; // check if the directory is writeable if (!is_dir($directory) && !@mkdir($directory)) { $msg->addError(array('MODULE_INSTALL', '<li>' . $directory . ' does not exist. Please create it.</li>')); } else { if (!is_writable($directory) && @chmod($directory, 0666)) { $msg->addError(array('MODULE_INSTALL', '<li>' . $directory . ' is not writeable. On Unix issue the command <kbd>chmod a+rw</kbd>.</li>')); } } /****** * the following code checks if there are any errors (generated previously) * then uses the SqlUtility to run any database queries it needs, ie. to create * its own tables. */ if (!$msg->containsErrors() && file_exists(dirname(__FILE__) . '/module.sql')) { // deal with the SQL file: require AT_INCLUDE_PATH . 'classes/sqlutility.class.php'; $sqlUtility = new SqlUtility(); /* * the SQL file could be stored anywhere, and named anything, "module.sql" is simply * a convention we're using. */ $sqlUtility->queryFromFile(dirname(__FILE__) . '/module.sql', TABLE_PREFIX); }
/* http://atutor.ca */ /* This program is free software. You can redistribute it and/or */ /* modify it under the terms of the GNU General Public License */ /* as published by the Free Software Foundation. */ /************************************************************************/ // $Id$ if (!defined('AT_INSTALLER_INCLUDE_PATH') || !defined('AT_INCLUDE_PATH')) { exit; } include AT_INCLUDE_PATH . 'install/install.inc.php'; if (isset($_POST['submit'])) { //check DB & table connection $db = create_and_switch_db($_POST['db_host'], $_POST['db_port'], $_POST['db_login'], $_POST['db_password'], $_POST['tb_prefix'], $_POST['db_name'], true); if (!isset($errors)) { $sqlUtility = new SqlUtility(); $sqlUtility->queryFromFile(AT_INCLUDE_PATH . 'install/db/atutor_schema.sql', $addslashes($_POST['tb_prefix'])); $sqlUtility->queryFromFile(AT_INCLUDE_PATH . 'install/db/atutor_language_text.sql', $addslashes($_POST['tb_prefix'])); if (!$errors) { print_progress($step); unset($_POST['submit']); unset($_POST['action']); store_steps($step); print_feedback($progress); echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post" name="form"> <input type="hidden" name="step" value="3" />'; print_hidden(3); echo '<p align="center"><input type="submit" class="button" value="Next » " name="submit" /></p></form>'; return; } } }
function import($language_sql_file) { // move sql import class from install/ to include/classes/ // store the lang def'n in a .ini file and use insertLang // after checking if it already exists // use the sql class to insert the language into the db // check if this language exists before calling this method require_once AT_INCLUDE_PATH . 'classes/sqlutility.class.php'; $sqlUtility = new SqlUtility(); $sqlUtility->queryFromFile($language_sql_file, TABLE_PREFIX); }
print_post_for_step9($_POST); echo '<p align="center"><input type="submit" class="button" value=" Next » " name="submit" /></p></form>'; return; } $result = ''; // Get course code to map encoding/charset if ($_POST['convert_type'] == 'all' || $_POST['convert_type'] == 'courses') { $query = "SELECT course_id, title FROM " . $_POST['tb_prefix'] . "courses"; $result = mysql_query($query); if (mysql_num_rows($result) <= 0) { return false; } } else { //'Skip' was selected, convert table structure only $sqlUtility = new SqlUtility(); $sqlUtility->queryFromFile(AT_INCLUDE_PATH . 'install/db/atutor_convert_db_to_utf8.sql', $_POST['tb_prefix']); $progress[] = 'Database table structure has been converted to UTF-8.'; print_feedback($progress); if (isset($errors)) { print_errors($errors); echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post" name="form"> <input type="hidden" name="step" value="3" />'; print_hidden(2); print_post_for_step9($_POST); echo '<p align="center"><input type="submit" class="button" value=" Retry " name="submit" /></p></form>'; return; } echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post" name="form"> <input type="hidden" name="step" value="3" />'; echo '<input type="hidden" name="con_step" value="4" />'; print_hidden(2);