示例#1
0
function preflightCheckJsonSchemaCheck($persistence)
{
    global $mod_strings;
    global $db;
    if (!isset($persistence['sql_check_done']) || $persistence['sql_check_done'] != true) {
        // must keep sql in order
        $completeLine = array_shift($persistence['sql_to_check']);
        $whatsLeft = count($persistence['sql_to_check']);
        // populate newTables array to prevent "getting sample data" from non-existent tables
        $newTables = array();
        if (strtoupper(substr($completeLine, 1, 5)) == 'CREAT') {
            $newTables[] = getTableFromQuery($completeLine);
        }
        $bad = verifySqlStatement(trim($completeLine), $db->dbType, $newTables);
        if (!empty($bad)) {
            logThis('*** ERROR: schema change script has errors: ' . $completeLine);
            $persistence['sql_errors'][] = $bad;
        }
        $persistence = ajaxSqlProgress($persistence, $completeLine, 'sql_to_check');
    } else {
        $persistence['sql_to_check'] = $persistence['sql_to_check_backup'];
        echo 'done';
    }
    return $persistence;
}
 logThis('found schema upgrade script: ' . $sqlScript);
 logThis('schema preflight using MySQL');
 $fp = fopen($sqlScript, 'r');
 $contents = fread($fp, filesize($sqlScript));
 if (rewind($fp)) {
     $completeLine = '';
     while ($line = fgets($fp)) {
         if (strpos($line, '--') === false) {
             $completeLine .= " " . trim($line);
             if (strpos($line, ';') !== false) {
                 $completeLine = str_replace(';', '', $completeLine);
                 // populate newTables array to prevent "getting sample data" from non-existent tables
                 if (strtoupper(substr($completeLine, 1, 5)) == 'CREAT') {
                     $newTables[] = getTableFromQuery($completeLine);
                 }
                 $bad = verifySqlStatement(trim($completeLine), $db->dbType, $newTables);
                 if (!empty($bad)) {
                     logThis('*** ERROR: schema change script has errors - stopping execution');
                     $sqlErrors[] = $bad;
                 }
                 // reset for next SQL query
                 $completeLine = '';
             }
         }
     }
 } else {
     logThis('*** ERROR: could not read schema script: ' . $sqlScript);
     $sqlErrors[] = $mod_strings['ERR_UW_FILE_NOT_READABLE'] . '::' . $sqlScript;
 }
 // remove __uw_temp tables
 testCleanUp($db->dbType);