Skip to content

Commit

Permalink
patch depends
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrayIterator committed Oct 19, 2023
1 parent d50e550 commit 3d3cb8d
Show file tree
Hide file tree
Showing 11 changed files with 394 additions and 41 deletions.
101 changes: 101 additions & 0 deletions Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
use ArrayAccess\TrayDigita\App\Modules\Core\SubModules\Templates\Templates;
use ArrayAccess\TrayDigita\App\Modules\Core\SubModules\Translator\Translator;
use ArrayAccess\TrayDigita\App\Modules\Media\Media;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\Admin;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\AdminLog;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\AdminMeta;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\AdminOnlineActivity;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\Attachment;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\Capability;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\Role;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\RoleCapability;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\User as UserEntity;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\UserAttachment;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\UserLog;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\UserMeta;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\UserOnlineActivity;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\UserTerm;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\UserTermGroup;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\UserTermGroupMeta;
use ArrayAccess\TrayDigita\App\Modules\Users\Entities\UserTermMeta;
use ArrayAccess\TrayDigita\App\Modules\Users\Users;
use ArrayAccess\TrayDigita\Benchmark\Aggregator\EventAggregator;
use ArrayAccess\TrayDigita\Benchmark\Injector\ManagerProfiler;
Expand All @@ -32,6 +49,7 @@
use ArrayAccess\TrayDigita\Util\Filter\Consolidation;
use ArrayAccess\TrayDigita\Util\Filter\ContainerHelper;
use ArrayAccess\TrayDigita\View\Interfaces\ViewInterface;
use Doctrine\DBAL\Exception;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use function class_exists;
use function strtolower;
Expand Down Expand Up @@ -81,6 +99,55 @@ final class Core extends AbstractModule
Translator::class,
];

const ENTITY_CHECKING = [
'required' => [
Entities\Option::class,
Entities\Post::class,
Entities\PostCategory::class,
Entities\PostMeta::class,
Entities\TaskScheduler::class,
Admin::class,
AdminLog::class,
AdminMeta::class,
AdminOnlineActivity::class,
Attachment::class,
Capability::class,
Role::class,
RoleCapability::class,
UserEntity::class,
UserAttachment::class,
UserLog::class,
UserMeta::class,
UserOnlineActivity::class,
UserTerm::class,
UserTermGroup::class,
UserTermGroupMeta::class,
UserTermMeta::class,
],
'optional' => [
Entities\Announcement::class,
Entities\Book::class,
Entities\BookAuthor::class,
Entities\BookCategory::class,
Entities\BookPublisher::class,
Entities\Classes::class,
Entities\ClassMeta::class,
Entities\Department::class,
Entities\DepartmentMeta::class,
Entities\Faculty::class,
Entities\FacultyMeta::class,
Entities\Question::class,
Entities\QuestionCategory::class,
Entities\Quiz::class,
],
'additional' => [
Entities\CacheItem::class,
Entities\LogItem::class,
Entities\Translation::class,
Entities\Site::class,
]
];

/**
* @var array<string, CoreSubmoduleAbstract>
*/
Expand Down Expand Up @@ -370,4 +437,38 @@ private function doInitSubModules($modules)
}
return $modules;
}

/**
* @var ?array
*/
private ?array $entityChecking = null;

/**
* @throws Exception
* @return array{
* required: array<string, bool>,
* optionsl: array<string, bool>,
* additional: array<string, bool>,
* tables: array<string, string>,
* }
*/
public function checkEntity(): array
{
if ($this->entityChecking !== null) {
return $this->entityChecking;
}
$schema = $this->getConnection()->createSchemaManager();
$em = $this->getConnection()->getEntityManager();
$schema = $schema->introspectSchema();
$this->entityChecking = [];
foreach (self::ENTITY_CHECKING as $type => $entities) {
$this->entityChecking[$type] = [];
foreach ($entities as $entity) {
$metadata = $em->getClassMetadata($entity);
$this->entityChecking[$type][$entity] = $schema->hasTable($metadata->getTableName());
$this->entityChecking['tables'][$entity] = $metadata->getTableName();
}
}
return $this->entityChecking;
}
}
48 changes: 48 additions & 0 deletions SubModules/ServiceInitializer/Controllers/RepairNeeded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);

namespace ArrayAccess\TrayDigita\App\Modules\Core\SubModules\ServiceInitializer\Controllers;

use ArrayAccess\TrayDigita\Http\Code;
use ArrayAccess\TrayDigita\Routing\Attributes\Any;
use ArrayAccess\TrayDigita\Routing\Attributes\Group;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use const PHP_INT_MIN;

#[Group('')]
class RepairNeeded extends AbstractServiceController
{
#[Any(
pattern: '/assets@core/(js|css|png|svg)/([^/]+\.\1)',
priority: PHP_INT_MIN + 9
)]
public function renderAssets(
ServerRequestInterface $request,
ResponseInterface $response,
array $params
): ResponseInterface {
return parent::renderAssets(
$request,
$response,
$params
);
}

#[Any(
pattern: '/.*',
priority: PHP_INT_MIN + 10
)]
public function any(
ServerRequestInterface $request,
ResponseInterface $response
) : ResponseInterface {
return $this->render(
'repair',
[
'request' => $request
],
$response
)->withStatus(Code::SERVICE_UNAVAILABLE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);

if (!isset($this, $kernel, $translator)) {
return;
}

use ArrayAccess\TrayDigita\Kernel\Interfaces\KernelInterface;
use ArrayAccess\TrayDigita\L10n\Translations\Interfaces\TranslatorInterface;
use ArrayAccess\TrayDigita\View\Engines\AbstractEngine;

// phpcs:disable Generic.Files.LineLength.TooLong
/**
* @var AbstractEngine $this
* @var array $parameters
* @var KernelInterface $kernel
* @var TranslatorInterface $translator
*/
?>
<div class="container">
<section id="install">
<h1 class="hero-title"><?= $translator->translateContext('Installation', 'installation', 'core-module');?></h1>
</section>
</div>
3 changes: 3 additions & 0 deletions SubModules/ServiceInitializer/Controllers/Views/install.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ $translator = $core->getTranslator();
case KernelInterface::CONFIG_NOT_ITERABLE:
require __DIR__ . '/contents/config-not-iterable.phtml';
break;
default:
require __DIR__ . '/contents/config-install.phtml';
break;
}
?>
</div>
Expand Down
53 changes: 53 additions & 0 deletions SubModules/ServiceInitializer/Controllers/Views/repair.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);

/**
* @var AbstractEngine $this
* @var array $parameters
*/
if (!isset($this)) {
return;
}

use ArrayAccess\TrayDigita\App\Modules\Core\Core;
use ArrayAccess\TrayDigita\Module\Modules;
use ArrayAccess\TrayDigita\Util\Filter\ContainerHelper;
use ArrayAccess\TrayDigita\View\Engines\AbstractEngine;

// phpcs:disable Generic.Files.LineLength.TooLong
$core = ContainerHelper::service(Modules::class, $this->getView()->getContainer())
->get(Core::class);
$entities = $core->checkEntity();
$tables = $entities['tables'];
$requiredModules = array_keys(array_filter($entities['required'], static fn($e) => $e === false));
?>
<!DOCTYPE html>
<html class="no-js" lang="<?= htmlspecialchars($parameters['language']??$core->getTranslator()?->getLanguage()??'en');?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex, nofollow, noodp, noydir, noarchive">
<title><?= htmlentities($core->translateContext('Incomplete Database Schema', 'module-not-found', 'core-module'));?></title>
<link rel="stylesheet" href="<?= $this->getView()->getBaseURI('assets@core/css/maintenance.css?v=1.0.0');?>" media="all">
</head>
<body>
<div id="page" class="page-wrapper">
<div class="container">
<h1 class="page-title">503</h1>
<h3 class="page-subtitle"><?=
$core->translateContext(
'Database schema are incomplete',
'incomplete-schema',
'core-module'
);
?></h3>
<ul class="module-list">
<?php foreach ($requiredModules as $module) {?>
<li><?= basename(str_replace('\\', '/', $module));?></li>
<?php } ?>

</ul>
</div>
</div>
</body>
</html>
9 changes: 9 additions & 0 deletions SubModules/ServiceInitializer/Middlewares/ErrorMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

namespace ArrayAccess\TrayDigita\App\Modules\Core\SubModules\ServiceInitializer\Middlewares;

use ArrayAccess\TrayDigita\App\Modules\Core\SubModules\ServiceInitializer\ServiceInitializer;
use ArrayAccess\TrayDigita\Middleware\ErrorMiddleware as CoreErrorMiddleware;
use Psr\Container\ContainerInterface;
use const PHP_INT_MAX;

class ErrorMiddleware extends CoreErrorMiddleware
Expand All @@ -12,4 +14,11 @@ class ErrorMiddleware extends CoreErrorMiddleware
* @var int set as highest priority
*/
protected int $priority = PHP_INT_MAX;

public function __construct(
ContainerInterface $container,
public readonly ServiceInitializer $serviceInitializer
) {
parent::__construct($container);
}
}
Loading

0 comments on commit 3d3cb8d

Please sign in to comment.