Skip to content

Commit

Permalink
Merge pull request #2 from JonisoftGermany/release-2.0.2
Browse files Browse the repository at this point in the history
Release 2.0.2
  • Loading branch information
JonisoftGermany authored Jan 30, 2022
2 parents a3d389d + b52f242 commit 1e29faf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
26 changes: 24 additions & 2 deletions ErrorReport2.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,32 @@
* ErrorReport2 Model
*
* @package ErrorReport2
* @version 2.0.0
* @version 2.0.2
*/
final class ErrorReport2 extends SuperStorage
{}
{
public static function databaseTableVersion() : ?int
{
$storage_engine = self::storageEngine();
$database = $storage_engine->database();
$database_name = $storage_engine->database()->getDatabaseConfig()->getDatabase();
$table_name = $storage_engine->tableName();
$query = 'SHOW TABLE STATUS FROM ' . $database_name . ' LIKE "' . $table_name . '"';

$results = $database->query($query);
if ($results = mysqli_fetch_object($results)) {
$table_comment = $results->Comment;
$comments = preg_split('/^\\\\,/', $table_comment);
foreach ($comments as $comment) {
if (strncmp($comment, 'er2-db-vers:', 12) === 0) {
return (int)substr($comment, 12);
}
}
}

return null;
}
}


?>
15 changes: 13 additions & 2 deletions ErrorReport2Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
* ErrorReport2 Server
*
* @package ErrorReport2
* @version 2.0.1
* @version 2.0.2
*/
final class ErrorReport2Server extends Controller
{
private const ER2_VERSION = '2.0.1';
private const ER2_VERSION = '2.0.2';

public const REQUIRED_DATABASE_VERSION = 2;

private const ERROR_RESPONSE_CODE = 400;
private const SUCCESS_RESPONSE_CODE = 201;
Expand Down Expand Up @@ -60,6 +62,15 @@ public function __construct(string $method_name, Request $request)
}

$this->config = $er2_server_config;

if (!self::checkDatabaseVersion()) {
throw new \RuntimeException('Unmatching database version');
}
}

public static function checkDatabaseVersion() : bool
{
return ErrorReport2::databaseTableVersion() === self::REQUIRED_DATABASE_VERSION;
}

private function checkHttpMethod(Request $request) : void
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ __Example for 6.:__
$config->setER2Config((new \ErrorReport2\ErrorReport2ServerConfig())->addToken('3915753d8765a0'));
```

## Update
When ER2 is included as git submodule, update the submodule.
Some updates come with database structure changes.
The database updates (sql batch files) can be found in db-directory.
They must be executed in the database manually.

## Configuration

### Required configuration
Expand Down
5 changes: 5 additions & 0 deletions db/update_201->202.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Error Report 2 Module
-- Update from ER2 2.0.1 to 2.0.2

ALTER TABLE ErrorReport2 CHANGE COLUMN `debug_mode` `debug_mode` tinyint unsigned COMMENT 'BOOL';
ALTER TABLE ErrorReport2 COMMENT = 'er2-db-vers:2';
6 changes: 3 additions & 3 deletions er2.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Error Report 2 Module
-- Version 2.0.1
-- Version 2.0.2


CREATE TABLE ErrorReport2 (
Expand All @@ -17,7 +17,7 @@ CREATE TABLE ErrorReport2 (
`php_version` varchar(20) NOT NULL,
`php_mode` varchar(30) NOT NULL,
`php_mem_usage` bigint unsigned NOT NULL,
`debug_mode` tinyint unsigned NOT NULL COMMENT 'BOOL',
`debug_mode` tinyint unsigned COMMENT 'BOOL',
`request_method` enum('CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'TRACE') NOT NULL,
`request_domain` varchar(255) NOT NULL,
`request_subdomain` varchar(255) NOT NULL,
Expand All @@ -33,4 +33,4 @@ CREATE TABLE ErrorReport2 (
`session` text,
`errors` text,
`throwable` text
) ENGINE = InnoDB;
) ENGINE = InnoDB, COMMENT = 'er2-db-vers:2';

0 comments on commit 1e29faf

Please sign in to comment.