summaryrefslogtreecommitdiffstats
path: root/includes/giglogadmin-register-db-tables.php
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2023-01-20 20:22:06 +0100
committerHarald Eilertsen <haraldei@anduin.net>2023-01-20 20:22:06 +0100
commit277fedffc624f55c6ecc8bd80ed8db370134e47e (patch)
treeac22560f978c3789a63c80284fbd314e11d0b396 /includes/giglogadmin-register-db-tables.php
parentf499d9e657fe79e4413eec9e20ae13d616fac6f5 (diff)
downloadgigologadmin-277fedffc624f55c6ecc8bd80ed8db370134e47e.tar.gz
gigologadmin-277fedffc624f55c6ecc8bd80ed8db370134e47e.tar.bz2
gigologadmin-277fedffc624f55c6ecc8bd80ed8db370134e47e.zip
Rename and reorganize more source files.
Diffstat (limited to 'includes/giglogadmin-register-db-tables.php')
-rw-r--r--includes/giglogadmin-register-db-tables.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/includes/giglogadmin-register-db-tables.php b/includes/giglogadmin-register-db-tables.php
new file mode 100644
index 0000000..84df6e8
--- /dev/null
+++ b/includes/giglogadmin-register-db-tables.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Register custome database tables used by GiglogAdmin
+ *
+ * @package giglogadmin
+ *
+ * SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
+ * SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+if ( ! function_exists( 'giglog_register_db_tables' ) ) {
+ /**
+ * Registers the tables used by the GiglogAdmin plugin
+ */
+ function giglog_register_db_tables() : void {
+ global $wpdb;
+
+ $tables = array();
+ $tables[] =
+ "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}giglogadmin_venues` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `wpgvenue_name` VARCHAR(500) NOT NULL,
+ `wpgvenue_city` VARCHAR(250) DEFAULT NULL,
+ `wpgvenue_address` VARCHAR(2000) DEFAULT NULL,
+ `wpgvenue_webpage` VARCHAR(200) DEFAULT NULL,
+ `created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ `updated` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
+
+ $tables[] =
+ "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}giglogadmin_concerts` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `wpgconcert_name` VARCHAR(2000) NOT NULL,
+ `venue` int(11) NOT NULL,
+ `wpgconcert_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `wpgconcert_tickets` VARCHAR(2000) DEFAULT NULL,
+ `wpgconcert_event` VARCHAR(2000) DEFAULT NULL,
+ `wpgconcert_type` INT NOT NULL DEFAULT '1' COMMENT '1 concert, 2 festival',
+ `wpgconcert_status` INT DEFAULT 1,
+ `wpgconcert_roles` JSON CHECK (JSON_VALID(wpgconcert_roles)),
+ `created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ `updated` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`),
+ CONSTRAINT `wpgconcert_venue`
+ FOREIGN KEY (`venue`)
+ REFERENCES `{$wpdb->prefix}giglogadmin_venues` (`id`) ON DELETE NO ACTION
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
+
+ foreach ( $tables as $tabledef ) {
+ // This use of the `query` nethod is safe
+ // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
+ $result = $wpdb->query( $tabledef );
+
+ if ( $result === false ) {
+ error_log( 'Registering table failed.' );
+ }
+ }
+ }
+}