* Returns crypto job status used by UI/capabilities. * * If a job is recorded on this folder or an ancestor, descendants should treat it as active. * * @return array{active:bool,root:?string,job:?array} */
(string $folder)
| 189 | * @return array{active:bool,root:?string,job:?array} |
| 190 | */ |
| 191 | public static function getJobStatus(string $folder): array |
| 192 | { |
| 193 | $key = self::normalizeKey($folder); |
| 194 | $doc = self::load(); |
| 195 | $folders = $doc['folders'] ?? []; |
| 196 | if (!is_array($folders) || !$folders) { |
| 197 | return ['active' => false, 'root' => null, 'job' => null]; |
| 198 | } |
| 199 | |
| 200 | $f = $key; |
| 201 | while (true) { |
| 202 | $row = $folders[$f] ?? null; |
| 203 | if (is_array($row) && isset($row['job']) && is_array($row['job'])) { |
| 204 | $job = $row['job']; |
| 205 | $state = strtolower((string)($job['state'] ?? '')); |
| 206 | if ($state !== '' && $state !== 'done') { |
| 207 | return ['active' => true, 'root' => $f, 'job' => $job]; |
| 208 | } |
| 209 | } |
| 210 | if ($f === 'root' || $f === '') { |
| 211 | break; |
| 212 | } |
| 213 | $pos = strrpos($f, '/'); |
| 214 | $f = ($pos === false) ? 'root' : substr($f, 0, $pos); |
| 215 | if ($f === '') { |
| 216 | $f = 'root'; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | return ['active' => false, 'root' => null, 'job' => null]; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Attach/clear a v2 crypto job marker on the folder root. |
no test coverage detected