function preflightCheckJsonFillSchema() { global $mod_strings; global $persistence; global $sugar_db_version; global $manifest; global $db; if (empty($sugar_db_version)) { include 'sugar_version.php'; } if (empty($manifest)) { include $persistence['unzip_dir'] . '/manifest.php'; } /////////////////////////////////////////////////////////////////////////////// //// SCHEMA SCRIPT HANDLING $schema = ''; $alterTableSchemaOut = ''; $origVersion = implodeVersion($sugar_db_version); $destVersion = implodeVersion($manifest['version']); $script_name = $db->getScriptType(); $sqlScript = $persistence['unzip_dir'] . "/scripts/{$origVersion}_to_{$destVersion}_{$script_name}.sql"; $newTables = array(); logThis('looking for SQL script for DISPLAY at ' . $sqlScript); if (file_exists($sqlScript)) { $contents = sugar_file_get_contents($sqlScript); $schema = "<p><a href='javascript:void(0); toggleNwFiles(\"schemashow\");'>{$mod_strings['LBL_UW_SHOW_SCHEMA']}</a>"; $schema .= "<div id='schemashow' style='display:none;'>"; $schema .= "<textarea readonly cols='80' rows='10'>{$contents}</textarea>"; $schema .= "</div></p>"; } //// END SCHEMA SCRIPT HANDLING /////////////////////////////////////////////////////////////////////////////// ob_start(); echo $schema; ob_flush(); }
} $out .= "</span><br />"; } $diffs = ''; /////////////////////////////////////////////////////////////////////////////// //// SCHEMA SCRIPT HANDLING logThis('starting schema preflight check...'); //Check the current and target versions and store them in session variables if (empty($sugar_db_version)) { include 'sugar_version.php'; } if (!isset($manifest['version']) || empty($manifest['version'])) { include $_SESSION['unzip_dir'] . '/manifest.php'; } $origVersion = implodeVersion($sugar_db_version, 3, '0'); $destVersion = implodeVersion($manifest['version'], 3, '0'); //save the versions as session variables $_SESSION['current_db_version'] = $sugar_db_version; $_SESSION['target_db_version'] = $manifest['version']; $_SESSION['upgrade_from_flavor'] = $manifest['name']; // aw: BUG 10161: check flavor conversion sql files $sqlFile = ''; // cn: bug if (version_compare($sugar_db_version, $manifest['version'], '=')) { $type = $db->getScriptName(); switch ($manifest['name']) { case 'SugarCE to SugarPro': $sqlFile = $origVersion . '_ce_to_pro_' . $type; break; case 'SugarCE to SugarEnt': $sqlFile = $origVersion . '_ce_to_ent_' . $type;
if (empty($errors)) { $stop = false; } $backupDesc = ''; if ($backupFilesExist) { $backupDesc .= "<b>{$mod_strings['LBL_UW_BACKUP_FILES_EXIST_TITLE']}</b><br />"; $backupDesc .= $mod_strings['LBL_UW_BACKUP_FILES_EXIST'] . ': ' . $rest_dir; } $customized_mods_Desc = ''; $old_schema = ''; $old_schema_opt = ''; $skipped_queries = ''; if (version_compare($_SESSION['current_db_version'], $_SESSION['target_db_version'], '!=')) { global $sugar_version; $origVersion = implodeVersion($_SESSION['current_db_version']); $destVersion = implodeVersion($_SESSION['target_db_version']); //old schema to be dropped $old_schema_contents = ''; if (file_exists($_SESSION['unzip_dir'] . '/scripts/drop_' . $origVersion . '_schema_after_upgrade_' . $destVersion . '.php')) { require_once $_SESSION['unzip_dir'] . '/scripts/drop_' . $origVersion . '_schema_after_upgrade_' . $destVersion . '.php'; ob_start(); $old_schema_contents = @drop_preUpgardeSchema(true); ob_end_clean(); } if ($old_schema_contents != null && strlen($old_schema_contents) > 0) { $old_schema = "<p><a href='javascript:void(0); toggleNwFiles(\"old_schemashow\");'>{$mod_strings['LBL_UW_SHOW_OLD_SCHEMA_TO_DROP']}</a>"; $old_schema .= "<div id='old_schemashow' style='display:none;'>"; $old_schema .= "<textarea readonly cols='80' rows='10'>{$old_schema_contents}</textarea>"; $old_schema .= "</div></p>"; $old_schema_opt = "<b>{$mod_strings['LBL_UW_DROP_SCHEMA_METHOD']}</b>\n\t\t\t\t\t\t<select name=\"schema_drop\" id=\"select_schema_drop\" onchange=\"checkSchemaDropStatus();\">\n\t\t\t\t\t\t\t<option value=\"manual\">{$mod_strings['LBL_UW_DROP_SCHEMA_MANUAL']}</option>\n\t\t\t\t\t\t\t<option value=\"sugar\">{$mod_strings['LBL_UW_DROP_SCHEMA_UPGRADE_WIZARD']}</option>\n\t\t\t\t\t\t</select>\n\t\t\t\t\t"; }
function runSqlFiles($origVersion, $destVersion, $queryType, $resumeFromQuery = '') { global $sugar_config; global $unzip_dir; global $sugar_config; global $sugar_version; global $path; global $_SESSION; $self_dir = "{$unzip_dir}/scripts"; // This flag is determined by the preflight check in the installer if (!isset($_SESSION['schema_change']) || $_SESSION['schema_change'] == 'sugar') { _logThis("Upgrading the database from {$origVersion} to version {$destVersion}", $path); $origVersion = implodeVersion($origVersion, 3, 'x'); $destVersion = implodeVersion($destVersion, 3, 'x'); $schemaFileName = $origVersion . "_to_" . $destVersion; switch ($sugar_config['dbconfig']['db_type']) { case 'mysql': $schemaFileName = $schemaFileName . '_mysql.sql'; break; case 'mssql': $schemaFileName = $schemaFileName . '_mssql.sql'; break; case 'oci8': $schemaFileName = $schemaFileName . '_oracle.sql'; break; case 'ibm_db2': $schemaFileName = $schemaFileName . '_ibm_db2.sql'; break; } $schemaFile = $_SESSION['unzip_dir'] . '/scripts/' . $schemaFileName; _logThis("Running SQL file {$schemaFile}", $path); if (is_file($schemaFile)) { //$sql_run_result = _run_sql_file($schemaFile); ob_start(); @parseAndExecuteSqlFile($schemaFile, $queryType, $resumeFromQuery); ob_end_clean(); } else { if (strcmp($origVersion, $destVersion) == 0) { _logThis("*** Skipping schema upgrade for point release.", $path); } else { _logThis("*** ERROR: Schema change script [{$schemaFile}] could not be found!", $path); } } } else { _logThis('*** Skipping Schema Change Scripts - Admin opted to run queries manually and should have done so by now.', $path); } }