Commit c89b0364 authored by Thomas Bella's avatar Thomas Bella

Perform automatic database upgrade from cron

Before a request to /index.php was required to perform a database upgrade
parent e602c1d2
<?php
if (!class_exists('SQL')) {
exit('Error loading SQL-class');
}
global $DBVERSION;
$DBVERSION = 3;
// Connect to SQLite database if not already done
if (!isset($SQL)) {
$SQL = new SQL(null, null, null, [ "file" => "monitor.sqlite", "driver" => "sqlite" ]);
}
// Check if database update is required
try {
$currentDatabaseVersion = (int)$SQL->single("SELECT value FROM meta WHERE key = 'version'");
}
catch (PDOException $e) {
$currentDatabaseVersion = 0;
}
if ($currentDatabaseVersion != $DBVERSION) {
// Close current connection
$SQL->close();
// Perform database upgrade
include "functions/dbUpgrade.php";
dbUpgrade();
// Reconnect to new database
$SQL = new SQL(null, null, null, [ "file" => "monitor.sqlite", "driver" => "sqlite" ]);
}
......@@ -12,6 +12,9 @@ header("Content-Type: text/plain");
$SQL = new SQL(null, null, null, [ "file" => "monitor.sqlite", "driver" => "sqlite" ]);
// Perform database upgrade if needed
require_once "assets/database.php";
vlog('Starting cronjob ...');
if (EMAIL && !empty(EMAIL_TARGET)) {
if (EMAIL_TARGET !== false) {
......
......@@ -35,30 +35,10 @@ require_once "config.inc.php";
require_once "assets/correct-config.php";
require_once "class/SQL.class.php";
global $DBVERSION;
$DBVERSION = 3;
$SQL = new SQL(null, null, null, [ "file" => "monitor.sqlite", "driver" => "sqlite" ]);
// Check if database update is required
try {
$currentDatabaseVersion = (int)$SQL->single("SELECT value FROM meta WHERE key = 'version'");
}
catch (PDOException $e) {
$currentDatabaseVersion = 0;
}
if ($currentDatabaseVersion != $DBVERSION) {
// Close current connection
$SQL->close();
// Perform database upgrade
include "functions/dbUpgrade.php";
dbUpgrade();
// Reconnect to new database
$SQL = new SQL(null, null, null, [ "file" => "monitor.sqlite", "driver" => "sqlite" ]);
}
// Perform database upgrade if needed
require_once "assets/database.php";
// Detect current version
if (file_exists(".git/refs/remotes/origin/master")) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment