Browse Source

Database::setVersion to update the database version

Tobias Reich 10 years ago
parent
commit
e20ba354da

+ 1 - 6
php/database/update_020100.php

@@ -37,12 +37,7 @@ if ($result->num_rows===0) {
 		return false;
 	}
 } else {
-	$query	= Database::prepare($database, "UPDATE ? SET value = '020100' WHERE `key` = 'version'", array(LYCHEE_TABLE_SETTINGS));
-	$result	= $database->query($query);
-	if (!$result) {
-		Log::error($database, 'update_020100', __LINE__, 'Could not update database (' . $database->error . ')');
-		return false;
-	}
+	if (Database::setVersion($database, '020100')===false) return false;
 }
 
 ?>

+ 2 - 6
php/database/update_020101.php

@@ -13,11 +13,7 @@ if (!$result) {
 	return false;
 }
 
-$query	= Database::prepare($database, "UPDATE ? SET value = '020101' WHERE `key` = 'version'", array(LYCHEE_TABLE_SETTINGS));
-$result	= $database->query($query);
-if (!$result) {
-	Log::error($database, 'update_020101', __LINE__, 'Could not update database (' . $database->error . ')');
-	return false;
-}
+# Set version
+if (Database::setVersion($database, '020101')===false) return false;
 
 ?>

+ 2 - 6
php/database/update_020200.php

@@ -16,11 +16,7 @@ if (!$database->query($query)) {
 	}
 }
 
-$query	= Database::prepare($database, "UPDATE ? SET value = '020200' WHERE `key` = 'version'", array(LYCHEE_TABLE_SETTINGS));
-$result	= $database->query($query);
-if (!$result) {
-	Log::error($database, 'update_020200', __LINE__, 'Could not update database (' . $database->error . ')');
-	return false;
-}
+# Set version
+if (Database::setVersion($database, '020200')===false) return false;
 
 ?>

+ 1 - 6
php/database/update_020500.php

@@ -150,11 +150,6 @@ if (!$result) {
 }
 
 # Set version
-$query	= Database::prepare($database, "UPDATE ? SET value = '020500' WHERE `key` = 'version'", array(LYCHEE_TABLE_SETTINGS));
-$result	= $database->query($query);
-if (!$result) {
-	Log::error($database, 'update_020500', __LINE__, 'Could not update database (' . $database->error . ')');
-	return false;
-}
+if (Database::setVersion($database, '020500')===false) return false;
 
 ?>

+ 1 - 6
php/database/update_020505.php

@@ -18,11 +18,6 @@ if (!$database->query($query)) {
 }
 
 # Set version
-$query	= Database::prepare($database, "UPDATE ? SET value = '020505' WHERE `key` = 'version'", array(LYCHEE_TABLE_SETTINGS));
-$result	= $database->query($query);
-if (!$result) {
-	Log::error($database, 'update_020505', __LINE__, 'Could not update database (' . $database->error . ')');
-	return false;
-}
+if (Database::setVersion($database, '020505')===false) return false;
 
 ?>

+ 1 - 6
php/database/update_020601.php

@@ -18,11 +18,6 @@ if (!$database->query($query)) {
 }
 
 # Set version
-$query	= Database::prepare($database, "UPDATE ? SET value = '020601' WHERE `key` = 'version'", array(LYCHEE_TABLE_SETTINGS));
-$result	= $database->query($query);
-if (!$result) {
-	Log::error($database, 'update_020601', __LINE__, 'Could not update database (' . $database->error . ')');
-	return false;
-}
+if (Database::setVersion($database, '020601')===false) return false;
 
 ?>

+ 1 - 6
php/database/update_020602.php

@@ -41,11 +41,6 @@ if ($result->num_rows===0) {
 }
 
 # Set version
-$query	= Database::prepare($database, "UPDATE ? SET value = '020602' WHERE `key` = 'version'", array(LYCHEE_TABLE_SETTINGS));
-$result = $database->query($query);
-if (!$result) {
-	Log::error($database, 'update_020602', __LINE__, 'Could not update database (' . $database->error . ')');
-	return false;
-}
+if (Database::setVersion($database, '020602')===false) return false;
 
 ?>

+ 11 - 0
php/modules/Database.php

@@ -242,6 +242,17 @@ if(!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
 
 	}
 
+	static function setVersion($database, $version) {
+
+		$query	= Database::prepare($database, "UPDATE ? SET value = '?' WHERE `key` = 'version'", array(LYCHEE_TABLE_SETTINGS, $version));
+		$result = $database->query($query);
+		if (!$result) {
+			Log::error($database, __METHOD__, __LINE__, 'Could not update database (' . $database->error . ')');
+			return false;
+		}
+
+	}
+
 	static function prepare($database, $query, $data) {
 
 		# Check dependencies