## Summary - move the Laravel application into `apps/platform` and keep the repository root for orchestration, docs, and tooling - update the local command model, Sail/Docker wiring, runtime paths, and ignore rules around the new platform location - add relocation quickstart/contracts plus focused smoke coverage for bootstrap, command model, routes, and runtime behavior ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/PlatformRelocation` - integrated browser smoke validated `/up`, `/`, `/admin`, `/admin/choose-workspace`, and tenant route semantics for `200`, `403`, and `404` ## Remaining Rollout Checks - validate Dokploy build context and working-directory assumptions against the new `apps/platform` layout - confirm web, queue, and scheduler processes all start from the expected working directory in staging/production - verify no legacy volume mounts or asset-publish paths still point at the old root-level `public/` or `storage/` locations Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #213
89 lines
2.5 KiB
PHP
89 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\BackupScheduling;
|
|
|
|
use App\Models\BackupSchedule;
|
|
use Carbon\CarbonImmutable;
|
|
|
|
class ScheduleTimeService
|
|
{
|
|
public function nextRunFor(BackupSchedule $schedule, ?CarbonImmutable $after = null): ?CarbonImmutable
|
|
{
|
|
$timezone = $schedule->timezone;
|
|
$cursor = $after?->copy()->timezone($timezone) ?? CarbonImmutable::now($timezone);
|
|
|
|
if ($schedule->frequency === 'weekly') {
|
|
return $this->nextWeeklyRun($schedule, $cursor);
|
|
}
|
|
|
|
return $this->nextDailyRun($schedule, $cursor);
|
|
}
|
|
|
|
protected function nextDailyRun(BackupSchedule $schedule, CarbonImmutable $cursor): ?CarbonImmutable
|
|
{
|
|
$time = $schedule->time_of_day;
|
|
$attempts = 0;
|
|
|
|
if ($cursor->format('H:i:s') >= $time) {
|
|
$cursor = $cursor->addDay();
|
|
}
|
|
|
|
while ($attempts++ < 14) {
|
|
$candidate = $this->buildLocalSlot($schedule, $cursor);
|
|
|
|
if ($candidate) {
|
|
return $candidate;
|
|
}
|
|
|
|
$cursor = $cursor->addDay();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
protected function nextWeeklyRun(BackupSchedule $schedule, CarbonImmutable $cursor): ?CarbonImmutable
|
|
{
|
|
$allowed = $schedule->days_of_week ?? [];
|
|
$allowed = array_filter($allowed, fn ($day) => is_numeric($day) && $day >= 1 && $day <= 7);
|
|
$allowed = array_values($allowed);
|
|
|
|
if (empty($allowed)) {
|
|
return null;
|
|
}
|
|
|
|
$attempts = 0;
|
|
|
|
while ($attempts++ < 21) {
|
|
$dayOfWeek = $cursor->dayOfWeekIso;
|
|
|
|
if (in_array($dayOfWeek, $allowed, true)) {
|
|
$candidate = $this->buildLocalSlot($schedule, $cursor);
|
|
|
|
$cursorUtc = $cursor->copy()->timezone('UTC');
|
|
|
|
if ($candidate && $candidate->greaterThan($cursorUtc)) {
|
|
return $candidate;
|
|
}
|
|
}
|
|
|
|
$cursor = $cursor->addDay()->startOfDay();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
protected function buildLocalSlot(BackupSchedule $schedule, CarbonImmutable $date): ?CarbonImmutable
|
|
{
|
|
$timezone = $schedule->timezone;
|
|
$time = $schedule->time_of_day;
|
|
$datePart = $date->format('Y-m-d');
|
|
$candidate = CarbonImmutable::createFromFormat('Y-m-d H:i:s', "{$datePart} {$time}", $timezone);
|
|
|
|
if (! $candidate || $candidate->format('H:i:s') !== $time) {
|
|
return null;
|
|
}
|
|
|
|
return $candidate->startOfMinute()->timezone('UTC');
|
|
}
|
|
}
|