/** Datei: plugins/systems/library/ARUNOX/Plugins/Systems/Model.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Systems\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Users; class Routes { public static function register() : void { /* ### MAIN ROUTES ############################## # */ Router::addAll( Controller::class ); /* ### MENU ROUTES ############################## # */ Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { if( !Users\Model::isSuperadmin() ) return $routes; $routes[] = [ "path" => "/systems", "label" => "Systems", "icon" => "bi bi-gear-wide-connected", "menu" => "administration", ]; return $routes; }); } } /** Datei: plugins/systems/library/ARUNOX/Plugins/Systems/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Systems\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Systems; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static string $PLUGIN = "systems"; protected static array $NOTIFY = [ "notfound" => "System nicht gefunden", "saved" => "System wurde erfolgreich gespeichert", "deleted" => "System wurde erfolgreich gelöscht", "created" => "System wurde erfolgreich erstellt", "statuschanged.0" => "System wurde erfolgreich deaktiviert", "statuschanged.1" => "System wurde erfolgreich aktiviert", "notcreated" => "System konnte nicht erstellt werden", "notsaved" => "System konnte nicht gespeichert werden", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /systems * @route.description Listet alle Systeme */ public static function getAll() : array { return Systems\Model::getAll(); } /** * @api * @method GET * * @route.path /systems/{hashid}/plugins * @route.description Listet die Plugins eines Systems */ public static function getPlugins( int|string $hashid ) : array | HTTP\Response { if( $result = Systems\Model::get( $hashid ) ) return $result->getPlugins(); return REST\Response::jsonResponse( 404, static::$NOTIFY["notfound"] ); } /** * @api * @method GET * * @route.path /systems/{hashid} * @route.description Gibt Details zu einem bestimmten System zurück */ public static function get( int|string $hashid ) : BaseEntity | HTTP\Response { if( $result = Systems\Model::get( $hashid ) ) return $result; return REST\Response::jsonResponse( 404, static::$NOTIFY["notfound"] ); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ /** * @api * @method PUT * * @route.path /systems/{hashid} * @route.description Speichert Änderungen an einem System */ public static function save( int|string $hashid, array $data ) : HTTP\Response { if( $result = Systems\Model::get( $hashid ) ) { if( $result->save( $data ) ) { return REST\Response::jsonResponse( 200, static::$NOTIFY["saved"] ); } return REST\Response::jsonResponse( 500, static::$NOTIFY["notsaved"] ); } return REST\Response::jsonResponse( 404, static::$NOTIFY["notfound"] ); } /** * @api * @method POST * * @route.path /systems * @route.description Erstellt ein neues System */ public static function create( array $data ) : HTTP\Response { if( $hashid = Systems\Model::save( $data ) ) { $result = Systems\Model::get( $hashid ); return REST\Response::jsonResponse( 200, static::$NOTIFY["created"], [ "data" => $result ] ); } return REST\Response::jsonResponse( 500, static::$NOTIFY["notfound"] ); } /** * @api * @method DELETE * * @route.path /systems/{hashid} * @route.description Löscht ein System */ public static function delete( int|string $hashid ) : HTTP\Response { if( Systems\Model::delete( $hashid ) ) { return REST\Response::jsonResponse( 200, static::$NOTIFY["deleted"] ); } return REST\Response::jsonResponse( 500, static::$NOTIFY["notfound"] ); } /** * @api * @method PATCH * * @route.path /systems/{hashid}/status * @route.description Aktualisiert den Aktivitätsstatus eines Systems */ public static function toggleStatus( int|string $hashid ) : HTTP\Response { if( $result = Systems\Model::get( $hashid ) ) { $result->toggleStatus( TRUE ); return REST\Response::jsonResponse( 200, static::$NOTIFY["statuschanged.{$result->status->getValue()}"], [ "data" => $result ] ); } return REST\Response::jsonResponse( 404, static::$NOTIFY["notfound"] ); } /** * @api * @method PATCH * * @route.path /systems/{hashid}/db_status * @route.description Überprüft und setzt den Datenbankstatus eines Systems */ public static function resolveDBStatus( int|string $hashid ) : HTTP\Response { if( $result = Systems\Model::get( $hashid ) ) { $result->resolveDBStatus(); return REST\Response::jsonResponse( 200, static::$NOTIFY["statuschanged.{$result->status->getValue()}"], [ "data" => $result ] ); } return REST\Response::jsonResponse( 404, static::$NOTIFY["notfound"] ); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST FUNCTIONS #################################### # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ /** * @internal rest * @method PUT * * @route.path /systems/{hashid} * @route.description REST-Antwort nach dem Speichern eines Systems */ public static function restResponseSave( int|string $hashid, array $data ) : HTTP\Response { $result = static::save( $hashid, $data ); if( $result->isStatus( 200 ) ) { $data = Systems\Model::get( $hashid ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /** * @internal rest * @method POST * * @route.path /systems * @route.alternative.0 /systems/{hashid}#plugins * @route.description REST-Antwort nach dem Erstellen eines Systems */ public static function restResponseCreate( array $data ) : HTTP\Response { $result = static::create( $data ); if( $result->isStatus( 200 ) ) { REST\Response::closeModals(); REST\Response::redirect( "/systems" ); } return static::restResponse( $result ); } /** * @internal rest * @method DELETE * * @route.path /systems/{hashid} * @route.description REST-Antwort nach dem Löschen eines Systems */ public static function restResponseDelete( int|string $hashid ) : HTTP\Response { REST\Response::closeModals(); $result = static::delete( $hashid ); if( $result->isStatus( 200 ) ) { REST\Response::redirect( "/systems" ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /systems/{hashid}/status * @route.description REST-Antwort zur Statusänderung eines Systems */ public static function restResponseToggleStatus( int|string $hashid ) : HTTP\Response { $result = static::toggleStatus( $hashid ); if( $result->isStatus( 200 ) ) { $data = $result->getBody("data"); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /systems/{hashid}/db_status * @route.description REST-Antwort zur Aktualisierung des DB-Status eines Systems */ public static function restResponseResolveDBStatus( int|string $hashid ) : HTTP\Response { $result = static::resolveDBStatus( $hashid ); if( $result->isStatus( 200 ) ) { $data = $result->getBody("data"); $status = Systems\DBStatus::get( $data->db_status ); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); REST\Response::addNotify( $status["color"]->value, $status["label"], $status["icon"] ); return REST\Response::jsonResponse(); } return static::restResponse( $result ); } /* ### PUBLIC REST CONFIG FUNCTIONS ############################# # */ /** * @internal rest * @method GET * * @route.path /systems * @route.description REST-Konfiguration für System-Tabelle */ public static function restConfigOverview() : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "overview", "Systems" ) ->replaceContent( static::restConfigTable() ->setApi( "/systems" ) ->setAction( "/systems/{hashid}" ) ->getColumn() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "systems", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "systems", "hashid" )) ); } /** * @internal rest * @method GET * * @route.path /systems/{hashid} * @route.description REST-Konfiguration für Detailansicht eines Systems */ public static function restConfigDetails( int|string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "details", "System bearbeiten" ) ->setBacklink( "/systems" ) ->get() ->setApi( "/systems/{$hashid}" ) ->setAction( "/systems/{$hashid}", "PUT" ) ->addTab( "System" )->get() ->setActive( TRUE ) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "name", TRUE, "systems" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => Systems\Type::getAll(), ], "type", TRUE, FALSE, "systems" )) ->parent() ->addTab( "Plugins" )->get() ->addContent( Systems\Plugins\API\v1\Controller::restConfigTable( $hashid ?? 0 ) ) ->parent() ->addTab( "Speichern" )->get() ->setColor( REST\Generator\Config\Color::Primary ) ->setIcon( "bi bi-save" ) ->setType( "submit" ); } /** * @internal rest * @method GET * * @route.path /systems/create * @route.description REST-Formularkonfiguration für neue Systeme */ public static function restConfigCreate() : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "System erstellen" ) ->setData([ "id" => 0 ]) ->get() ->setAction( "/systems", "POST" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "systems" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "name", TRUE, "systems" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => Systems\Type::getAll(), ], "type", TRUE, FALSE, "systems" )) ->top(); } /** * @internal rest * @method GET * * @route.path /systems/{hashid}/delete * @route.description REST-Bestätigungsdialog zum Löschen eines Systems */ public static function restConfigDelete( int|string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "System Löschen" ) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/systems/{$hashid}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$hashid}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "systems" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "systems" )) ->top(); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTable( ?string $prefix = NULL ) : REST\Generator\Base\BaseGenerator { $plugin = static::getPluginName( $prefix ); return REST\Generator\Data\Table::create() ->setApi( $prefix ? $plugin : FALSE ) ->setOrder( "name", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], $plugin )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [], "status", [], $plugin )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ "icon" => "bi-diagram-3", "options" => Systems\Type::getAll(), ], "type", [], $plugin )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "label" => "Datenbank", "icon" => "bi-database-gear", "options" => Systems\DBStatus::getAll(), ], "db_status", [], $plugin )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "name", TRUE, TRUE, TRUE, $plugin )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "domain", TRUE, TRUE, TRUE, $plugin )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, $plugin )); } } /** Datei: plugins/systems/library/ARUNOX/Plugins/Systems/Type.php **/ [ "color" => REST\Generator\Config\Color::Danger, "label" => "Admin", "icon" => "bi bi-shield-lock-fill" ], 2 => [ "color" => REST\Generator\Config\Color::Warning, "label" => "Tenant shared", "icon" => "bi bi-layers-fill" ], 3 => [ "color" => REST\Generator\Config\Color::Success, "label" => "Tenant isolated", "icon" => "bi bi-boxes" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/systems/library/ARUNOX/Plugins/Systems/Plugins/Model.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Systems\Plugins\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Users; class Routes { public static function register() : void { /* ### MAIN ROUTES ############################## # */ Router::addAll( Controller::class ); } } /** Datei: plugins/systems/library/ARUNOX/Plugins/Systems/Plugins/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Systems\Plugins\API\v1; use ARUNOX\HTTP; use ARUNOX\API\PHP; use ARUNOX\Core\Hooks; use ARUNOX\API\Method; use ARUNOX\Core\Router; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Systems; use ARUNOX\Database\Attribute; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; #[PHP\Attributes\Controller\Label( "Plugin", "Plugins" )] #[PHP\Attributes\Database\Definitions\Model( Systems\Plugins\Model::class )] class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Plugin nicht gefunden", "saved" => "Plugin wurde erfolgreich gespeichert", "deleted" => "Plugin wurde erfolgreich gelöscht", "created" => "Plugin wurde erfolgreich erstellt", "statuschanged.0" => "Plugin wurde erfolgreich deaktiviert", "statuschanged.1" => "Plugin wurde erfolgreich aktiviert", "statuschanged.2" => "Plugin wurde als notwendig markiert", "notcreated" => "Plugin konnte nicht erstellt werden", "notsaved" => "Plugin konnte nicht gespeichert werden", "systemneeded" => "Plugin wird vom System benötigt", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /systems/plugins * @route.description Gibt eine Liste aller verfügbaren System-Plugins zurück */ public static function getAll() : array { return Systems\Plugins\Model::getAll([ "status" => "1", "system_id" => SYSTEM->id, ]); } /** * @api * @method GET * * @route.path /systems/plugins/routes * @route.description Gibt alle verfügbaren Routen der Plugins zurück */ public static function getAllRoutes() : array { $routes = Router::getRoutes(); $routes = array_filter( $routes, fn( $item ) => $item["method"] == Method::GET ); $routes = array_filter( $routes, fn( $item ) => $item["config"] ?? FALSE ); $routes = array_map( fn( $item ) => [ "name" => "{$item["method"]} {$item["path"]}", "method" => $item["method"], "route" => $item["path"], "api" => $item["config"]["api"] ?? $item["config"]["internal"] ?? FALSE, "link" => $item["config"]["route"]["link"] ?? false, "query" => $item["config"]["route"]["query"] ?? false, "alternatives" => $item["config"]["route"]["alternative"] ?? false, "description" => $item["config"]["route"]["description"], ], $routes ); // Aktualisiere Dich! Ich brauche keine Auswertung $routes = array_filter( $routes, fn( $item ) => $item["api"] ); // show( $rest ); // show( $routes ); return $routes; } /** * @api * @method GET * * @route.path /systems/plugins/{id} * @route.description Gibt die Details eines einzelnen System-Plugins zurück */ public static function get( int $id ) : BaseEntity | HTTP\Response { if( $result = Systems\Plugins\Model::get( $id ) ) return $result; return REST\Response::jsonResponse( 404, static::$NOTIFY["notfound"] ); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ /** * @api * @method PATCH * * @route.path /systems/plugins/{id}/status * @route.description Aktiviert oder deaktiviert ein Plugin (Status-Umschaltung) */ public static function toggleStatus( int $id ) : HTTP\Response { if( $result = Systems\Plugins\Model::get( $id ) ) { if( $result->system_need ) { return REST\Response::autoResponse( "409", static::$NOTIFY["systemneeded"] ); } $result->toggleStatus( TRUE ); return REST\Response::autoResponse( 200, static::$NOTIFY["statuschanged.{$result->status->getValue()}"], [ "data" => $result ] ); } return REST\Response::autoResponse( 404, static::$NOTIFY["notfound"] ); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ /** * @internal rest * @method PATCH * * @route.path /systems/plugins/{id}/status * @route.description Gibt die REST-Antwort zur Status-Umschaltung eines Plugins zurück (z. B. für Notifications) */ public static function restResponseToggleStatusPrepared( string $hashid ) : HTTP\Response { return parent::restResponseToggleStatusPrepared( $hashid ); } /* ### PUBLIC REST CONFIG FUNCTIONS ############################# # */ /** * @internal rest * @method GET * * @route.path /systems/plugins * @route.description Liefert die UI-Konfiguration für die Plugin-Tabelle im REST-Frontend */ public static function restConfigOverview() : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "overview", "Setting" ) ->get() ->setApi( "/systems/plugins" ) ->setAction( "/systems/plugins/{id}" ) ->setOrder( "plugin", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "plugin", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [], "type", [], "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "setting", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "systems/plugins" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "systems/plugins" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "systems/plugins" )) ->top(); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTable( int|string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Generator\Data\Table::create() ->setApi( "/api/v1/systems/{$hashid}/plugins" ) ->setOrder( "plugin", "asc" ) ->setSearch( TRUE ) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "options" => Systems\Plugins\Status::getAll(), ], "status", [], "systems/plugins", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ "icon" => "bi-lightning-charge-fill", "options" => Attribute\Status::getAll(), ], "preload", [], "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "plugin", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "description", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "version", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "author", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "dependencies", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", FALSE, FALSE, TRUE, "systems/plugins" )) ->top(); } } /** Datei: plugins/systems/library/ARUNOX/Plugins/Systems/Plugins/Entity.php **/ Status::class, "preload" => Attribute\Status::class, "date_create" => Attribute\DateTime::class, "date_edit" => Attribute\DateTime::class, "system_hashid" => "system->hashid", ]; /* ### PUBLIC FUNCTIONS ######################################### # */ public function toggleStatus( bool $save = FALSE ) { $this->status->toggle(); if( $save ) $this->save([ "status" => $this->status->getValue() ]); } public function getSystem() { if( $this->system_id ) { return Systems\Model::get( $this->system_id ); } return NULL; } public function getSchema() { return include "{$this->path}/config/schema/v{$this->fileVersion}.php"; } public function checkSchema( bool $onlyTables = FALSE ) { foreach( $this->schema as $table => $schema ) { if( !$this->db->existsTable( $table ) ) { return NULL; } if( $onlyTables ) continue; $current = $this->db->getSchema( $table ); if( $current !== $schema ) { return FALSE; } } return TRUE; } public function getSchemaIssues( ?Database $db = NULL ) { if( $db ) $this->setDB( $db ); $issues = []; foreach( $this->schema as $table => $schema ) { if( !$this->db->existsTable( $table ) ) { $issues[ $table ] = DBStatus::TablesMissing; continue; } $current = $this->db->getSchema( $table ); if( $current !== $schema ) { $issues[ $table ] = DBStatus::SchemaMismatch; } } return $issues; } public function repairSchema( ?Database $db = NULL ) { if( $db ) $this->setDB( $db ); $issues = $this->getSchemaIssues(); foreach( $issues as $table => &$issue ) { $schema = $this->getSchema(); if( $issue === DBStatus::TablesMissing ) { $issue = $this->db->installSchema( $schema ); } if( $issue === DBStatus::SchemaMismatch ) { $issue = $this->db->updateSchema( $schema ); } } $issues = array_filter( $issues, fn( $item ) => !is_bool( $item ) ); return !$issues; } public function installSchema() { } public function updateSchema() { } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### PRIVATE FUNCTIONS ######################################## # */ public function getDB() { return $this->db_conn ?? Connections::current(); } public function setDB( ?Database $db = NULL ) { return $this->db_conn = $db; } /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct() { $plugin = Core\Plugins::get( $this->plugin ); if( $plugin ) { $this->preload = (int)$plugin->preload; $this->path = $plugin->path; $this->author = $plugin->author; $this->fileVersion = $plugin->version; $this->description = $plugin->description; $this->dependencies = $plugin->dependencies; $this->system_need = FALSE; $this->system_show = TRUE; // if( $plugin->name == "cronjobs" ) show("X"); if( $plugin->system["only"] ?? FALSE ) { $types = preg_split( "/,|\s/", $plugin->system["need"] ); $types = array_map( "trim", $types ); $types = array_filter( $types ); $types = array_unique( $types ); $types = array_map( fn( $type ) => Systems\Type::getByConstant( $type ), $types ); $this->system_show = in_array( $this->system->type, $types ); // show( $this->system->type, $types, $plugin, $this ); } if( $plugin->system["need"] ?? FALSE ) { if( strtoupper( $plugin->system["need"] ) != "ALL" ) { $types = preg_split( "/,|\s/", $plugin->system["need"] ); $types = array_map( "trim", $types ); $types = array_filter( $types ); $types = array_unique( $types ); $types = array_map( fn( $type ) => Systems\Type::getByConstant( $type ), $types ); } else $types = array_column( Systems\Type::getAll(), "value" ); $this->system_need = in_array( $this->system->type, $types ); // if( $plugin->name == "logs" ) show( $this->system->type, $types ); // show( $this->system->type, $types, $plugin, $this ); } // if( $plugin->name == "logs" ) show( $this ); } // show( $plugin, $this ); } } /** Datei: plugins/systems/library/ARUNOX/Plugins/Systems/Plugins/Status.php **/ [ "color" => "info", "label" => "Mandatory", "icon" => "bi bi-shield-lock" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( mixed $value, $parent = NULL ) { static::$OPTIONS = array_replace( parent::$OPTIONS, static::$OPTIONS ); parent::__construct( $value, $parent ); } } /** Datei: plugins/systems/library/ARUNOX/Plugins/Systems/DBStatus.php **/ [ "color" => REST\Generator\Config\Color::Danger, "label" => "Datenbank fehlt", "icon" => "bi bi-database-x" ], 1 => [ "color" => REST\Generator\Config\Color::Danger, "label" => "Tabellen fehlen", "icon" => "bi bi-exclamation-triangle" ], 2 => [ "color" => REST\Generator\Config\Color::Danger, "label" => "Schema fehlerhaft", "icon" => "bi bi-hourglass-split" ], 3 => [ "color" => REST\Generator\Config\Color::Danger, "label" => "Fehler aufgetreten", "icon" => "bi bi-x-octagon" ], 4 => [ "color" => REST\Generator\Config\Color::Info, "label" => "Installiere…", "icon" => "bi bi-arrow-repeat" ], 5 => [ "color" => REST\Generator\Config\Color::Warning, "label" => "In Wartung", "icon" => "bi bi-tools" ], 6 => [ "color" => REST\Generator\Config\Color::Default, "label" => "Administrator fehlt", "icon" => "bi bi-person-x" ], 7 => [ "color" => REST\Generator\Config\Color::Success, "label" => "System lauffähig", "icon" => "bi bi-check-circle" ], 8 => [ "color" => REST\Generator\Config\Color::Light, "label" => "Via Tenant", "icon" => "bi bi-suitcase-lg" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/systems/library/ARUNOX/Plugins/Systems/Entity.php **/ Type::class, "db_status" => DBStatus::class, "status" => Attribute\Status::class, "date_create" => Attribute\DateTime::class, "date_edit" => Attribute\DateTime::class, ]; /* ### PUBLIC FUNCTIONS ######################################### # */ public function connect( ?string $db_name = NULL ) : Database { if( $this->db_name || $db_name ) { $this->db_conn = Connections::connect([ "host" => DB_HOST, "dbname" => $this->db_name ?? $db_name, "charset" => DB_CHARSET, "user" => DB_USER, "pass" => DB_PASS, ], "system", TRUE ); } return Connections::switch(); } public function toggleStatus( bool $save = FALSE ) { $this->status->toggle(); if( $save ) $this->save(); } public function checkDBStatus( ?BaseEntity $entity = NULL ) : bool { $entity = $this->getEntity( $entity ); if( SYSTEM->type->isAdmin() ) { if( SYSTEM->id == $this->id ) { $entity->save(["db_status" => DBStatus::Ok ]); return TRUE; } if( $entity->type->isTenantIsolated() && !$entity->tenant_id ) { $entity->save(["db_status" => DBStatus::ByTenant ]); return TRUE; } } if( !$entity->db_name ) { $entity->save(["db_status" => DBStatus::Missing ]); return FALSE; } if( !Database::existsDatabase( $entity->db_name ) ) { $entity->save(["db_status" => DBStatus::Missing ]); return FALSE; } $entity->connect(); $plugins = $entity->getPlugins( TRUE ); foreach( $plugins as $plugin ) { $plugin->db_conn = $entity->db_conn; $result = $plugin->checkSchema(); if( $result === NULL ) $entity->save(["db_status" => DBStatus::TablesMissing ]); if( $result === FALSE ) $entity->save(["db_status" => DBStatus::SchemaMismatch ]); if( $result !== TRUE ) return FALSE; } if( $this->type->isTenantShared() ) { Connections::switch("system"); $users = Users\Model::getCount([ "role" => Users\Role::Admin, "status" => Attribute\Status::Active, "tenant_id__meta" => $entity->tenant_id, ]); Connections::switch(); if( !$users ) $entity->save(["db_status" => DBStatus::AdminMissing ]); else $entity->save(["db_status" => DBStatus::Ok ]); } if( $this->type->isTenantIsolated() ) { if( get_class( $entity ) !== get_class( $this ) ) { $entity->save(["db_status" => DBStatus::AdminMissing ]); //$entity->save(["db_status" => DBStatus::Ok ]); } else $entity->save(["db_status" => DBStatus::ByTenant ]); } return TRUE; } public function resolveDBStatus( ?BaseEntity $entity = NULL ) : bool|string { $entity = $this->getEntity( $entity ); $this->checkDBStatus( $entity ); if( $entity->type->isTenantIsolated() && !$entity->tenant_id ) return TRUE; if( $entity->db_status->isOk() ) return TRUE; if( !$entity->db_name || $entity->db_status->isMissing() || !Database::existsDatabase( $entity->db_name ) ) { $entity->save(["db_status" => DBStatus::Missing ]); return FALSE; } $plugins = $entity->getPlugins( TRUE ); $entity->connect(); foreach( $plugins as $plugin ) { if( !$plugin->repairSchema( $entity->db_conn ) ) { $entity->save(["db_status" => DBStatus::Failed ]); return FALSE; } } $entity->save(["db_status" => DBStatus::Ok ]); return TRUE; } public function setDBName( string $db_name ) { $this->db_name = $db_name; } public function getPlugins( bool $onlyActive = FALSE ) { $allPlugins = Core\Plugins::getAll(); foreach( $allPlugins as $name => $plugin ) { $check = Plugins\Model::get([ "system_id" => $this->id, "plugin" => $name, ]); if( $check ) { if( !$check->system_show && $check->status->isInactive() ) { $check->status = Plugins\Status::Inactive; $check->save(); } if( $check->system_need && !$check->status->isMandatory() ) { $check->status = Plugins\Status::Mandatory; $check->save(); } continue; } Plugins\Model::save([ "plugin" => $name, "system_id" => $this->id, ]); } $plugins = Plugins\Model::getAll([ "system_id" => $this->id ]); $plugins = array_filter( $plugins, fn( $item ) => $item->system_show ); if( $onlyActive ) { $plugins = array_filter( $plugins, fn( $item ) => $item->status->isActive() ); } $plugins = array_values( $plugins ); return $plugins; } /* ### PRIVATE FUNCTIONS ######################################## # */ private function getEntity( ?BaseEntity $entity = NULL ) : BaseEntity { if( !$this->type->isTenantIsolated() || !$entity ) { if( $entity ) $this->tenant_id = $entity->tenant_id; $entity = $this; } return $entity; } /* ### MAGIC FUNCTIONS ########################################## # */ }