From 4fc4f3f7c8154a7669bf8dd95cfb250b3344ef50 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 3 Feb 2018 13:11:17 +0100 Subject: [PATCH] Combine activate/deactivate to status --- Module/ActivateAbstract.php | 94 ------------------- Module/ModuleManager.php | 4 +- ...ctivateAbstract.php => StatusAbstract.php} | 65 ++++++++++++- 3 files changed, 66 insertions(+), 97 deletions(-) delete mode 100644 Module/ActivateAbstract.php rename Module/{DeactivateAbstract.php => StatusAbstract.php} (56%) diff --git a/Module/ActivateAbstract.php b/Module/ActivateAbstract.php deleted file mode 100644 index a0a810230..000000000 --- a/Module/ActivateAbstract.php +++ /dev/null @@ -1,94 +0,0 @@ -getDirectory() . '/Admin/Routes/http.php'); - self::activateInDatabase($dbPool, $info); - } - - /** - * Install routes. - * - * @param string $destRoutePath Destination route path - * @param string $srcRoutePath Source route path - * - * @return void - * - * @since 1.0.0 - */ - private static function activateRoutes(string $destRoutePath, string $srcRoutePath) /* : void */ - { - // todo: remove route - } - - /** - * Deactivate module in database. - * - * @param DatabasePool $dbPool Database instance - * @param InfoManager $info Module info - * - * @return void - * - * @since 1.0.0 - */ - public static function activateInDatabase(DatabasePool $dbPool, InfoManager $info) /* : void */ - { - switch ($dbPool->get()->getType()) { - case DatabaseType::MYSQL: - $dbPool->get()->con->beginTransaction(); - - $sth = $dbPool->get()->con->prepare( - 'UPDATE `' . $dbPool->get()->prefix . 'module` SET `module_active` = :active WHERE `module_id` = :internal;' - ); - - $sth->bindValue(':internal', $info->getInternalName(), \PDO::PARAM_INT); - $sth->bindValue(':active', 1, \PDO::PARAM_INT); - $sth->execute(); - - $dbPool->get()->con->commit(); - - break; - default: - throw new InvalidDatabaseTypeException($dbPool->get()->getType()); - } - } -} diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index c13915ac3..4e3b7da16 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -354,7 +354,7 @@ class ModuleManager */ private function deactivateModule(InfoManager $info) /* : void */ { - $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Deactivate'; + $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Status'; if (!Autoloader::exists($class)) { throw new InvalidModuleException($info->getDirectory()); @@ -412,7 +412,7 @@ class ModuleManager */ private function activateModule(InfoManager $info) /* : void */ { - $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Activate'; + $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Status'; if (!Autoloader::exists($class)) { throw new InvalidModuleException($info->getDirectory()); diff --git a/Module/DeactivateAbstract.php b/Module/StatusAbstract.php similarity index 56% rename from Module/DeactivateAbstract.php rename to Module/StatusAbstract.php index 8c04d2272..b4c9083f1 100644 --- a/Module/DeactivateAbstract.php +++ b/Module/StatusAbstract.php @@ -26,9 +26,72 @@ use phpOMS\DataStorage\Database\Exception\InvalidDatabaseTypeException; * @link http://website.orange-management.de * @since 1.0.0 */ -class DeactivateAbstract +class StatusAbstract { + /** + * Deactivate module. + * + * @param DatabasePool $dbPool Database instance + * @param InfoManager $info Module info + * + * @return void + * + * @since 1.0.0 + */ + public static function activate(DatabasePool $dbPool, InfoManager $info) /* : void */ + { + self::activateRoutes(__DIR__ . '/../../Web/Routes.php', __DIR__ . '/../../Modules/' . $info->getDirectory() . '/Admin/Routes/http.php'); + self::activateInDatabase($dbPool, $info); + } + + /** + * Install routes. + * + * @param string $destRoutePath Destination route path + * @param string $srcRoutePath Source route path + * + * @return void + * + * @since 1.0.0 + */ + private static function activateRoutes(string $destRoutePath, string $srcRoutePath) /* : void */ + { + // todo: remove route + } + + /** + * Deactivate module in database. + * + * @param DatabasePool $dbPool Database instance + * @param InfoManager $info Module info + * + * @return void + * + * @since 1.0.0 + */ + public static function activateInDatabase(DatabasePool $dbPool, InfoManager $info) /* : void */ + { + switch ($dbPool->get()->getType()) { + case DatabaseType::MYSQL: + $dbPool->get()->con->beginTransaction(); + + $sth = $dbPool->get()->con->prepare( + 'UPDATE `' . $dbPool->get()->prefix . 'module` SET `module_active` = :active WHERE `module_id` = :internal;' + ); + + $sth->bindValue(':internal', $info->getInternalName(), \PDO::PARAM_INT); + $sth->bindValue(':active', 1, \PDO::PARAM_INT); + $sth->execute(); + + $dbPool->get()->con->commit(); + + break; + default: + throw new InvalidDatabaseTypeException($dbPool->get()->getType()); + } + } + /** * Deactivate module. *