forked from fa/breadcrumb-the-shire
Existing systems used to have no automatic mechanism for the db/updates/*.sql idempotent updates after `git pull` — devs had to remember which files were already applied and run new ones manually with `mariadb < ...`. Mirror module:migrate to fix this: - New `bin/console db:migrate` walks db/updates/*.sql in alphabetical order, skipping anything already recorded in the new core_migrations tracking table. Each file runs in its own transaction; failure rolls back so the file is retried on the next run. - New `db:migrate --status` lists applied vs. pending files without running anything. Useful for ops debugging "schema seems stale" symptoms. - module:sync now runs db:migrate as its first step, so the standard post-pull command stays a single invocation. README's 3-step setup is unchanged — module:sync now also covers core schema updates. CoreMigrationRepository owns its own mysqli connection (using the same DB credentials as MintyPHP\DB) and runs raw `$mysqli->query()` instead of going through DB::query's prepared statement path — MariaDB rejects some DDL (e.g. ALTER TABLE … ADD CONSTRAINT CHECK) in the prepared protocol, which the existing 18 db/updates files trip on. ModuleMigrationRepository is left untouched (no module migration uses such DDL today and changing the vendor pattern is out of scope). End-to-end verified: against an existing DB the first run applies all 19 idempotent files as no-ops and records them, second run reports "all updates already applied". Against a freshly init'd DB the same thing happens — no double work, no surprises. All encrypted seed secrets keep decrypting because APP_CRYPTO_KEY is unchanged. Tests: tests/Console/CoreCommandsTest covers success/failure/status output shapes against a FakeModuleRunner (mirror of the existing ModuleCommandsTest pattern). 5 stale baseline entries in phpstan-baseline removed (covered by the new @api annotation on the test fixture class). Docs: CLAUDE.md and docs/reference-cli-commands.md document the new command + --status flag; docs/howto-fehlerbehebung.md gains a "schema seems stale after git pull" section pointing at db:migrate --status. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
105 lines
7.0 KiB
PHP
105 lines
7.0 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\App\Container\Registrars;
|
|
|
|
use MintyPHP\App\AppContainer;
|
|
use MintyPHP\App\Container\ContainerRegistrar;
|
|
use MintyPHP\App\Module\ModulePermissionSynchronizer;
|
|
use MintyPHP\App\Module\ModuleRegistry;
|
|
use MintyPHP\App\Module\ModuleRuntimeAssetPublisher;
|
|
use MintyPHP\App\Module\ModuleRuntimePageBuilder;
|
|
use MintyPHP\Http\CookieStore;
|
|
use MintyPHP\Http\CookieStoreInterface;
|
|
use MintyPHP\Http\Input\RequestInputFactory;
|
|
use MintyPHP\Http\IntendedUrlService;
|
|
use MintyPHP\Http\RequestRuntime;
|
|
use MintyPHP\Http\RequestRuntimeInterface;
|
|
use MintyPHP\Http\SessionStore;
|
|
use MintyPHP\Http\SessionStoreInterface;
|
|
use MintyPHP\Repository\Access\PermissionRepository;
|
|
use MintyPHP\Repository\Database\CoreMigrationRepository;
|
|
use MintyPHP\Repository\Database\CoreMigrationRepositoryInterface;
|
|
use MintyPHP\Repository\Module\ModuleMigrationRepository;
|
|
use MintyPHP\Repository\Search\SearchQueryRepository;
|
|
use MintyPHP\Repository\Stats\AdminStatsRepository;
|
|
use MintyPHP\Repository\System\SystemHealthRepository;
|
|
use MintyPHP\Repository\Tenant\UserTenantRepository;
|
|
use MintyPHP\Service\Access\PermissionService;
|
|
use MintyPHP\Service\CustomField\CustomFieldServicesFactory;
|
|
use MintyPHP\Service\CustomField\TenantCustomFieldService;
|
|
use MintyPHP\Service\CustomField\UserCustomFieldValueService;
|
|
use MintyPHP\Service\Data\GridUserCountEnricher;
|
|
use MintyPHP\Service\Database\CoreMigrationService;
|
|
use MintyPHP\Service\Import\ImportService;
|
|
use MintyPHP\Service\Import\ImportServicesFactory;
|
|
use MintyPHP\Service\Mail\MailLogService;
|
|
use MintyPHP\Service\Mail\MailService;
|
|
use MintyPHP\Service\Mail\MailServicesFactory;
|
|
use MintyPHP\Service\Module\ModuleMigrationService;
|
|
use MintyPHP\Service\Scheduler\ScheduledJobService;
|
|
use MintyPHP\Service\Scheduler\SchedulerRunService;
|
|
use MintyPHP\Service\Scheduler\SchedulerServicesFactory;
|
|
use MintyPHP\Service\Search\SearchDataService;
|
|
use MintyPHP\Service\Security\RateLimiterService;
|
|
use MintyPHP\Service\Security\SecurityServicesFactory;
|
|
use MintyPHP\Service\Stats\AdminStatsViewDataService;
|
|
use MintyPHP\Service\System\SystemHealthService;
|
|
|
|
final class AppServicesRegistrar implements ContainerRegistrar
|
|
{
|
|
public function register(AppContainer $container): void
|
|
{
|
|
$projectRoot = dirname(__DIR__, 4);
|
|
|
|
$container->set(AdminStatsViewDataService::class, static fn (AppContainer $c): AdminStatsViewDataService => new AdminStatsViewDataService(
|
|
$c->get(AdminStatsRepository::class)
|
|
));
|
|
$container->set(SystemHealthRepository::class, static fn (): SystemHealthRepository => new SystemHealthRepository());
|
|
$container->set(SystemHealthService::class, static fn (AppContainer $c): SystemHealthService => new SystemHealthService(
|
|
$c->get(SystemHealthRepository::class)
|
|
));
|
|
$container->set(SearchDataService::class, static fn (AppContainer $c): SearchDataService => new SearchDataService(
|
|
$c->get(PermissionService::class),
|
|
$c->get(UserTenantRepository::class),
|
|
$c->get(SearchQueryRepository::class)
|
|
));
|
|
$container->set(RateLimiterService::class, static fn (AppContainer $c): RateLimiterService => $c->get(SecurityServicesFactory::class)->createRateLimiterService());
|
|
$container->set(MailService::class, static fn (AppContainer $c): MailService => $c->get(MailServicesFactory::class)->createMailService());
|
|
$container->set(MailLogService::class, static fn (AppContainer $c): MailLogService => $c->get(MailServicesFactory::class)->createMailLogService());
|
|
// Audit services are registered by the audit module's AuditContainerRegistrar.
|
|
$container->set(ImportService::class, static fn (AppContainer $c): ImportService => $c->get(ImportServicesFactory::class)->createImportService());
|
|
$container->set(ScheduledJobService::class, static fn (AppContainer $c): ScheduledJobService => $c->get(SchedulerServicesFactory::class)->createScheduledJobService());
|
|
$container->set(SchedulerRunService::class, static fn (AppContainer $c): SchedulerRunService => $c->get(SchedulerServicesFactory::class)->createSchedulerRunService());
|
|
$container->set(TenantCustomFieldService::class, static fn (AppContainer $c): TenantCustomFieldService => $c->get(CustomFieldServicesFactory::class)->createTenantCustomFieldService());
|
|
$container->set(UserCustomFieldValueService::class, static fn (AppContainer $c): UserCustomFieldValueService => $c->get(CustomFieldServicesFactory::class)->createUserCustomFieldValueService());
|
|
// AuditMetadataEnricher is registered by the audit module's AuditContainerRegistrar.
|
|
$container->set(GridUserCountEnricher::class, static fn (): GridUserCountEnricher => new GridUserCountEnricher());
|
|
$container->set(IntendedUrlService::class, static fn (): IntendedUrlService => new IntendedUrlService());
|
|
$container->set(RequestInputFactory::class, static fn (): RequestInputFactory => new RequestInputFactory());
|
|
$container->set(SessionStore::class, static fn (): SessionStore => new SessionStore());
|
|
$container->set(SessionStoreInterface::class, static fn (AppContainer $c): SessionStoreInterface => $c->get(SessionStore::class));
|
|
$container->set(CookieStore::class, static fn (): CookieStore => new CookieStore());
|
|
$container->set(CookieStoreInterface::class, static fn (AppContainer $c): CookieStoreInterface => $c->get(CookieStore::class));
|
|
$container->set(RequestRuntime::class, static fn (): RequestRuntime => new RequestRuntime());
|
|
$container->set(RequestRuntimeInterface::class, static fn (AppContainer $c): RequestRuntimeInterface => $c->get(RequestRuntime::class));
|
|
$container->set(ModuleMigrationRepository::class, static fn (): ModuleMigrationRepository => new ModuleMigrationRepository());
|
|
$container->set(ModuleMigrationService::class, static fn (AppContainer $c): ModuleMigrationService => new ModuleMigrationService(
|
|
$c->get(ModuleRegistry::class),
|
|
$c->get(ModuleMigrationRepository::class)
|
|
));
|
|
$container->set(CoreMigrationRepository::class, static fn (): CoreMigrationRepository => new CoreMigrationRepository());
|
|
$container->set(CoreMigrationRepositoryInterface::class, static fn (AppContainer $c): CoreMigrationRepositoryInterface => $c->get(CoreMigrationRepository::class));
|
|
$container->set(CoreMigrationService::class, fn (AppContainer $c): CoreMigrationService => new CoreMigrationService(
|
|
$c->get(CoreMigrationRepositoryInterface::class),
|
|
$projectRoot . '/db/updates'
|
|
));
|
|
$container->set(ModulePermissionSynchronizer::class, fn (AppContainer $c): ModulePermissionSynchronizer => new ModulePermissionSynchronizer(
|
|
$c->get(ModuleRegistry::class),
|
|
$c->get(PermissionRepository::class),
|
|
$projectRoot . '/modules'
|
|
));
|
|
$container->set(ModuleRuntimePageBuilder::class, static fn (): ModuleRuntimePageBuilder => new ModuleRuntimePageBuilder());
|
|
$container->set(ModuleRuntimeAssetPublisher::class, static fn (): ModuleRuntimeAssetPublisher => new ModuleRuntimeAssetPublisher());
|
|
}
|
|
}
|