diff --git a/.docker/run.sh b/.docker/run.sh
index 3e1856c..12807fb 100644
--- a/.docker/run.sh
+++ b/.docker/run.sh
@@ -10,6 +10,12 @@ sed -i "s/^\$gkey = .*$/\$gkey = \"${ULOGGER_GKEY}\";/" /var/www/html/config.php
sed -i "s/^\$lang = .*$/\$lang = \"${ULOGGER_LANG}\";/" /var/www/html/config.php
sed -i "s/^\$units = .*$/\$units = \"${ULOGGER_UNITS}\";/" /var/www/html/config.php
+if [ "${ULOGGER_ENABLE_SETUP}" = "1" ]; then
+ sed -i "s/\$enabled = false;/\$enabled = true;/" /var/www/html/scripts/setup.php;
+ echo "ulogger setup script enabled"
+ echo "----------------------------"
+fi
+
# show config variables
echo "ulogger configuration"
echo "---------------------"
diff --git a/.tests/lib/BaseDatabaseTestCase.php b/.tests/lib/BaseDatabaseTestCase.php
index cf7108f..35dc482 100644
--- a/.tests/lib/BaseDatabaseTestCase.php
+++ b/.tests/lib/BaseDatabaseTestCase.php
@@ -1,9 +1,17 @@
query("ALTER SEQUENCE tracks_id_seq RESTART WITH $tracks");
self::$pdo->query("ALTER SEQUENCE positions_id_seq RESTART WITH $positions");
} else if (self::$driver == "sqlite") {
- self::$pdo->query("DELETE FROM sqlite_sequence WHERE NAME = 'users'");
- self::$pdo->query("DELETE FROM sqlite_sequence WHERE NAME = 'tracks'");
- self::$pdo->query("DELETE FROM sqlite_sequence WHERE NAME = 'positions'");
+ $retry = 1;
+ do {
+ try {
+ self::$pdo->query("DELETE FROM sqlite_sequence WHERE NAME = 'users'");
+ self::$pdo->query("DELETE FROM sqlite_sequence WHERE NAME = 'tracks'");
+ self::$pdo->query("DELETE FROM sqlite_sequence WHERE NAME = 'positions'");
+ $retry = 0;
+ } catch (Exception $e) {
+ // sqlite raises error when db schema changes in another connection.
+ if (strpos($e->getMessage(), 'database schema has changed') !== false) {
+ self::$pdo = null;
+ self::setUpBeforeClass();
+ }
+ }
+ } while ($retry--);
}
}
diff --git a/.tests/lib/UloggerAPITestCase.php b/.tests/lib/UloggerAPITestCase.php
index d22773e..c98334e 100644
--- a/.tests/lib/UloggerAPITestCase.php
+++ b/.tests/lib/UloggerAPITestCase.php
@@ -5,6 +5,9 @@ require_once("BaseDatabaseTestCase.php");
class UloggerAPITestCase extends BaseDatabaseTestCase {
+ /**
+ * @var null|GuzzleHttp\Client $http
+ */
protected $http = null;
public function setUp() {
diff --git a/.tests/lib/UloggerDatabaseTestCase.php b/.tests/lib/UloggerDatabaseTestCase.php
index f47ad79..bf3ed07 100644
--- a/.tests/lib/UloggerDatabaseTestCase.php
+++ b/.tests/lib/UloggerDatabaseTestCase.php
@@ -6,6 +6,9 @@ require_once(__DIR__ . "/../../helpers/db.php");
class UloggerDatabaseTestCase extends BaseDatabaseTestCase {
+ /**
+ * @var uDb $udb
+ */
static private $udb = null;
public static function setUpBeforeClass() {
diff --git a/.travis.yml b/.travis.yml
index 21fd9c0..b237bf1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,11 +25,11 @@ before_install:
case "$DB_DSN" in
mysql*)
docker build -t ulogger --build-arg DB_DRIVER=mysql .
- docker run -d --name ulogger -p 8080:80 -p 8081:3306 --expose 3306 ulogger
+ docker run -d --name ulogger -p 8080:80 -p 8081:3306 --expose 3306 -e ULOGGER_ENABLE_SETUP=1 ulogger
;;
pgsql*)
docker build -t ulogger --build-arg DB_DRIVER=pgsql .
- docker run -d --name ulogger -p 8080:80 -p 8081:5432 --expose 5432 ulogger
+ docker run -d --name ulogger -p 8080:80 -p 8081:5432 --expose 5432 -e ULOGGER_ENABLE_SETUP=1 ulogger
;;
sqlite*)
sudo apt-get update -qq
@@ -39,7 +39,7 @@ before_install:
sudo chown -R travis:travis /tmp/data
sudo chmod -R 777 /tmp/data
docker build -t ulogger --build-arg DB_DRIVER=sqlite .
- docker run -d --name ulogger -p 8080:80 -v /tmp/data:/data ulogger
+ docker run -d --name ulogger -p 8080:80 -v /tmp/data:/data -e ULOGGER_ENABLE_SETUP=1 ulogger
;;
esac
- composer install
@@ -68,4 +68,4 @@ addons:
notification_email: scan.coverity@fabiszewski.net
build_command_prepend: ""
build_command: "--no-command --fs-capture-search ./ --fs-capture-search-exclude-regex vendor/ --fs-capture-search-exclude-regex .tests/ --fs-capture-search-exclude-regex config.php --fs-capture-search-exclude-regex .docker/"
- branch_pattern: master
\ No newline at end of file
+ branch_pattern: master
diff --git a/Dockerfile b/Dockerfile
index b71557f..d33ae33 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -16,6 +16,7 @@ ENV ULOGGER_GKEY ""
ENV ULOGGER_LANG en
ENV ULOGGER_UNITS metric
ENV ULOGGER_DB_DRIVER ${DB_DRIVER}
+ENV ULOGGER_ENABLE_SETUP 0
ENV LANG=en_US.utf-8
diff --git a/composer.json b/composer.json
index f53bf7f..4561df0 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,9 @@
{
"require": {
- "ulrichsg/getopt-php": "^3.2"
+ "ulrichsg/getopt-php": "^3.2",
+ "ext-json": "*",
+ "ext-pdo": "*",
+ "ext-xmlwriter": "*"
},
"scripts": {
"test": "./vendor/bin/phpunit"
diff --git a/lang/en.php b/lang/en.php
index 6b3235b..05ea3c6 100644
--- a/lang/en.php
+++ b/lang/en.php
@@ -43,6 +43,8 @@ $langSetup["scriptdesc"] = "This script will set up tables needed for µlogger (
$langSetup["scriptdesc2"] = "When done the script will ask you to provide user name and password for your µlogger user.";
$langSetup["startbutton"] = "Press to start";
$langSetup["restartbutton"] = "Restart";
+$langSetup["optionwarn"] = "PHP configuration option %s must be set to %s."; // substitutes option name and value
+$langSetup["extensionwarn"] = "Required PHP extension %s is not available."; // substitutes extension name
// application strings
diff --git a/scripts/setup.php b/scripts/setup.php
index 9481710..b606431 100644
--- a/scripts/setup.php
+++ b/scripts/setup.php
@@ -54,21 +54,21 @@ switch ($command) {
$options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ];
$pdo = new PDO(uConfig::$dbdsn, uConfig::$dbuser, uConfig::$dbpass, $options);
$dbDriver = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
- } catch (PDOException $e ) {
+ } catch (PDOException $e) {
$messages[] = "{$langSetup["dbconnectfailed"]}";
$messages[] = sprintf($langSetup["serversaid"], "" . $e->getMessage() . "");
$messages[] = $langSetup["checkdbsettings"];
break;
}
try {
- $queries = getQueries($pdo);
+ $queries = getQueries();
foreach ($queries as $query) {
$pdo->query($query);
}
} catch (PDOException $e) {
- $messages[] = "{$langSetup["dbqueryfailed"]}";
- $messages[] = sprintf($langSetup["serversaid"], "" . $e->getMessage() . "");
- $error = true;
+ $messages[] = "{$langSetup["dbqueryfailed"]}";
+ $messages[] = sprintf($langSetup["serversaid"], "" . $e->getMessage() . "");
+ $error = true;
}
$pdo = null;
if (!$error) {
@@ -85,21 +85,21 @@ switch ($command) {
break;
case "adduser":
- $login = uUtils::postString('login');
- $pass = uUtils::postPass('pass');
+ $login = uUtils::postString('login');
+ $pass = uUtils::postPass('pass');
- if (uUser::add($login, $pass) !== false) {
- $messages[] = "{$langSetup["congratulations"]}";
- $messages[] = $langSetup["setupcomplete"];
- $messages[] = "{$langSetup["disablewarn"]}
";
- $messages[] = sprintf($langSetup["disabledesc"], "\$enabled", "false");
- } else {
- $messages[] = "{$langSetup["setupfailed"]}";
- }
+ if (uUser::add($login, $pass) !== false) {
+ $messages[] = "{$langSetup["congratulations"]}";
+ $messages[] = $langSetup["setupcomplete"];
+ $messages[] = "{$langSetup["disablewarn"]}
";
+ $messages[] = sprintf($langSetup["disabledesc"], "\$enabled", "false");
+ } else {
+ $messages[] = "{$langSetup["setupfailed"]}";
+ }
break;
default:
- $messages[] = "" . $langSetup["welcome"];
+ $messages[] = "" . $langSetup["welcome"];
if (!isset($enabled) || $enabled === false) {
$messages[] = sprintf($langSetup["disabledwarn"], "\$enabled", "true");
$messages[] = sprintf($langSetup["lineshouldread"], "
\$enabled = false;
", "
\$enabled = true;");
@@ -132,20 +132,34 @@ switch ($command) {
$messages[] = "
= $message ?>
- -= $message ?>
+ +