From 8aac741b6fae9af88af207750859c431908c4ff9 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 28 Sep 2017 08:17:45 -0400 Subject: [PATCH] Added logic to get the starting migration number --- install/index.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/install/index.php b/install/index.php index 82784cb6..e12bbe28 100644 --- a/install/index.php +++ b/install/index.php @@ -14,6 +14,42 @@ We have four possible installation scenarios: 3. Installed a recent version, but before migrations began - just pull the version # and use the dictionary below. 4. Migration number present in the settings table. Take that number and run with it. */ + +$tableSql = hesk_dbQuery("SHOW TABLES LIKE '" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings'"); +$startingMigrationNumber = 0; +if (hesk_dbNumRows($tableSql) > 0) { + // They have installed at LEAST to version 1.6.0. Just pull the version number OR migration number + $migrationNumberSql = hesk_dbQuery("SELECT `Value` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` WHERE `Key` = 'lastMigration'"); + if ($migrationRow = hesk_dbFetchAssoc($migrationNumberSql)) { + $startingMigrationNumber = $migrationRow['Value']; + } else { + $versionSql = hesk_dbQuery("SELECT `Value` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` WHERE `Key` = 'modsForHeskVersion'"); + $versionRow = hesk_dbFetchAssoc($versionSql); + + //TODO Actually map this + $startingMigrationNumber = $versionRow['Value']; + } +} else { + // migration # => sql for checking + $versionChecks = array( + // 1.5.0 -> users.active + 1 => "SHOW COLUMNS FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` LIKE 'active'", + // 1.4.1 -> denied_emails + 2 => "SHOW TABLES LIKE '" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails'", + // 1.4.0 -> denied ips + 3 => "SHOW TABLES LIKE '" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips'", + // Pre-1.4.0 but still something -> statuses + 4 => "SHOW TABLES LIKE '" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses'" + ); + + foreach ($versionChecks as $migrationNumber => $sql) { + $rs = hesk_dbQuery($sql); + if (hesk_dbNumRows($rs) > 0) { + $startingMigrationNumber = $migrationNumber; + break; + } + } +} ?> @@ -85,6 +121,9 @@ We have four possible installation scenarios: +
+

Here we'd actually be doing some things

+