649 lines
20 KiB
PHP
649 lines
20 KiB
PHP
<?php
|
|
/**
|
|
* Copyright seit 2024 Webshop System
|
|
*
|
|
* Admin Controller für Repository-, Auto-Update- und Dependency-Management
|
|
*
|
|
* @author Webshop System
|
|
* @license GPL v3
|
|
*/
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\Core\ModuleRepository;
|
|
use App\Core\AutoUpdateSystem;
|
|
use App\Core\DependencyManager;
|
|
use App\Core\Logger;
|
|
use Doctrine\DBAL\DriverManager;
|
|
use Doctrine\DBAL\Exception;
|
|
|
|
class RepositoryController extends BaseAdminController
|
|
{
|
|
private $moduleRepository;
|
|
private $autoUpdateSystem;
|
|
private $dependencyManager;
|
|
private $logger;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->moduleRepository = ModuleRepository::getInstance();
|
|
$this->autoUpdateSystem = AutoUpdateSystem::getInstance();
|
|
$this->dependencyManager = DependencyManager::getInstance();
|
|
$this->logger = Logger::getInstance();
|
|
}
|
|
|
|
/**
|
|
* Repository-Übersicht anzeigen
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->checkPermission('repository_management');
|
|
|
|
$repositories = $this->moduleRepository->getRepositories();
|
|
$repositoryStats = $this->moduleRepository->getRepositoryStatistics();
|
|
$availableUpdates = $this->autoUpdateSystem->getAvailableUpdates();
|
|
|
|
$this->render('admin/repository/index', [
|
|
'repositories' => $repositories,
|
|
'repository_stats' => $repositoryStats,
|
|
'available_updates' => $availableUpdates,
|
|
'page_title' => 'Repository-Verwaltung'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Repository verwalten
|
|
*/
|
|
public function repositories()
|
|
{
|
|
$this->checkPermission('repository_management');
|
|
|
|
$action = $_GET['action'] ?? 'list';
|
|
|
|
switch ($action) {
|
|
case 'add':
|
|
$this->addRepository();
|
|
break;
|
|
case 'edit':
|
|
$this->editRepository();
|
|
break;
|
|
case 'delete':
|
|
$this->deleteRepository();
|
|
break;
|
|
case 'toggle':
|
|
$this->toggleRepository();
|
|
break;
|
|
default:
|
|
$this->listRepositories();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Repository-Liste anzeigen
|
|
*/
|
|
private function listRepositories()
|
|
{
|
|
$repositories = $this->moduleRepository->getRepositories();
|
|
$repositoryStats = $this->moduleRepository->getRepositoryStatistics();
|
|
|
|
$this->render('admin/repository/repositories', [
|
|
'repositories' => $repositories,
|
|
'repository_stats' => $repositoryStats,
|
|
'page_title' => 'Repository-Liste'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Repository hinzufügen
|
|
*/
|
|
private function addRepository()
|
|
{
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$id = $_POST['repository_id'] ?? '';
|
|
$name = $_POST['name'] ?? '';
|
|
$url = $_POST['url'] ?? '';
|
|
$type = $_POST['type'] ?? 'custom';
|
|
$enabled = isset($_POST['enabled']);
|
|
$priority = (int)($_POST['priority'] ?? 10);
|
|
|
|
if (empty($id) || empty($name) || empty($url)) {
|
|
$this->addError('Alle Felder sind erforderlich');
|
|
$this->redirect('/admin/repository/repositories');
|
|
return;
|
|
}
|
|
|
|
$config = [
|
|
'name' => $name,
|
|
'url' => $url,
|
|
'type' => $type,
|
|
'enabled' => $enabled,
|
|
'priority' => $priority
|
|
];
|
|
|
|
$this->moduleRepository->addRepository($id, $config);
|
|
|
|
$this->addSuccess('Repository erfolgreich hinzugefügt');
|
|
$this->redirect('/admin/repository/repositories');
|
|
} else {
|
|
$this->render('admin/repository/add_repository', [
|
|
'page_title' => 'Repository hinzufügen'
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Repository bearbeiten
|
|
*/
|
|
private function editRepository()
|
|
{
|
|
$repositoryId = $_GET['id'] ?? '';
|
|
|
|
if (empty($repositoryId)) {
|
|
$this->addError('Repository-ID ist erforderlich');
|
|
$this->redirect('/admin/repository/repositories');
|
|
return;
|
|
}
|
|
|
|
$repositories = $this->moduleRepository->getRepositories();
|
|
$repository = $repositories[$repositoryId] ?? null;
|
|
|
|
if (!$repository) {
|
|
$this->addError('Repository nicht gefunden');
|
|
$this->redirect('/admin/repository/repositories');
|
|
return;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$name = $_POST['name'] ?? '';
|
|
$url = $_POST['url'] ?? '';
|
|
$type = $_POST['type'] ?? 'custom';
|
|
$enabled = isset($_POST['enabled']);
|
|
$priority = (int)($_POST['priority'] ?? 10);
|
|
|
|
if (empty($name) || empty($url)) {
|
|
$this->addError('Name und URL sind erforderlich');
|
|
$this->redirect('/admin/repository/repositories');
|
|
return;
|
|
}
|
|
|
|
$config = [
|
|
'name' => $name,
|
|
'url' => $url,
|
|
'type' => $type,
|
|
'enabled' => $enabled,
|
|
'priority' => $priority
|
|
];
|
|
|
|
$this->moduleRepository->addRepository($repositoryId, $config);
|
|
|
|
$this->addSuccess('Repository erfolgreich aktualisiert');
|
|
$this->redirect('/admin/repository/repositories');
|
|
} else {
|
|
$this->render('admin/repository/edit_repository', [
|
|
'repository' => $repository,
|
|
'repository_id' => $repositoryId,
|
|
'page_title' => 'Repository bearbeiten'
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Repository löschen
|
|
*/
|
|
private function deleteRepository()
|
|
{
|
|
$repositoryId = $_GET['id'] ?? '';
|
|
|
|
if (empty($repositoryId)) {
|
|
$this->addError('Repository-ID ist erforderlich');
|
|
$this->redirect('/admin/repository/repositories');
|
|
return;
|
|
}
|
|
|
|
$this->moduleRepository->removeRepository($repositoryId);
|
|
|
|
$this->addSuccess('Repository erfolgreich entfernt');
|
|
$this->redirect('/admin/repository/repositories');
|
|
}
|
|
|
|
/**
|
|
* Repository aktivieren/deaktivieren
|
|
*/
|
|
private function toggleRepository()
|
|
{
|
|
$repositoryId = $_GET['id'] ?? '';
|
|
$enabled = $_GET['enabled'] ?? '0';
|
|
|
|
if (empty($repositoryId)) {
|
|
$this->addError('Repository-ID ist erforderlich');
|
|
$this->redirect('/admin/repository/repositories');
|
|
return;
|
|
}
|
|
|
|
$this->moduleRepository->setRepositoryEnabled($repositoryId, (bool)$enabled);
|
|
|
|
$status = $enabled ? 'aktiviert' : 'deaktiviert';
|
|
$this->addSuccess("Repository erfolgreich {$status}");
|
|
$this->redirect('/admin/repository/repositories');
|
|
}
|
|
|
|
/**
|
|
* Module aus Repository anzeigen
|
|
*/
|
|
public function repositoryModules()
|
|
{
|
|
$this->checkPermission('repository_management');
|
|
|
|
$repositoryId = $_GET['repository'] ?? 'official';
|
|
$filters = $_GET;
|
|
unset($filters['repository']);
|
|
|
|
$modules = $this->moduleRepository->getModulesFromRepository($repositoryId, $filters);
|
|
$repositories = $this->moduleRepository->getRepositories();
|
|
|
|
$this->render('admin/repository/modules', [
|
|
'modules' => $modules,
|
|
'repositories' => $repositories,
|
|
'current_repository' => $repositoryId,
|
|
'filters' => $filters,
|
|
'page_title' => 'Repository-Module'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Modul-Details anzeigen
|
|
*/
|
|
public function moduleDetails()
|
|
{
|
|
$this->checkPermission('repository_management');
|
|
|
|
$moduleName = $_GET['name'] ?? '';
|
|
$repositoryId = $_GET['repository'] ?? 'official';
|
|
|
|
if (empty($moduleName)) {
|
|
$this->addError('Modul-Name ist erforderlich');
|
|
$this->redirect('/admin/repository/modules');
|
|
return;
|
|
}
|
|
|
|
$moduleDetails = $this->moduleRepository->getModuleDetails($moduleName, $repositoryId);
|
|
|
|
if (!$moduleDetails) {
|
|
$this->addError('Modul nicht gefunden');
|
|
$this->redirect('/admin/repository/modules');
|
|
return;
|
|
}
|
|
|
|
$this->render('admin/repository/module_details', [
|
|
'module' => $moduleDetails,
|
|
'repository_id' => $repositoryId,
|
|
'page_title' => 'Modul-Details: ' . $moduleName
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Modul aus Repository installieren
|
|
*/
|
|
public function installModule()
|
|
{
|
|
$this->checkPermission('module_management');
|
|
|
|
$moduleName = $_POST['module_name'] ?? '';
|
|
$version = $_POST['version'] ?? null;
|
|
$repositoryId = $_POST['repository_id'] ?? 'official';
|
|
|
|
if (empty($moduleName)) {
|
|
$this->addError('Modul-Name ist erforderlich');
|
|
$this->redirect('/admin/repository/module-details?name=' . urlencode($moduleName) . '&repository=' . urlencode($repositoryId));
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$this->moduleRepository->installModuleFromRepository($moduleName, $version, $repositoryId);
|
|
|
|
$this->addSuccess('Modul erfolgreich installiert');
|
|
$this->redirect('/admin/modules');
|
|
|
|
} catch (\Exception $e) {
|
|
$this->addError('Installation fehlgeschlagen: ' . $e->getMessage());
|
|
$this->redirect('/admin/repository/module-details?name=' . urlencode($moduleName) . '&repository=' . urlencode($repositoryId));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Auto-Update verwalten
|
|
*/
|
|
public function autoUpdate()
|
|
{
|
|
$this->checkPermission('auto_update_management');
|
|
|
|
$action = $_GET['action'] ?? 'settings';
|
|
|
|
switch ($action) {
|
|
case 'check':
|
|
$this->checkForUpdates();
|
|
break;
|
|
case 'install':
|
|
$this->installUpdate();
|
|
break;
|
|
case 'history':
|
|
$this->updateHistory();
|
|
break;
|
|
default:
|
|
$this->updateSettings();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update-Einstellungen
|
|
*/
|
|
private function updateSettings()
|
|
{
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$enabled = isset($_POST['enabled']);
|
|
$checkInterval = (int)($_POST['check_interval'] ?? 86400);
|
|
$autoInstall = isset($_POST['auto_install']);
|
|
$notifyEmail = $_POST['notify_email'] ?? '';
|
|
|
|
$settings = [
|
|
'enabled' => $enabled ? '1' : '0',
|
|
'check_interval' => (string)$checkInterval,
|
|
'auto_install' => $autoInstall ? '1' : '0',
|
|
'notify_email' => $notifyEmail
|
|
];
|
|
|
|
$result = $this->autoUpdateSystem->saveSettings($settings);
|
|
|
|
if ($result) {
|
|
$this->addSuccess('Auto-Update-Einstellungen erfolgreich gespeichert');
|
|
} else {
|
|
$this->addError('Fehler beim Speichern der Einstellungen');
|
|
}
|
|
|
|
$this->redirect('/admin/repository/auto-update');
|
|
} else {
|
|
$availableUpdates = $this->autoUpdateSystem->getAvailableUpdates();
|
|
|
|
$this->render('admin/repository/auto_update_settings', [
|
|
'available_updates' => $availableUpdates,
|
|
'page_title' => 'Auto-Update-Einstellungen'
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update-Check durchführen
|
|
*/
|
|
private function checkForUpdates()
|
|
{
|
|
try {
|
|
$updates = $this->autoUpdateSystem->checkForUpdates();
|
|
|
|
if (!empty($updates)) {
|
|
$this->addSuccess(count($updates) . ' Updates gefunden');
|
|
} else {
|
|
$this->addSuccess('Keine Updates verfügbar');
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
$this->addError('Update-Check fehlgeschlagen: ' . $e->getMessage());
|
|
}
|
|
|
|
$this->redirect('/admin/repository/auto-update');
|
|
}
|
|
|
|
/**
|
|
* Update installieren
|
|
*/
|
|
private function installUpdate()
|
|
{
|
|
$moduleName = $_GET['module'] ?? '';
|
|
$version = $_GET['version'] ?? null;
|
|
|
|
if (empty($moduleName)) {
|
|
$this->addError('Modul-Name ist erforderlich');
|
|
$this->redirect('/admin/repository/auto-update');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$this->autoUpdateSystem->installUpdate($moduleName, $version);
|
|
|
|
$this->addSuccess('Update erfolgreich installiert');
|
|
|
|
} catch (\Exception $e) {
|
|
$this->addError('Update-Installation fehlgeschlagen: ' . $e->getMessage());
|
|
}
|
|
|
|
$this->redirect('/admin/repository/auto-update');
|
|
}
|
|
|
|
/**
|
|
* Update-Historie anzeigen
|
|
*/
|
|
private function updateHistory()
|
|
{
|
|
$moduleName = $_GET['module'] ?? null;
|
|
$history = $this->autoUpdateSystem->getUpdateHistory($moduleName);
|
|
|
|
$this->render('admin/repository/update_history', [
|
|
'history' => $history,
|
|
'module_name' => $moduleName,
|
|
'page_title' => 'Update-Historie'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Dependencies verwalten
|
|
*/
|
|
public function dependencies()
|
|
{
|
|
$this->checkPermission('dependency_management');
|
|
|
|
$action = $_GET['action'] ?? 'list';
|
|
|
|
switch ($action) {
|
|
case 'add':
|
|
$this->addDependency();
|
|
break;
|
|
case 'remove':
|
|
$this->removeDependency();
|
|
break;
|
|
case 'check':
|
|
$this->checkDependencies();
|
|
break;
|
|
case 'conflicts':
|
|
$this->checkConflicts();
|
|
break;
|
|
default:
|
|
$this->listDependencies();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Dependencies auflisten
|
|
*/
|
|
private function listDependencies()
|
|
{
|
|
$dependencyGraph = $this->dependencyManager->getDependencyGraph();
|
|
$conflictResolutions = $this->dependencyManager->getConflictResolutions();
|
|
|
|
$this->render('admin/repository/dependencies', [
|
|
'dependency_graph' => $dependencyGraph,
|
|
'conflict_resolutions' => $conflictResolutions,
|
|
'page_title' => 'Dependency-Management'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Dependency hinzufügen
|
|
*/
|
|
private function addDependency()
|
|
{
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$dependentName = $_POST['dependent_name'] ?? '';
|
|
$dependentType = $_POST['dependent_type'] ?? 'module';
|
|
$dependencyName = $_POST['dependency_name'] ?? '';
|
|
$dependencyType = $_POST['dependency_type'] ?? 'module';
|
|
$dependencyVersion = $_POST['dependency_version'] ?? null;
|
|
$required = isset($_POST['required']);
|
|
$priority = (int)($_POST['priority'] ?? 10);
|
|
|
|
if (empty($dependentName) || empty($dependencyName)) {
|
|
$this->addError('Abhängiger Name und Dependency-Name sind erforderlich');
|
|
$this->redirect('/admin/repository/dependencies');
|
|
return;
|
|
}
|
|
|
|
$result = $this->dependencyManager->addDependency(
|
|
$dependentName,
|
|
$dependentType,
|
|
$dependencyName,
|
|
$dependencyType,
|
|
$dependencyVersion,
|
|
$required,
|
|
$priority
|
|
);
|
|
|
|
if ($result) {
|
|
$this->addSuccess('Dependency erfolgreich hinzugefügt');
|
|
} else {
|
|
$this->addError('Fehler beim Hinzufügen der Dependency');
|
|
}
|
|
|
|
$this->redirect('/admin/repository/dependencies');
|
|
} else {
|
|
$this->render('admin/repository/add_dependency', [
|
|
'page_title' => 'Dependency hinzufügen'
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Dependency entfernen
|
|
*/
|
|
private function removeDependency()
|
|
{
|
|
$dependentName = $_GET['dependent_name'] ?? '';
|
|
$dependentType = $_GET['dependent_type'] ?? 'module';
|
|
$dependencyName = $_GET['dependency_name'] ?? '';
|
|
$dependencyType = $_GET['dependency_type'] ?? 'module';
|
|
|
|
if (empty($dependentName) || empty($dependencyName)) {
|
|
$this->addError('Abhängiger Name und Dependency-Name sind erforderlich');
|
|
$this->redirect('/admin/repository/dependencies');
|
|
return;
|
|
}
|
|
|
|
$result = $this->dependencyManager->removeDependency(
|
|
$dependentName,
|
|
$dependentType,
|
|
$dependencyName,
|
|
$dependencyType
|
|
);
|
|
|
|
if ($result) {
|
|
$this->addSuccess('Dependency erfolgreich entfernt');
|
|
} else {
|
|
$this->addError('Fehler beim Entfernen der Dependency');
|
|
}
|
|
|
|
$this->redirect('/admin/repository/dependencies');
|
|
}
|
|
|
|
/**
|
|
* Dependencies prüfen
|
|
*/
|
|
private function checkDependencies()
|
|
{
|
|
$itemName = $_GET['item_name'] ?? '';
|
|
$itemType = $_GET['item_type'] ?? 'module';
|
|
|
|
if (empty($itemName)) {
|
|
$this->addError('Item-Name ist erforderlich');
|
|
$this->redirect('/admin/repository/dependencies');
|
|
return;
|
|
}
|
|
|
|
$result = $this->dependencyManager->resolveDependencies($itemName, $itemType);
|
|
|
|
$this->render('admin/repository/dependency_check', [
|
|
'item_name' => $itemName,
|
|
'item_type' => $itemType,
|
|
'result' => $result,
|
|
'page_title' => 'Dependency-Prüfung'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Konflikte prüfen
|
|
*/
|
|
private function checkConflicts()
|
|
{
|
|
$itemName = $_GET['item_name'] ?? '';
|
|
$itemType = $_GET['item_type'] ?? 'module';
|
|
|
|
if (empty($itemName)) {
|
|
$this->addError('Item-Name ist erforderlich');
|
|
$this->redirect('/admin/repository/dependencies');
|
|
return;
|
|
}
|
|
|
|
$conflicts = $this->dependencyManager->checkConflicts($itemName, $itemType);
|
|
|
|
$this->render('admin/repository/conflict_check', [
|
|
'item_name' => $itemName,
|
|
'item_type' => $itemType,
|
|
'conflicts' => $conflicts,
|
|
'page_title' => 'Konflikt-Prüfung'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Repository-Status prüfen
|
|
*/
|
|
public function checkRepositoryStatus()
|
|
{
|
|
$this->checkPermission('repository_management');
|
|
|
|
$repositoryId = $_GET['id'] ?? '';
|
|
|
|
if (empty($repositoryId)) {
|
|
$this->addError('Repository-ID ist erforderlich');
|
|
$this->redirect('/admin/repository/repositories');
|
|
return;
|
|
}
|
|
|
|
$status = $this->moduleRepository->checkRepositoryStatus($repositoryId);
|
|
|
|
if ($status) {
|
|
$this->addSuccess('Repository ist erreichbar');
|
|
} else {
|
|
$this->addError('Repository ist nicht erreichbar');
|
|
}
|
|
|
|
$this->redirect('/admin/repository/repositories');
|
|
}
|
|
|
|
/**
|
|
* Cache invalidieren
|
|
*/
|
|
public function invalidateCache()
|
|
{
|
|
$this->checkPermission('repository_management');
|
|
|
|
$repositoryId = $_GET['id'] ?? null;
|
|
|
|
$this->moduleRepository->invalidateCache($repositoryId);
|
|
|
|
if ($repositoryId) {
|
|
$this->addSuccess("Cache für Repository '{$repositoryId}' invalidiert");
|
|
} else {
|
|
$this->addSuccess('Alle Repository-Caches invalidiert');
|
|
}
|
|
|
|
$this->redirect('/admin/repository');
|
|
}
|
|
}
|