diff --git a/runtime/lib/piwigo-db-check.php b/runtime/lib/piwigo-db-check.php new file mode 100644 index 0000000..2e3d061 --- /dev/null +++ b/runtime/lib/piwigo-db-check.php @@ -0,0 +1,53 @@ + $target) { + if (str_starts_with((string) $source, 'share:') && !str_contains((string) $source, '/')) { + $expected[] = basename((string) $target); + } +} +if ($expected === []) { + exit(1); +} + +$conf = []; +$prefixeTable = ''; +require $databaseConfig; + +$database = new mysqli( + (string) $conf['db_host'], + (string) $conf['db_user'], + (string) $conf['db_password'], + (string) $conf['db_base'] +); +$database->set_charset('utf8mb4'); +$table = $database->real_escape_string((string) $prefixeTable) . 'categories'; +$result = $database->query( + 'SELECT dir FROM `' . $table . '` WHERE site_id = 1 AND dir IS NOT NULL' +); +$existing = []; +while ($row = $result->fetch_assoc()) { + $existing[(string) $row['dir']] = true; +} + +foreach ($expected as $directory) { + if (!isset($existing[$directory])) { + exit(1); + } +} +exit(0);