Esempio n. 1
0
 /**
  * check if database is online and return current version
  *
  * this should be, if user-id is not set (checking always might
  * be too performance intensive)
  */
 public function getVersion()
 {
     global $sql_obj;
     if (!is_object($sql_obj)) {
         $sql_obj = new sql_class($this->dbhost, $this->user, $this->pass, $this->dbname);
     }
     if (!$sql_obj->connect()) {
         ### can't connect db... ###
         log_message("Can't connect database");
         return NULL;
     }
     if (!$sql_obj->selectdb()) {
         ### can't select... ###
         log_message("Can't select database");
         return NULL;
     }
     ### get version ###
     $prefix = confGet('DB_TABLE_PREFIX');
     $sql_command = "select * from {$prefix}db where updated is NULL";
     if ($sql_obj->execute($sql_command)) {
         $row = $sql_obj->fetchArray();
         return $row;
     } else {
         trigger_error("Can't selection version row from db: {$sql_command}");
         return NULL;
     }
 }
Esempio n. 2
0
/**
* upgrades
*/
function upgrade($args = NULL)
{
    global $g_form_fields;
    $db_type = $args['db_type'];
    $hostname = $args['hostname'];
    $db_username = $args['db_username'];
    $db_password = $args['db_password'];
    $db_table_prefix = $args['db_table_prefix'];
    $db_name = $args['db_name'];
    $flag_continue_on_sql_errors = $args['continue_on_sql_errors'];
    $db_version = $args['db_version'];
    # set to NULL if autodetect
    require_once dirname(__FILE__) . "/../db/db_" . $db_type . "_class.php";
    echo "<h2>Upgrading...</h2>";
    print_testStart("getting original version...");
    ### connect db ###
    $sql_obj = new sql_class($hostname, $db_username, $db_password, $db_name);
    if ($sql_obj->error != false) {
        print_testResult(RESULT_FAILED, "mySQL-Error[" . __LINE__ . "]:<pre>" . $sql_obj->error . "</pre>");
        return false;
    }
    ### select db? ###
    if (!$sql_obj->selectdb()) {
        print_testResult(RESULT_FAILED, "Database does not exists mySQL-Error[" . __LINE__ . "]:<pre>" . $sql_obj->error . "</pre>");
        return false;
    }
    ### get version ###
    if (!$db_version) {
        if (!($result = $sql_obj->execute("SELECT *\r\n                                   FROM {$db_table_prefix}db\r\n                                  WHERE updated is NULL"))) {
            print_testResult(RESULT_FAILED, "Count not get version:<pre>" . $sql_obj->error . "</pre>");
            return false;
        }
        $count = 0;
        while ($row = $sql_obj->fetchArray()) {
            $db_version = $row['version'];
            $streber_version_required = $row['version_streber_required'];
            $count++;
        }
        if ($count != 1) {
            print_testResult(RESULT_FAILED, "could not get propper db-version table entry. Please view " . getStreberWikiLink('installation', 'Installation Guide') . " on hints how to proceed.");
            return false;
        }
        if ($db_version < 0.044) {
            print_testResult(RESULT_FAILED, "Sorry upgrading is supoorted since v0.044");
            return false;
        }
        print_testResult(RESULT_GOOD, "v {$db_version}");
    } else {
        print_testResult(RESULT_GOOD, "assuming v{$db_version}");
    }
    $update_queries = array();
    require dirname(__FILE__) . "/db_updates.inc.php";
    print_testStart("doing " . count($update_queries) . " changes to database...");
    foreach ($update_queries as $q) {
        ### strict mode for development ###
        #if($result= $sql_obj->execute('SET session sql_mode = "STRICT_ALL_TABLES,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"')){
        #  }
        #}
        if (!($result = $sql_obj->execute($q))) {
            if (function_exists('mysql_error') && mysql_error()) {
                $mysql_error = mysql_error();
            } else {
                if (function_exists('mysqli_error') && mysqli_error()) {
                    $mysql_error = mysql_error();
                } else {
                    $mysql_error = $sql_obj->error;
                }
            }
            print_testResult(RESULT_FAILED, "Failed:<pre>" . $sql_obj->error . "</pre><br>Error:<pre>" . $mysql_error . "</pre>");
            if (isset($flag_continue_on_sql_errors) && $flag_continue_on_sql_errors) {
                print_testStart("proceeding upgrade...");
            } else {
                return false;
            }
        }
    }
    ### update the db-version ###
    print_testStart("update db-version information");
    $str_query = "UPDATE {$db_table_prefix}db\r\n                SET  updated = now();\r\n                ";
    if (!$sql_obj->execute($str_query)) {
        print_testResult(RESULT_FAILED, "SQL-Error[" . __LINE__ . "]:<br><pre>" . $sql_obj->error . "</pre><br><br>Querry was:<br>{$str_query}");
        return false;
    }
    ### create new db-version ###
    $db_version_new = confGet('STREBER_VERSION');
    $streber_version_required = confGet('STREBER_VERSION');
    $str_query = "INSERT IGNORE into {$db_table_prefix}db (id,version,version_streber_required,created) VALUES(1,'{$db_version_new}','{$streber_version_required}',NOW() )";
    if (!$sql_obj->execute($str_query)) {
        print_testResult(RESULT_FAILED, "SQL-Error[" . __LINE__ . "]:<pre>" . $sql_obj->error . "</pre>Query was:<pre>{$str_query}</pre>");
        return false;
    } else {
        print_testResult(RESULT_GOOD);
    }
    $filename = "../" . confGet("DIR_SETTINGS") . confGet("SITE_SETTINGS");
    print_testStart("writing configuration file '" . $filename . "'...");
    $write_ok = writeSettingsFile($filename, $settings = array("APP_NAME" => $g_form_fields["site_name"]["value"], "EMAIL_ADMINISTRATOR" => $g_form_fields["site_email"]["value"], 'APP_TITLE_HEADER' => $g_form_fields["site_name"]["value"] . "<span class=extend>PM</span>"));
    if (!$write_ok) {
        print_testResult(RESULT_FAILED, "can not write '" . $filename . "'.");
        /**
         * note: because settings-file is now written by a function, we no longer
         * have content to display when creation fails
         */
        # Please create it with this content:<br><pre>&lt;?php".$buffer."?&gt;</pre>");
        return false;
    } else {
        print_testResult(RESULT_GOOD);
    }
    $filename = '../' . confGet('DIR_SETTINGS') . confGet('FILE_DB_SETTINGS');
    print_testStart("writing configuration file '{$filename}'...");
    $write_ok = writeSettingsFile($filename, array('DB_TYPE' => $db_type, 'HOSTNAME' => $hostname, 'DB_USERNAME' => $db_username, 'DB_PASSWORD' => $db_password, 'DB_TABLE_PREFIX' => $db_table_prefix, 'DB_NAME' => $db_name, 'DB_VERSION' => confGet('STREBER_VERSION')));
    if (!$write_ok) {
        print_testResult(RESULT_FAILED, "can not write '{$filename}'.");
        /**
         * note: because settings-file is now written by a function, we no longer
         * have content to display when creation fails
         */
        # Please create it with this content:<br><pre>&lt;?php".$buffer."?&gt;</pre>");
        return false;
    } else {
        print_testResult(RESULT_GOOD);
    }
    return true;
}