mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
Combine activate/deactivate to status
This commit is contained in:
parent
c71556a6d8
commit
4fc4f3f7c8
|
|
@ -1,94 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @package Framework
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace phpOMS\Module;
|
||||
|
||||
use phpOMS\DataStorage\Database\DatabaseType;
|
||||
use phpOMS\DataStorage\Database\DatabasePool;
|
||||
use phpOMS\DataStorage\Database\Exception\InvalidDatabaseTypeException;
|
||||
|
||||
/**
|
||||
* Installer Abstract class.
|
||||
*
|
||||
* @package Framework
|
||||
* @license OMS License 1.0
|
||||
* @link http://website.orange-management.de
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ActivateAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*
|
||||
Loading…
Reference in New Issue
Block a user