-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create update functionality to upgrade game
- Loading branch information
1 parent
8622998
commit b5bd895
Showing
11 changed files
with
208 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
$version_extra = null; | ||
{ | ||
$git_head = dirname(__FILE__) . '/../.git/HEAD'; | ||
if (file_exists($git_head)) { | ||
$content = file_get_contents($git_head); | ||
if (strpos($content, 'ref:') !== false) { | ||
$tmp = explode('/', $content); | ||
$content = trim($tmp[count($tmp) - 1]); | ||
} | ||
$version_extra = '+' . substr($content, 0, 8); | ||
} | ||
} | ||
define('game_version', "1.10.1" . $version_extra); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
create table update_info | ||
( | ||
ID int auto_increment primary key, | ||
Executed datetime not null default current_timestamp, | ||
Script varchar(64) not null, | ||
Checksum char(40) not null | ||
); | ||
create unique index Script on update_info (Script); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
require_once('../include/config.inc.php'); | ||
require_once('../include/functions.inc.php'); | ||
require_once('../include/database.class.php'); | ||
|
||
header('Content-Type: text/plain; charset=UTF-8'); | ||
ob_start(); | ||
http_response_code(500); | ||
|
||
echo "Checking installation for version " . game_version . "\n"; | ||
echo "Verifying database connection\n"; | ||
Database::getInstance(); | ||
|
||
echo "Checking base installation\n"; | ||
$executedScripts = array(); | ||
if (!Database::getInstance()->tableExists('auftrag')) { | ||
echo "Base installation not found, executing setup script\n"; | ||
// initial setup | ||
$script = 'sql/00-1.10.0-setup.sql'; | ||
$result = Database::getInstance()->executeFile($script); | ||
if ($result !== null) { | ||
die("Could not execute setup script, failed step: " . $result); | ||
} | ||
$executedScripts[$script] = sha1_file($script); | ||
} | ||
|
||
echo "Checking for update information\n"; | ||
if (!Database::getInstance()->tableExists('update_info')) { | ||
echo "Update information not found, execute first update script\n"; | ||
// coming from v1.10.0 | ||
$script = 'sql/01-1.10.1-update_info.sql'; | ||
$result = Database::getInstance()->executeFile($script); | ||
if ($result !== null) { | ||
die("Could not execute setup script, failed step: " . $result); | ||
} | ||
$executedScripts[$script] = sha1_file($script); | ||
} | ||
|
||
echo "Enumerating update scripts\n"; | ||
$dh = opendir('sql/'); | ||
while (false !== ($entry = readdir($dh))) { | ||
$script = 'sql/' . $entry; | ||
if (mb_strpos($script, '.sql') === false) continue; | ||
if (strpos($script, '/0') !== false) { | ||
echo "Skipping $script\n"; | ||
continue; | ||
} | ||
|
||
echo "Verify update script: $script\n"; | ||
$dbChecksum = Database::getInstance()->getInstallScriptChecksum($script); | ||
if ($dbChecksum === null) { | ||
echo "> Script unknown, begin execution\n"; | ||
$result = Database::getInstance()->executeFile($script); | ||
if ($result !== null) { | ||
die("Could not execute setup script, failed step: " . $result); | ||
} | ||
$executedScripts[$script] = sha1_file($script); | ||
} else { | ||
echo "> Script already executed, verifying checksum\n"; | ||
$fsChecksum = sha1_file($script); | ||
if ($dbChecksum !== $fsChecksum) { | ||
die(sprintf("> Calculated checksum for '%s' is different between database (%s) and filesystem (%s). Please correct manually!", | ||
$script, $dbChecksum, $fsChecksum)); | ||
} else { | ||
echo ">> OK\n"; | ||
} | ||
} | ||
} | ||
|
||
$script = '/tmp/99_testdata.sql'; | ||
if (file_exists($script)) { | ||
echo "Verify update script: $script\n"; | ||
$result = Database::getInstance()->executeFile($script); | ||
if ($result !== null) { | ||
die("Could not execute setup script, failed step: " . $result); | ||
} | ||
} | ||
|
||
Database::getInstance()->begin(); | ||
foreach ($executedScripts as $script => $checksum) { | ||
if (Database::getInstance()->createTableEntry(Database::TABLE_UPDATE_INFO, array( | ||
'Script' => $script, | ||
'Checksum' => $checksum | ||
)) !== 1) { | ||
Database::getInstance()->rollBack(); | ||
die('Could not create update_info entry for ' . $script); | ||
} | ||
} | ||
Database::getInstance()->commit(); | ||
|
||
http_response_code(200); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,40 @@ | ||
alter table mitglieder | ||
auto_increment 100; | ||
|
||
DELIMITER $$ | ||
CREATE OR REPLACE PROCEDURE InsertUsers(P_count int) | ||
BEGIN | ||
DECLARE NR int; | ||
insertLoop: | ||
LOOP | ||
SET NR = coalesce(NR, 0) + 1; | ||
-- all passwords are "changeit" | ||
|
||
REPLACE INTO `mitglieder` (`ID`, `Name`, `EMail`, `Passwort`) | ||
VALUES (10 + NR, concat('test', NR), concat('test', NR, '@example.com'), | ||
-- password is "changeit" | ||
'$argon2i$v=19$m=16384,t=8,p=2$cFlRVVl2WTdFREFkaU8zQg$kphB/S9ZP41FplBbhUH1uYSURQD4kK8JYQvjtieU/ZM'); | ||
INSERT INTO `statistik` (`user_id`) VALUES (10 + NR); | ||
REPLACE INTO `mitglieder` (`ID`, `Name`, `EMail`, `Passwort`) | ||
VALUES (11, 'test1', '[email protected]', | ||
'$argon2i$v=19$m=16384,t=8,p=2$cFlRVVl2WTdFREFkaU8zQg$kphB/S9ZP41FplBbhUH1uYSURQD4kK8JYQvjtieU/ZM'); | ||
REPLACE INTO `statistik` (`user_id`) | ||
VALUES (11); | ||
|
||
REPLACE INTO `mitglieder` (`ID`, `Name`, `EMail`, `Passwort`) | ||
VALUES (12, 'test2', '[email protected]', | ||
'$argon2i$v=19$m=16384,t=8,p=2$cFlRVVl2WTdFREFkaU8zQg$kphB/S9ZP41FplBbhUH1uYSURQD4kK8JYQvjtieU/ZM'); | ||
REPLACE INTO `statistik` (`user_id`) | ||
VALUES (12); | ||
|
||
IF NR = P_count THEN LEAVE insertLoop; END IF; | ||
END LOOP insertLoop; | ||
END $$ | ||
DELIMITER ; | ||
REPLACE INTO `mitglieder` (`ID`, `Name`, `EMail`, `Passwort`) | ||
VALUES (13, 'test3', '[email protected]', | ||
'$argon2i$v=19$m=16384,t=8,p=2$cFlRVVl2WTdFREFkaU8zQg$kphB/S9ZP41FplBbhUH1uYSURQD4kK8JYQvjtieU/ZM'); | ||
REPLACE INTO `statistik` (`user_id`) | ||
VALUES (13); | ||
|
||
CALL InsertUsers(5); | ||
REPLACE INTO `mitglieder` (`ID`, `Name`, `EMail`, `Passwort`) | ||
VALUES (14, 'test4', '[email protected]', | ||
'$argon2i$v=19$m=16384,t=8,p=2$cFlRVVl2WTdFREFkaU8zQg$kphB/S9ZP41FplBbhUH1uYSURQD4kK8JYQvjtieU/ZM'); | ||
REPLACE INTO `statistik` (`user_id`) | ||
VALUES (14); | ||
|
||
REPLACE INTO `mitglieder` (`ID`, `Name`, `EMail`, `Passwort`) | ||
VALUES (15, 'test5', '[email protected]', | ||
'$argon2i$v=19$m=16384,t=8,p=2$cFlRVVl2WTdFREFkaU8zQg$kphB/S9ZP41FplBbhUH1uYSURQD4kK8JYQvjtieU/ZM'); | ||
REPLACE INTO `statistik` (`user_id`) | ||
VALUES (15); | ||
|
||
REPLACE INTO `mitglieder` (`ID`, `Name`, `EMail`, `Admin`, `Passwort`) | ||
VALUES (9, 'admin', '[email protected]', 1, | ||
-- password is "changeit" | ||
'$argon2i$v=19$m=16384,t=8,p=2$cFlRVVl2WTdFREFkaU8zQg$kphB/S9ZP41FplBbhUH1uYSURQD4kK8JYQvjtieU/ZM'); | ||
INSERT INTO `statistik` (`user_id`) VALUES (9); | ||
REPLACE INTO `statistik` (`user_id`) | ||
VALUES (9); |