refactor: rename lib/ to core/ for clearer core-module separation
Rename the top-level lib/ directory to core/ so the project root immediately communicates which code is core platform and which lives in modules/. PHP namespaces (MintyPHP\*) are unchanged — only the Composer PSR-4 path mapping moves from lib/ to core/. Module-internal lib/ directories (modules/*/lib/) are untouched. Updated across the full stack: - composer.json PSR-4 mapping - bootstrap entry points (web/index.php, bin/*, tests/bootstrap.php) - tooling configs (phpstan.neon, phpunit.xml, php-cs-fixer) - 26 architecture contract tests - enforcement-policy, guard-catalog, quality-gates - all documentation (CLAUDE.md, README, 25 docs/, .agents/skills/) - bin/qa-extended.sh search paths - .claude/settings.local.json permission paths Workflow: .agents/runs/CORE-LIB-RENAME-001/ (Analyst → Planner → Executor → Code Review (4 findings fixed) → Security Review → Acceptance Test → Finalizer) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Service\Scheduler\Handler;
|
||||
|
||||
interface ScheduledJobHandlerInterface
|
||||
{
|
||||
/**
|
||||
* Returns the job definition (metadata + schedule defaults).
|
||||
*
|
||||
* The job_key is NOT included here – it is provided as the key in the
|
||||
* registry handler map in ScheduledJobRegistry.
|
||||
*
|
||||
* Required keys:
|
||||
* label (string) Human-readable name shown in admin UI.
|
||||
* description (string) Short description of what the job does.
|
||||
* default_enabled (int) 1 = enabled on first creation, 0 = disabled.
|
||||
* default_timezone (string) IANA timezone name (e.g. 'Europe/Berlin').
|
||||
* default_schedule_type (string) 'hourly'|'daily'|'weekly'
|
||||
* default_schedule_interval (int) 1..24 hourly / 1..365 daily / 1..52 weekly
|
||||
* default_schedule_time (string|null) 'HH:MM', required for daily and weekly.
|
||||
* default_schedule_weekdays_csv(string|null) CSV of ISO weekday numbers 1..7, weekly only.
|
||||
* default_catchup_once (int) 1 = catch up once after downtime (default).
|
||||
* allowed_schedule_types (array) Subset of ['hourly','daily','weekly'].
|
||||
*/
|
||||
public function definition(): array;
|
||||
|
||||
/**
|
||||
* Executes the job and returns a normalized result envelope.
|
||||
*
|
||||
* Implementations are responsible for:
|
||||
* - Calling the underlying service
|
||||
* - Mapping service results to the envelope format below
|
||||
* - Handling and wrapping service-level errors (e.g. lock_not_acquired → skipped)
|
||||
*
|
||||
* The result array content is job-specific and is JSON-encoded into the run log.
|
||||
* Keep values JSON-serializable (no objects, no resources).
|
||||
*
|
||||
* @param int|null $actorUserId Null for scheduler-triggered runs; user ID for manual runs.
|
||||
* @return array{status:string, error_code:?string, error_message:?string, result:array}
|
||||
* status: 'success'|'failed'|'skipped'
|
||||
* error_code: short machine-readable code, null on success
|
||||
* error_message: human-readable detail, null on success (max 255 chars)
|
||||
* result: job-specific payload, empty array if nothing to report
|
||||
*/
|
||||
public function execute(?int $actorUserId): array;
|
||||
}
|
||||
62
core/Service/Scheduler/Handler/UserLifecycleJobHandler.php
Normal file
62
core/Service/Scheduler/Handler/UserLifecycleJobHandler.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Service\Scheduler\Handler;
|
||||
|
||||
use MintyPHP\Service\User\UserLifecycleService;
|
||||
|
||||
class UserLifecycleJobHandler implements ScheduledJobHandlerInterface
|
||||
{
|
||||
public function __construct(private readonly UserLifecycleService $userLifecycleService)
|
||||
{
|
||||
}
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'label' => 'User lifecycle run',
|
||||
'description' => 'Runs automatic user deactivate/delete policy',
|
||||
'default_enabled' => 1,
|
||||
'default_timezone' => defined('APP_TIMEZONE') ? (string) APP_TIMEZONE : 'UTC',
|
||||
'default_schedule_type' => 'daily',
|
||||
'default_schedule_interval' => 1,
|
||||
'default_schedule_time' => '02:15',
|
||||
'default_schedule_weekdays_csv' => null,
|
||||
'default_catchup_once' => 1,
|
||||
'allowed_schedule_types' => ['hourly', 'daily', 'weekly'],
|
||||
];
|
||||
}
|
||||
|
||||
public function execute(?int $actorUserId): array
|
||||
{
|
||||
$result = $this->userLifecycleService->run($actorUserId !== null && $actorUserId > 0 ? $actorUserId : null);
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
$errorCode = (string) ($result['error'] ?? 'job_failed');
|
||||
$status = $errorCode === 'lock_not_acquired' ? 'skipped' : 'failed';
|
||||
return [
|
||||
'status' => $status,
|
||||
'error_code' => $errorCode,
|
||||
'error_message' => null,
|
||||
'result' => $this->formatResult($result),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'error_code' => null,
|
||||
'error_message' => null,
|
||||
'result' => $this->formatResult($result),
|
||||
];
|
||||
}
|
||||
|
||||
private function formatResult(array $result): array
|
||||
{
|
||||
return [
|
||||
'run_uuid' => (string) ($result['run_uuid'] ?? ''),
|
||||
'deactivated_count' => (int) ($result['deactivated_count'] ?? 0),
|
||||
'deleted_count' => (int) ($result['deleted_count'] ?? 0),
|
||||
'skipped_count' => (int) ($result['skipped_count'] ?? 0),
|
||||
'duration_ms' => (int) ($result['duration_ms'] ?? 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user