attendance['timezone'] ?? 'America/New_York'); $timezone = new \DateTimeZone($tzName); $dateOption = CLI::getOption('date'); $date = $dateOption ? new \DateTimeImmutable((string) $dateOption, $timezone) : new \DateTimeImmutable('today', $timezone); $force = CLI::getOption('force') !== null; $dryRun = CLI::getOption('dry-run') !== null; $email = CLI::getOption('email'); $email = is_string($email) && trim($email) !== '' ? trim($email) : null; if ($email !== null && ! filter_var($email, FILTER_VALIDATE_EMAIL)) { CLI::error('Invalid --email value.'); return; } $service = service('enrollmentRegistrationEmail'); $summary = $service->sendForDate($date, $force, $email, $dryRun); foreach ($summary['messages'] as $message) { CLI::write($message, 'yellow'); } $sentLabel = $dryRun ? 'Would send' : 'Sent'; CLI::write(sprintf( 'Registration opening email complete. Years: %d. Recipients: %d. %s: %d. Failed: %d. Skipped: %d%s.', $summary['school_years'], $summary['recipients'], $sentLabel, $summary['sent'], $summary['failed'], $summary['skipped'], $dryRun ? ' (dry run)' : '' ), $summary['failed'] > 0 ? 'red' : 'green'); } }