freax-media/build_media_cache.php

35 lines
939 B
PHP
Raw Normal View History

<?php
declare(strict_types=1);
require_once __DIR__ . '/media_cache_lib.php';
if (PHP_SAPI !== 'cli') {
fwrite(STDERR, "build_media_cache.php must run in CLI mode\n");
exit(1);
}
$resolveError = null;
$baseDir = fm_resolve_media_root($resolveError);
if ($baseDir === null) {
fwrite(STDERR, ($resolveError ?? 'MEDIA_ROOT base directory not found') . PHP_EOL);
exit(1);
}
$exitCode = 0;
foreach (['videos', 'music'] as $type) {
$start = microtime(true);
$rebuildError = null;
$tree = fm_rebuild_cache($type, $baseDir, true, $rebuildError);
$durationMs = (int)round((microtime(true) - $start) * 1000);
if (!is_array($tree)) {
fwrite(STDERR, sprintf('[%s] cache rebuild failed: %s', $type, $rebuildError ?? 'unknown error') . PHP_EOL);
$exitCode = 1;
continue;
}
fwrite(STDOUT, sprintf('[%s] cache rebuilt in %dms', $type, $durationMs) . PHP_EOL);
}
exit($exitCode);