(array $job)
| 90 | } |
| 91 | |
| 92 | public static function create(array $job): array |
| 93 | { |
| 94 | self::ensureDirs(); |
| 95 | |
| 96 | $jobId = bin2hex(random_bytes(16)); |
| 97 | $now = time(); |
| 98 | $doc = array_merge([ |
| 99 | 'id' => $jobId, |
| 100 | 'status' => 'queued', |
| 101 | 'createdAt' => $now, |
| 102 | 'updatedAt' => $now, |
| 103 | 'startedAt' => null, |
| 104 | 'endedAt' => null, |
| 105 | 'cancelRequested' => false, |
| 106 | 'error' => null, |
| 107 | 'errors' => [], |
| 108 | 'current' => null, |
| 109 | 'phase' => 'queued', |
| 110 | 'pct' => 0, |
| 111 | 'filesDone' => 0, |
| 112 | 'bytesDone' => 0, |
| 113 | 'selectedFiles' => 0, |
| 114 | 'selectedBytes' => 0, |
| 115 | ], $job); |
| 116 | |
| 117 | $path = self::pathFor($jobId); |
| 118 | $ok = @file_put_contents($path, json_encode($doc, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), LOCK_EX); |
| 119 | if ($ok === false) { |
| 120 | throw new \RuntimeException('Failed to create transfer job.'); |
| 121 | } |
| 122 | @chmod($path, 0600); |
| 123 | return ['id' => $jobId, 'path' => $path, 'job' => $doc]; |
| 124 | } |
| 125 | |
| 126 | public static function listForUser(string $username, bool $isAdmin = false, int $limit = 50): array |
| 127 | { |
no test coverage detected