Пример #1
0
$version = $_REQUEST['version'];
if (!$version || !$installer->isUpdateReady($version)) {
    header('Location: index.php');
    exit;
}
$update = $installer->getUpdate($version);
if ($_POST["submit"]) {
    $database_username = trim($_POST['database_username']);
    $database_password = trim($_POST['database_password']);
    if ($database_username) {
        $installer->connect($database_username, $database_password);
        if ($installer->error) {
            $installer->addErrorMessage($installer->error);
        }
    }
    if ($installer->hasPermissions($update["privileges"])) {
        $sql_file = "protected/update_{$version}.sql";
        if (!file_exists($sql_file)) {
            $installer->addErrorMessage("Could not open sql file: " . $sql_file . ".  If this file does not exist you must download new install files.");
        } else {
            //run the file - checking for errors at each SQL execution
            $f = fopen($sql_file, "r");
            $contents = fread($f, filesize($sql_file));
            $statements = explode(';', $contents);
            //Process the sql file by statements
            foreach ($statements as $statement) {
                if (strlen(trim($statement)) > 3) {
                    $result = mysql_query($statement);
                    if (!$result) {
                        $installer->addErrorMessage(mysql_error() . "<br /><br />For statement: " . $statement);
                        break;