From 3d997992642ecfa56591f40b118cb7bb0b2fb1dc Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Wed, 17 Jan 2018 15:47:00 +0100 Subject: [PATCH] Fix di alcuni bug (#117) Risoluzione di alcuni malfunzionamenti durante l'installazione causati da codice non aggiornato. --- include/configuration.php | 11 +++-- src/Update.php | 92 +++++++++++++++++++++++++++------------ 2 files changed, 70 insertions(+), 33 deletions(-) diff --git a/include/configuration.php b/include/configuration.php index 7e5da1780..8e06cd50f 100644 --- a/include/configuration.php +++ b/include/configuration.php @@ -50,14 +50,13 @@ if (post('db_host') !== null) { $results = $dbo->fetchArray('SHOW GRANTS FOR CURRENT_USER'); foreach ($results as $result) { + $privileges = current($result); + if ( - str_contains($result, $find) && - ( - str_contains($result, ' ON `'.$db_name.'`.*') || - str_contains($result, ' ON *.*') - ) + str_contains($privileges, ' ON `'.$db_name.'`.*') || + str_contains($privileges, ' ON *.*') ) { - $pieces = explode(', ', explode(' ON ', str_replace('GRANT ', '', current($result)))[0]); + $pieces = explode(', ', explode(' ON ', str_replace('GRANT ', '', $privileges))[0]); if (in_array('ALL', $pieces) || in_array('ALL PRIVILEGES', $pieces)) { break; diff --git a/src/Update.php b/src/Update.php index 279615bac..5ac0be960 100644 --- a/src/Update.php +++ b/src/Update.php @@ -20,35 +20,12 @@ class Update $database_ready = $database->isConnected() && $database->fetchNum("SHOW TABLES LIKE 'updates'"); // Individuazione di tutti gli aggiornamenti fisicamente presenti - $results = []; - // Aggiornamenti del gestionale - $core = (array) glob(DOCROOT.'/update/*.{php,sql}', GLOB_BRACE); - foreach ($core as $value) { - $infos = pathinfo($value); - $value = str_replace('_', '.', $infos['filename']); - - if (self::isVersion($value)) { - $results[] = $value; - } - } - + $core = self::getCoreUpdates(); // Aggiornamenti dei moduli - $modules = (array) glob(DOCROOT.'/modules/*/update/*.{php,sql}', GLOB_BRACE); - foreach ($modules as $value) { - $infos = pathinfo($value); + $modules = self::getModulesUpdates(); - $module = end(explode('/', dirname($infos['dirname']))); - - $value = str_replace('_', '.', $infos['filename']); - - if (self::isVersion($value)) { - $results[] = $module.'_'.$value; - } - } - - $results = array_unique($results); - asort($results); + $results = array_merge($core, $modules); // Individuazione di tutti gli aggiornamenti inseriti $updates = ($database_ready) ? $database->fetchArray('SELECT * FROM `updates`') : []; @@ -89,6 +66,61 @@ class Update } } + /** + * Restituisce l'elenco degli aggiornamento del gestionale presenti nella cartella update. + * + * @return array + */ + protected static function getCoreUpdates() + { + $results = []; + + // Aggiornamenti del gestionale + $core = (array) glob(DOCROOT.'/update/*.{php,sql}', GLOB_BRACE); + foreach ($core as $value) { + $infos = pathinfo($value); + $value = str_replace('_', '.', $infos['filename']); + + if (self::isVersion($value)) { + $results[] = $value; + } + } + + $results = array_unique($results); + asort($results); + + return $results; + } + + /** + * Restituisce l'elenco degli aggiornamento dei moduli, presenti nella cartella update dei singoli moduli. + * + * @return array + */ + protected static function getModulesUpdates() + { + $results = []; + + // Aggiornamenti dei moduli + $modules = (array) glob(DOCROOT.'/modules/*/update/*.{php,sql}', GLOB_BRACE); + foreach ($modules as $value) { + $infos = pathinfo($value); + + $module = end(explode('/', dirname($infos['dirname']))); + + $value = str_replace('_', '.', $infos['filename']); + + if (self::isVersion($value)) { + $results[] = $module.'_'.$value; + } + } + + $results = array_unique($results); + asort($results); + + return $results; + } + /** * Restituisce l'elenco degli aggiornamento incompleti o non ancora effettuati. * @@ -205,7 +237,13 @@ class Update $result = self::getFile('VERSION'); if (empty($result)) { - $result = self::getDatabaseVersion(); + $database = Database::getConnection(); + + if ($database->isInstalled()) { + $result = self::getDatabaseVersion(); + } else { + $result = end(self::getCoreUpdates()); + } } return $result;