diff --git a/core/.gitignore b/core/.gitignore new file mode 100644 index 0000000..8fca34b --- /dev/null +++ b/core/.gitignore @@ -0,0 +1 @@ +TemplateCache \ No newline at end of file diff --git a/core/Api/Parameter/Parameter.class.php b/core/Api/Parameter/Parameter.class.php index 06e4ac8..167322e 100644 --- a/core/Api/Parameter/Parameter.class.php +++ b/core/Api/Parameter/Parameter.class.php @@ -104,11 +104,11 @@ class Parameter { return Parameter::TYPE_BOOLEAN; else if(is_a($value, 'DateTime')) return Parameter::TYPE_DATE_TIME; - else if(($d = DateTime::createFromFormat(self::DATE_FORMAT, $value)) && $d->format(self::DATE_FORMAT) === $value) + else if($value !== null && ($d = DateTime::createFromFormat(self::DATE_FORMAT, $value)) && $d->format(self::DATE_FORMAT) === $value) return Parameter::TYPE_DATE; - else if(($d = DateTime::createFromFormat(self::TIME_FORMAT, $value)) && $d->format(self::TIME_FORMAT) === $value) + else if($value !== null && ($d = DateTime::createFromFormat(self::TIME_FORMAT, $value)) && $d->format(self::TIME_FORMAT) === $value) return Parameter::TYPE_TIME; - else if(($d = DateTime::createFromFormat(self::DATE_TIME_FORMAT, $value)) && $d->format(self::DATE_TIME_FORMAT) === $value) + else if($value !== null && ($d = DateTime::createFromFormat(self::DATE_TIME_FORMAT, $value)) && $d->format(self::DATE_TIME_FORMAT) === $value) return Parameter::TYPE_DATE_TIME; else if (filter_var($value, FILTER_VALIDATE_EMAIL)) return Parameter::TYPE_EMAIL; diff --git a/core/Api/UserAPI.class.php b/core/Api/UserAPI.class.php index 121c966..14d6b9c 100644 --- a/core/Api/UserAPI.class.php +++ b/core/Api/UserAPI.class.php @@ -67,11 +67,11 @@ namespace Api { $this->checkPasswordRequirements($password, $confirmPassword); } - protected function insertUser($username, $email, $password, $confirmed, $fullName = null) { + protected function insertUser($username, $email, $password, $confirmed, $fullName = "") { $sql = $this->user->getSQL(); $hash = $this->hashPassword($password); $res = $sql->insert("User", array("name", "password", "email", "confirmed", "fullName")) - ->addRow($username, $hash, $email, $confirmed, $fullName) + ->addRow($username, $hash, $email, $confirmed, $fullName ?? "") ->returning("uid") ->execute(); diff --git a/core/Configuration/CreateDatabase.class.php b/core/Configuration/CreateDatabase.class.php index 61696ad..de7a0e1 100644 --- a/core/Configuration/CreateDatabase.class.php +++ b/core/Configuration/CreateDatabase.class.php @@ -27,6 +27,24 @@ class CreateDatabase extends DatabaseScript { ->addRow("en_US", 'American English') ->addRow("de_DE", 'Deutsch Standard'); + + $queries[] = $sql->createTable("GpgKey") + ->addSerial("uid") + ->addString("fingerprint", 64) + ->addDateTime("added", false, $sql->now()) + ->addDateTime("expires") + ->addBool("confirmed") + ->addString("algorithm", 32) + ->primaryKey("uid"); + + $queries[] = $sql->createTable("2FA") + ->addSerial("uid") + ->addEnum("type", ["totp","fido"]) + ->addString("data", 512) // either totp secret, fido challenge or fido public key information + ->addBool("confirmed", false) + ->addDateTime("added", false, $sql->now()) + ->primaryKey("uid"); + $queries[] = $sql->createTable("User") ->addSerial("uid") ->addString("email", 64, true) @@ -210,23 +228,6 @@ class CreateDatabase extends DatabaseScript { ->primaryKey("uid"); $queries = array_merge($queries, \Configuration\Patch\log::createTableLog($sql, "MailQueue", 30)); - $queries[] = $sql->createTable("GpgKey") - ->addSerial("uid") - ->addString("fingerprint", 64) - ->addDateTime("added", false, $sql->now()) - ->addDateTime("expires") - ->addBool("confirmed") - ->addString("algorithm", 32) - ->primaryKey("uid"); - - $queries[] = $sql->createTable("2FA") - ->addSerial("uid") - ->addEnum("type", ["totp","fido"]) - ->addString("data", 512) // either totp secret, fido challenge or fido public key information - ->addBool("confirmed", false) - ->addDateTime("added", false, $sql->now()) - ->primaryKey("uid"); - $queries[] = $sql->createTable("News") ->addSerial("uid") ->addInt("publishedBy") diff --git a/core/Documents/Install.class.php b/core/Documents/Install.class.php index 37ac920..b545407 100644 --- a/core/Documents/Install.class.php +++ b/core/Documents/Install.class.php @@ -17,6 +17,9 @@ namespace Documents { namespace Documents\Install { use Configuration\CreateDatabase; + use Driver\SQL\Query\Commit; + use Driver\SQL\Query\RollBack; + use Driver\SQL\Query\StartTransaction; use Driver\SQL\SQL; use Elements\Body; use Elements\Head; @@ -271,10 +274,21 @@ namespace Documents\Install { $msg = ""; $success = true; $queries = CreateDatabase::createQueries($sql); + array_unshift($queries, new StartTransaction($sql)); + $queries[] = new Commit($sql); foreach ($queries as $query) { - if (!($res = $query->execute())) { - $msg = "Error creating tables: " . $sql->getLastError(); - $success = false; + try { + if (!$query->execute()) { + $msg = "Error creating tables: " . $sql->getLastError(); + $success = false; + } + } finally { + if (!$success) { + (new RollBack($sql))->execute(); + } + } + + if (!$success) { break; } } @@ -619,7 +633,7 @@ namespace Documents\Install { )), array( "title" => "Encoding", "name" => "encoding", "type" => "text", "required" => false, - "value" => "UTF-8" + "value" => "UTF8" ), ) ), diff --git a/core/Driver/SQL/Query/Commit.class.php b/core/Driver/SQL/Query/Commit.class.php new file mode 100644 index 0000000..a6b9c34 --- /dev/null +++ b/core/Driver/SQL/Query/Commit.class.php @@ -0,0 +1,15 @@ +