aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/1.127_setup_api.php
diff options
context:
space:
mode:
authorPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
committerPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
commit4459dd7917f4d1c34f40bb68f0e991e9c3d53e4c (patch)
tree5c07151ae61276d334e88f6309c30d439a85c12e /db/migrations/1.127_setup_api.php
parentda0022e5c1abbf9825ae76debaabdff7e8623bb4 (diff)
parent97a188592c679890a25c37ab78463add76a52ff7 (diff)
Merge branch 'main' into issue-3911issue-3911
Diffstat (limited to 'db/migrations/1.127_setup_api.php')
-rw-r--r--db/migrations/1.127_setup_api.php71
1 files changed, 41 insertions, 30 deletions
diff --git a/db/migrations/1.127_setup_api.php b/db/migrations/1.127_setup_api.php
index 7cae3f9..73b36f6 100644
--- a/db/migrations/1.127_setup_api.php
+++ b/db/migrations/1.127_setup_api.php
@@ -1,12 +1,46 @@
<?php
class SetupApi extends Migration
{
- function description()
+ public function description()
{
return 'Creates api tables in database and according config entries';
}
- function up()
+ public function up()
+ {
+ $this->createTables();
+
+ // Add config entries
+ $query = "INSERT IGNORE INTO `config`
+ (`config_id`, `field`, `value`, `is_default`, `type`, `range`, `section`,
+ `mkdate`, `chdate`, `description`)
+ VALUES (MD5(:field), :field, :value, 1, :type, 'global', 'global',
+ UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), :description)";
+ $statement = DBManager::get()->prepare($query);
+
+ $statement->execute([
+ ':field' => 'API_ENABLED',
+ ':value' => (int)false,
+ ':type' => 'boolean',
+ ':description' => 'Schaltet die REST-API an',
+ ]);
+
+ $statement->execute([
+ ':field' => 'API_OAUTH_AUTH_PLUGIN',
+ ':value' => 'Standard',
+ ':type' => 'string',
+ ':description' => 'Definiert das für OAuth verwendete Authentifizierungsverfahren',
+ ]);
+ }
+
+ public function down()
+ {
+ DBManager::get()->exec("DELETE FROM config WHERE field IN ('API_ENABLED', 'API_OAUTH_AUTH_PLUGIN')");
+
+ $this->dropTables();
+ }
+
+ public function createTables(): void
{
// Add vendor tables
$query = "CREATE TABLE IF NOT EXISTS `oauth_consumer_registry` (
@@ -29,7 +63,7 @@ class SetupApi extends Migration
KEY `ocr_usa_id_ref` (`ocr_usa_id_ref`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
DBManager::get()->exec($query);
-
+
$query = "CREATE TABLE IF NOT EXISTS `oauth_consumer_token` (
`oct_id` int(11) NOT NULL AUTO_INCREMENT,
`oct_ocr_id_ref` int(11) NOT NULL,
@@ -47,7 +81,7 @@ class SetupApi extends Migration
CONSTRAINT `oauth_consumer_token_ibfk_1` FOREIGN KEY (`oct_ocr_id_ref`) REFERENCES `oauth_consumer_registry` (`ocr_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
DBManager::get()->exec($query);
-
+
$query = "CREATE TABLE IF NOT EXISTS `oauth_log` (
`olg_id` int(11) NOT NULL AUTO_INCREMENT,
`olg_osr_consumer_key` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
@@ -80,7 +114,7 @@ class SetupApi extends Migration
UNIQUE KEY `osn_consumer_key` (`osn_consumer_key`,`osn_token`,`osn_timestamp`,`osn_nonce`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
DBManager::get()->exec($query);
-
+
$query = "CREATE TABLE IF NOT EXISTS `oauth_server_registry` (
`osr_id` int(11) NOT NULL AUTO_INCREMENT,
`osr_usa_id_ref` int(11) DEFAULT NULL,
@@ -176,39 +210,16 @@ class SetupApi extends Migration
PRIMARY KEY (`user_id`,`consumer_id`)
) ENGINE=MyISAM";
DBManager::get()->exec($query);
-
- // Add config entries
- $query = "INSERT IGNORE INTO `config`
- (`config_id`, `field`, `value`, `is_default`, `type`, `range`, `section`,
- `mkdate`, `chdate`, `description`)
- VALUES (MD5(:field), :field, :value, 1, :type, 'global', 'global',
- UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), :description)";
- $statement = DBManager::get()->prepare($query);
-
- $statement->execute([
- ':field' => 'API_ENABLED',
- ':value' => (int)false,
- ':type' => 'boolean',
- ':description' => 'Schaltet die REST-API an',
- ]);
-
- $statement->execute([
- ':field' => 'API_OAUTH_AUTH_PLUGIN',
- ':value' => 'Standard',
- ':type' => 'string',
- ':description' => 'Definiert das für OAuth verwendete Authentifizierungsverfahren',
- ]);
}
- function down()
+ public function dropTables(): void
{
- DBManager::get()->exec("DELETE FROM config WHERE field IN ('API_ENABLED', 'API_OAUTH_AUTH_PLUGIN')");
DBManager::get()->exec("DROP TABLE IF EXISTS `oauth_consumer_registry`,
`oauth_consumer_token`,
`oauth_log`,
`oauth_server_nonce`,
`oauth_server_registry`,
- `oauth_server_token`
+ `oauth_server_token`,
`api_consumer_permissions`,
`api_consumers`,
`api_oauth_user_mapping`,