Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| UninstallerAbstract | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
| uninstall | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| dropTables | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
4 | |||
| unregisterFromDatabase | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Application |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Application; |
| 16 | |
| 17 | use phpOMS\DataStorage\Database\DatabasePool; |
| 18 | use phpOMS\DataStorage\Database\Query\Builder; |
| 19 | use phpOMS\DataStorage\Database\Schema\Builder as SchemaBuilder; |
| 20 | |
| 21 | /** |
| 22 | * Uninstaller abstract class. |
| 23 | * |
| 24 | * @package phpOMS\Application |
| 25 | * @license OMS License 2.0 |
| 26 | * @link https://jingga.app |
| 27 | * @since 1.0.0 |
| 28 | */ |
| 29 | abstract class UninstallerAbstract |
| 30 | { |
| 31 | /** |
| 32 | * Path of the file |
| 33 | * |
| 34 | * @var string |
| 35 | * @since 1.0.0 |
| 36 | */ |
| 37 | public const PATH = ''; |
| 38 | |
| 39 | /** |
| 40 | * Install module. |
| 41 | * |
| 42 | * @param DatabasePool $dbPool Database instance |
| 43 | * @param ApplicationInfo $info App info |
| 44 | * |
| 45 | * @return void |
| 46 | * |
| 47 | * @since 1.0.0 |
| 48 | */ |
| 49 | public static function uninstall(DatabasePool $dbPool, ApplicationInfo $info) : void |
| 50 | { |
| 51 | //self::deactivate($dbPool, $info); |
| 52 | self::dropTables($dbPool, $info); |
| 53 | self::unregisterFromDatabase($dbPool, $info); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Activate after install. |
| 58 | * |
| 59 | * @param DatabasePool $dbPool Database instance |
| 60 | * @param ApplicationInfo $info App info |
| 61 | * |
| 62 | * @return void |
| 63 | * |
| 64 | * @since 1.0.0 |
| 65 | */ |
| 66 | /* |
| 67 | protected static function deactivate(DatabasePool $dbPool, ApplicationInfo $info) : void |
| 68 | { |
| 69 | $classPath = \substr(\realpath(static::PATH) . '/Status', \strlen(\realpath(__DIR__ . '/../../'))); |
| 70 | |
| 71 | $class = \strtr($classPath, '/', '\\'); |
| 72 | $class::deactivate($dbPool, $info); |
| 73 | }*/ |
| 74 | |
| 75 | /** |
| 76 | * Drop tables of app. |
| 77 | * |
| 78 | * @param DatabasePool $dbPool Database instance |
| 79 | * @param ApplicationInfo $info App info |
| 80 | * |
| 81 | * @return void |
| 82 | * |
| 83 | * @since 1.0.0 |
| 84 | */ |
| 85 | public static function dropTables(DatabasePool $dbPool, ApplicationInfo $info) : void |
| 86 | { |
| 87 | $path = static::PATH . '/Install/db.json'; |
| 88 | if (!\is_file($path)) { |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | $content = \file_get_contents($path); |
| 93 | if ($content === false) { |
| 94 | return; // @codeCoverageIgnore |
| 95 | } |
| 96 | |
| 97 | /** @var array<string, string> $definitions */ |
| 98 | $definitions = \json_decode($content, true); |
| 99 | $builder = new SchemaBuilder($dbPool->get('schema')); |
| 100 | |
| 101 | foreach ($definitions as $name => $definition) { |
| 102 | $builder->dropTable($name); |
| 103 | } |
| 104 | |
| 105 | $builder->execute(); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Unregister app from database. |
| 110 | * |
| 111 | * @param DatabasePool $dbPool Database instance |
| 112 | * @param ApplicationInfo $info App info |
| 113 | * |
| 114 | * @return void |
| 115 | * |
| 116 | * @since 1.0.0 |
| 117 | */ |
| 118 | public static function unregisterFromDatabase(DatabasePool $dbPool, ApplicationInfo $info) : void |
| 119 | { |
| 120 | $queryApp = new Builder($dbPool->get('delete')); |
| 121 | $queryApp->delete() |
| 122 | ->from('app') |
| 123 | ->where('app_name', '=', $info->getInternalName()) |
| 124 | ->execute(); |
| 125 | } |
| 126 | } |