From 0c703ce2cfdbc97c74b57c0d0b5f9f60d0487a2b Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 1 Apr 2021 19:33:02 +0200 Subject: Populate the pressstatus table on activation. Was missing in the first import. This looks like pure static data, though, and will probably be moved to constants in the code instead. While this doesn't really change the db schema, the db version was incremented to version 2, to make sure the new data is added, even if the db is already initialized. --- includes/admin/register_db_tables.php | 83 +++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/includes/admin/register_db_tables.php b/includes/admin/register_db_tables.php index a54e2c8..9cff614 100644 --- a/includes/admin/register_db_tables.php +++ b/includes/admin/register_db_tables.php @@ -247,13 +247,15 @@ if (!function_exists('giglogadmin_populate_countries')) { } } -if ( !function_exists( "giglog_register_db_tables") ) { - $db_version = get_option('giglogadmin_db_version'); - if ($db_version == 1) { - return; - } +if ( !function_exists( "giglog_register_db_tables") ) +{ + function giglog_register_db_tables() + { + $db_version = get_option('giglogadmin_db_version'); + if ($db_version == 2) { + return; + } - function giglog_register_db_tables() { $bands_table = "CREATE TABLE IF NOT EXISTS `wpg_bands` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -358,38 +360,53 @@ if ( !function_exists( "giglog_register_db_tables") ) { } } - giglogadmin_populate_countries(); + if ($db_version == NULL || $db_version < 1) + { + giglogadmin_populate_countries(); - $wpdb->query( - "ALTER TABLE `wpg_countries` - ADD FULLTEXT KEY `id` - (`id`,`wpgc_fullname`,`wpgcountry_name`,`wpgc_iso3`,`wpgc_numcode`);"); + $wpdb->query( + "ALTER TABLE `wpg_countries` + ADD FULLTEXT KEY `id` + (`id`,`wpgc_fullname`,`wpgcountry_name`,`wpgc_iso3`,`wpgc_numcode`);"); - $wpdb->query( - "ALTER TABLE `wpg_bands` - ADD CONSTRAINT `wpgband_country` - FOREIGN KEY (`wpgband_country`) - REFERENCES `wpg_countries` (`id`) ON DELETE NO ACTION;"); + $wpdb->query( + "ALTER TABLE `wpg_bands` + ADD CONSTRAINT `wpgband_country` + FOREIGN KEY (`wpgband_country`) + REFERENCES `wpg_countries` (`id`) ON DELETE NO ACTION;"); - $wpdb->query( - "ALTER TABLE `wpg_concertlogs` - ADD CONSTRAINT `wpglog_concerts` - FOREIGN KEY (`wpgcl_concertid`) - REFERENCES `wpg_concerts` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION, - ADD CONSTRAINT `wpglog_status` - FOREIGN KEY (`wpgcl_status`) - REFERENCES `wpg_pressstatus` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;"); + $wpdb->query( + "ALTER TABLE `wpg_concertlogs` + ADD CONSTRAINT `wpglog_concerts` + FOREIGN KEY (`wpgcl_concertid`) + REFERENCES `wpg_concerts` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION, + ADD CONSTRAINT `wpglog_status` + FOREIGN KEY (`wpgcl_status`) + REFERENCES `wpg_pressstatus` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;"); - $wpdb->query( - "ALTER TABLE `wpg_concerts` - ADD CONSTRAINT `wpgconcert_band` - FOREIGN KEY (`band`) - REFERENCES `wpg_bands` (`id`) ON DELETE NO ACTION, - ADD CONSTRAINT `wpgconcert_venue` - FOREIGN KEY (`venue`) - REFERENCES `wpg_venues` (`id`) ON DELETE NO ACTION;"); + $wpdb->query( + "ALTER TABLE `wpg_concerts` + ADD CONSTRAINT `wpgconcert_band` + FOREIGN KEY (`band`) + REFERENCES `wpg_bands` (`id`) ON DELETE NO ACTION, + ADD CONSTRAINT `wpgconcert_venue` + FOREIGN KEY (`venue`) + REFERENCES `wpg_venues` (`id`) ON DELETE NO ACTION;"); + } + + if ($db_version == NULL || $db_version < 2) + { + $wpdb->query( + "INSERT INTO `wpg_pressstatus` (`id`, `wpgs_name`) VALUES + (1, ' '), + (2, 'Accred Requested'), + (3, 'Photo Approved'), + (4, 'Text Approved'), + (5, 'Photo and Text approved'), + (6, 'Rejected');"); + } - update_option("giglogadmin_db_version", 1); + update_option("giglogadmin_db_version", 2); } giglog_register_db_tables(); -- cgit v1.2.3