Files
Wallos/endpoints/admin/deleteunusedlogos.php
Miguel Ribeiro aff3ed06b1 feat: add OIDC_REQUIRE_EMAIL_VERIFIED environment variable and SSRF_ALLOWLIST environment variable
feat: add Arabic localization
feat: add manual logo search box and png prioritization
fix: pin discord notification action to a commit sha
fix: service worker caching stale logo search results and broken images as logos
fix: ai recommendations not handling varied provider responses
fix: deleting orphaned logos not taking into account themed variants
fix: stats page not using themed logo variants
fix: email notification test rejecting non-admin users
fix: notification test/send requests hanging on unreachable hosts
fix: progress bar showing 100% when next payment is more than one cycle away
2026-07-18 23:33:40 +02:00

63 lines
1.5 KiB
PHP

<?php
require_once '../../includes/connect_endpoint.php';
require_once '../../includes/validate_endpoint_admin.php';
$query = 'SELECT logo, logo_variant FROM subscriptions';
$stmt = $db->prepare($query);
$result = $stmt->execute();
$logosOnDB = [];
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$logosOnDB[] = $row['logo'];
$logosOnDB[] = $row['logo_variant'];
}
$logosOnDB = array_unique($logosOnDB);
$uploadDir = '../../images/uploads/logos/';
$uploadFiles = scandir($uploadDir);
foreach ($uploadFiles as $file) {
if ($file != '.' && $file != '..' && $file != 'avatars') {
$logosOnDisk[] = ['logo' => $file];
}
}
// Get all logos in the payment_methods table
$query = 'SELECT icon FROM payment_methods';
$stmt = $db->prepare($query);
$result = $stmt->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
if (!strstr($row['icon'], "images/uploads/icons/")) {
$logosOnDB[] = $row['icon'];
}
}
$logosOnDB = array_unique($logosOnDB);
// Find and delete unused logos
$count = 0;
foreach ($logosOnDisk as $disk) {
$found = false;
foreach ($logosOnDB as $dbLogo) {
if ($disk['logo'] == $dbLogo) {
$found = true;
break;
}
}
if (!$found) {
unlink($uploadDir . $disk['logo']);
$count++;
}
}
echo json_encode([
"success" => true,
"message" => translate('success', $i18n),
'count' => $count
]);
?>