コード例 #1
0
function renderUpgraderHTML()
{
    global $found_secret_file;
    if (!$found_secret_file) {
        die('<center>There is no working RackTables instance here, <a href="?module=installer">install</a>?</center>');
    }
    try {
        connectDB();
    } catch (RackTablesError $e) {
        die("Database connection failed:\n\n" . $e->getMessage());
    }
    if (!isset($_SERVER['PHP_AUTH_USER']) or !strlen($_SERVER['PHP_AUTH_USER']) or !isset($_SERVER['PHP_AUTH_PW']) or !strlen($_SERVER['PHP_AUTH_PW']) or !authenticate_admin($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
        header('WWW-Authenticate: Basic realm="RackTables upgrade"');
        header('HTTP/1.0 401 Unauthorized');
        ?>
<h1>Trouble logging in?</h1>
You are trying to authenticate for the RackTables upgrade screen. This means that
you must authenticate with the username and password of the main RackTables
administrator. There is only one such account in each installation, its default
username is "admin". RackTables wiki provides more information on this topic.
<?php 
        die;
    }
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>RackTables upgrade script</title>
<style type="text/css">
.tdleft {
	text-align: left;
}

.trok {
	background-color: #80FF80;
}

.trwarning {
	background-color: #FFFF80;
}

.trerror {
	background-color: #FF8080;
}
</style>
</head>
<body>
<h1>Platform check status</h1>
<?php 
    if (!platform_is_ok()) {
        echo '<h1>Please resolve the failed (red) item(s) above.</h1>';
        die('</body></html>');
    }
    echo '<h1>Upgrade status</h1>';
    global $dbver;
    $dbver = getDatabaseVersion();
    echo '<table border=1 cellpadding=5>';
    echo "<tr><th>Current status</th><td>Data version: {$dbver}<br>Code version: " . CODE_VERSION . "</td></tr>\n";
    $path = getDBUpgradePath($dbver, CODE_VERSION);
    if ($path === NULL) {
        echo "<tr><th>Upgrade path</th><td><font color=red>not found</font></td></tr>\n";
        echo "<tr><th>Summary</th><td>Check README for more information. RackTables releases prior to 0.18.0 ";
        echo "must be upgraded to 0.18.0 first.</td></tr>\n";
    } else {
        if (!count($path)) {
            echo "<tr><th>Summary</th><td>Come back later.</td></tr>\n";
        } else {
            echo "<tr><th>Upgrade path</th><td>{$dbver} &rarr; " . implode(' &rarr; ', $path) . "</td></tr>\n";
            global $relnotes;
            foreach ($path as $batchid) {
                if (isset($relnotes[$batchid])) {
                    echo "<tr><th>Release notes for {$batchid}</th><td><pre>" . $relnotes[$batchid] . "</pre></td></tr>\n";
                }
            }
            if (array_key_exists('reallyreally', $_REQUEST)) {
                foreach ($path as $batchid) {
                    executeUpgradeBatch($batchid);
                }
                executeUpgradeBatch('dictionary');
                echo "<tr><th>Summary</th><td>Upgrade complete, it is Ok to ";
                echo "<a href='index.php'>enter</a> the system.</td></tr>\n";
            } else {
                echo '<form method=post action="index.php?module=upgrade"><tr><th>Wait!</th>';
                echo '<td><p>RackTables database upgrades sometimes go wrong because of assorted reasons. ';
                echo 'It is <strong>highly recommended</strong> to make a database backup before ';
                echo 'proceeding any further. <tt>mysqldump</tt> and <tt>PHPMyAdmin</tt> are convenient ';
                echo 'tools for doing this.</p>';
                echo '<p><input type=checkbox name=reallyreally id=reallyreally><label for=reallyreally>';
                echo 'I am ready to bear all risks of this upgrade. I am ready to roll it back in case of ';
                echo 'a failure.</label> <input type=submit value="Yes, I am."></p></td></tr></form>';
            }
        }
    }
    echo '</table>';
    echo '</body></html>';
}
コード例 #2
0
 protected function upgrade($from, $to, InputInterface $input, OutputInterface $output)
 {
     global $dbxlink;
     $dry = $input->getOption('dry-run');
     if ($from == $to) {
         $output->writeln('<info>Database is up-to-date. Nothing to do here.</info>');
         return 0;
     }
     $failures = 0;
     $path = getDBUpgradePath($from, $to);
     $output->writeln('<comment>Upgrading database [' . $from . '] -> ' . join(' -> ', $path) . '</comment>');
     $path[] = 'dictionary';
     foreach ($path as $version) {
         $batch = getUpgradeBatch($version);
         if ($version == 'dictionary') {
             $output->writeln('<info>Updating Dictionary</info>');
         } else {
             $output->writeln('<info>Upgrading to Version ' . $version . '</info>');
         }
         $output->writeln('');
         foreach ($batch as $query) {
             try {
                 if ($output->getVerbosity() == OutputInterface::VERBOSITY_VERBOSE) {
                     $output->writeln("<comment>  {$query}</comment>");
                 } else {
                     $output->write(".");
                 }
                 if (!$dry) {
                     $dbxlink->query($query);
                 }
             } catch (PDOException $e) {
                 $errorInfo = $dbxlink->errorInfo();
                 if ($output->getVerbosity() != OutputInterface::VERBOSITY_VERBOSE) {
                     $output->writeln('');
                     $output->writeln("<error>QUERY FAILED:\t{$query}</error>");
                 }
                 $output->writeln("<error>REASON: {$errorInfo[2]}</error>");
                 $failures++;
             }
         }
         $output->writeln("");
     }
     return $failures;
 }