From 3bfb94b0b402ff08e5888afb946384316f6d3e60 Mon Sep 17 00:00:00 2001 From: Greg Roach Date: Tue, 2 Jun 2015 23:51:34 +0100 Subject: Refactor database migrations to use autoloading and remove duplicates --- app/Module/GoogleMaps/Schema/Migration0.php | 48 +++++++++++++++++++++++++++++ app/Module/GoogleMaps/Schema/Migration1.php | 44 ++++++++++++++++++++++++++ app/Module/GoogleMaps/Schema/Migration2.php | 31 +++++++++++++++++++ app/Module/GoogleMaps/Schema/Migration3.php | 36 ++++++++++++++++++++++ app/Module/GoogleMaps/Schema/Migration4.php | 33 ++++++++++++++++++++ 5 files changed, 192 insertions(+) create mode 100644 app/Module/GoogleMaps/Schema/Migration0.php create mode 100644 app/Module/GoogleMaps/Schema/Migration1.php create mode 100644 app/Module/GoogleMaps/Schema/Migration2.php create mode 100644 app/Module/GoogleMaps/Schema/Migration3.php create mode 100644 app/Module/GoogleMaps/Schema/Migration4.php (limited to 'app/Module/GoogleMaps') diff --git a/app/Module/GoogleMaps/Schema/Migration0.php b/app/Module/GoogleMaps/Schema/Migration0.php new file mode 100644 index 0000000000..ccaf8355d2 --- /dev/null +++ b/app/Module/GoogleMaps/Schema/Migration0.php @@ -0,0 +1,48 @@ +. + */ +use Fisharebest\Webtrees\Database; +use Fisharebest\Webtrees\Schema\MigrationInterface; + +/** + * Class Migration0 - upgrade the database schema from version 0 (empty database) to version 1. + */ +class Migration0 implements MigrationInterface { + /** {@inheritDoc} */ + public function upgrade() { + // Create the tables, as per PhpGedView 4.2.1 + + Database::exec( + "CREATE TABLE IF NOT EXISTS `##placelocation` (" . + " pl_id INTEGER NOT NULL," . + " pl_parent_id INTEGER NULL," . + " pl_level INTEGER NULL," . + " pl_place VARCHAR(255) NULL," . + " pl_long VARCHAR(30) NULL," . + " pl_lati VARCHAR(30) NULL," . + " pl_zoom INTEGER NULL," . + " pl_icon VARCHAR(255) NULL," . + " PRIMARY KEY (pl_id)," . + " KEY ix1 (pl_level)," . + " KEY ix2 (pl_long)," . + " KEY ix3 (pl_lati)," . + " KEY ix4 (pl_place)," . + " KEY ix5 (pl_parent_id)" . + ") COLLATE utf8_unicode_ci ENGINE=InnoDB" + ); + } +} diff --git a/app/Module/GoogleMaps/Schema/Migration1.php b/app/Module/GoogleMaps/Schema/Migration1.php new file mode 100644 index 0000000000..d5843e5c65 --- /dev/null +++ b/app/Module/GoogleMaps/Schema/Migration1.php @@ -0,0 +1,44 @@ +. + */ +use Fisharebest\Webtrees\Database; +use Fisharebest\Webtrees\Schema\MigrationInterface; +use PDOException; + +/** + * Class Migration1 - upgrade the database schema from version 1 to version 2. + */ +class Migration1 implements MigrationInterface { + /** {@inheritDoc} */ + public function upgrade() { + // Update the tables to support streetview + try { + Database::exec( + "ALTER TABLE `##placelocation` ADD (" . + " pl_media VARCHAR(60) NULL," . + " sv_long FLOAT NOT NULL DEFAULT 0," . + " sv_lati FLOAT NOT NULL DEFAULT 0," . + " sv_bearing FLOAT NOT NULL DEFAULT 0," . + " sv_elevation FLOAT NOT NULL DEFAULT 0," . + " sv_zoom FLOAT NOT NULL DEFAULT 1" . + ")" + ); + } catch (PDOException $ex) { + // Already done this? + } + } +} diff --git a/app/Module/GoogleMaps/Schema/Migration2.php b/app/Module/GoogleMaps/Schema/Migration2.php new file mode 100644 index 0000000000..ac17dce363 --- /dev/null +++ b/app/Module/GoogleMaps/Schema/Migration2.php @@ -0,0 +1,31 @@ +. + */ +use Fisharebest\Webtrees\Database; +use Fisharebest\Webtrees\Schema\MigrationInterface; + +/** + * Class Migration2 - upgrade the database schema from version 2 to version 3. + */ +class Migration2 implements MigrationInterface { + /** {@inheritDoc} */ + public function upgrade() { + // Convert flag icons from .gif to .png + + Database::exec("UPDATE `##placelocation` SET pl_icon=REPLACE(pl_icon, '.gif', '.png')"); + } +} diff --git a/app/Module/GoogleMaps/Schema/Migration3.php b/app/Module/GoogleMaps/Schema/Migration3.php new file mode 100644 index 0000000000..a10ef44920 --- /dev/null +++ b/app/Module/GoogleMaps/Schema/Migration3.php @@ -0,0 +1,36 @@ +. + */ +use Fisharebest\Webtrees\Database; +use Fisharebest\Webtrees\Schema\MigrationInterface; + +/** + * Class Migration3 - upgrade the database schema from version 3 to version 4. + */ +class Migration3 implements MigrationInterface { + /** {@inheritDoc} */ + public function upgrade() { + // Combine the two ways of enabling the GM module + Database::exec( + "UPDATE `##module` m, `##module_setting` ms SET m.status=CASE WHEN (m.status=1 AND ms.setting_value=1) THEN 'enabled' ELSE 'disabled' END WHERE m.module_name=ms.module_name AND m.module_name='googlemap' AND ms.setting_name='GM_ENABLED'" + ); + + Database::exec( + "DELETE FROM `##module_setting` WHERE module_name='googlemap' AND setting_name='GM_ENABLED'" + ); + } +} diff --git a/app/Module/GoogleMaps/Schema/Migration4.php b/app/Module/GoogleMaps/Schema/Migration4.php new file mode 100644 index 0000000000..a07a4c448d --- /dev/null +++ b/app/Module/GoogleMaps/Schema/Migration4.php @@ -0,0 +1,33 @@ +. + */ +use Fisharebest\Webtrees\Database; +use Fisharebest\Webtrees\Schema\MigrationInterface; + +/** + * Class Migration4 - upgrade the database schema from version 4 to version 5. + */ +class Migration4 implements MigrationInterface { + /** {@inheritDoc} */ + public function upgrade() { + // Delete some old/unused configuration settings + Database::exec( + "DELETE FROM `##module_setting` WHERE module_name='googlemap' AND setting_name IN ( + 'GM_API_KEY', 'GM_DEFAULT_TOP_VALUE', 'GM_DISP_COUNT', 'GM_MAX_NOF_LEVELS', 'GM_PH_CONTROLS', 'GM_PH_WHEEL', 'GM_PRE_POST_MODE_1', 'GM_PRE_POST_MODE_2', 'GM_PRE_POST_MODE_3', 'GM_PRE_POST_MODE_4', 'GM_PRE_POST_MODE_5', 'GM_PRE_POST_MODE_6', 'GM_PRE_POST_MODE_7', 'GM_PRE_POST_MODE_8', 'GM_PRE_POST_MODE_9')" + ); + } +} -- cgit v1.3