( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
@mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$servername = "localhost";
$username = "root";
$password = "Pw4TheBrand!";
$dbname = "thebrand";
header('Content-Type: application/json');
$baseDir = __DIR__;
$convDir = $baseDir . '/v/uploads/converted';
if (!is_dir($convDir)) { @mkdir($convDir, 0777, true); }
// Basic local error logging for this verifier (optional)
$errorLogPath = $convDir . '/verify_php_errors.log';
@ini_set('log_errors','1');
@ini_set('error_log',$errorLogPath);
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
http_response_code(500);
echo json_encode(["success" => false, "message" => "db_connect_error"]);
exit;
}
$conn->set_charset("utf8");
$catalogid = 152;
$limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 5000;
if ($limit < 1) { $limit = 5000; }
$offset = isset($_GET['offset']) ? (int)$_GET['offset'] : 0;
if ($offset < 0) { $offset = 0; }
$q = "SELECT id, title FROM profilepicture WHERE catalogid = ? AND converted = 1 AND public = 1 AND is_deleted = 0 AND isdisplay = 13 AND comments = 'none' ORDER BY id DESC LIMIT ? OFFSET ?";
$stmt = $conn->prepare($q);
$stmt->bind_param("iii", $catalogid, $limit, $offset);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($themeid, $titleStr);
$updateStmt = $conn->prepare("UPDATE profilepicture SET comments = ? WHERE id = ?");
// Prepared statement to inspect layerorder content for reasons
$stmtLayers = $conn->prepare("SELECT layers3, layers2 FROM layerorder WHERE themeid = ? ORDER BY id DESC LIMIT 1");
$verified = 0;
$missing = 0;
$updates = [];
// We do not rely on transfer PHP errors or progress log; we infer from DB
// Buffer rows to avoid commands out of sync when running nested queries
$rows = [];
while ($stmt->fetch()) {
$rows[] = ['id' => (int)$themeid, 'title' => (string)$titleStr];
}
$stmt->free_result();
$stmt->close();
foreach ($rows as $row) {
$themeid = $row['id'];
$titleStr = $row['title'];
$basename = sha1($themeid . ':' . $titleStr);
$jsonPath = $convDir . '/' . $basename . '.json';
if (is_file($jsonPath) && filesize($jsonPath) > 2) {
$comment = 'verified';
$updateStmt->bind_param("si", $comment, $themeid);
$updateStmt->execute();
$verified++;
$updates[] = ["themeid" => $themeid, "status" => "verified", "file" => 'v/uploads/converted/' . $basename . '.json'];
} else {
// Determine reason by inspecting layerorder
$stmtLayers->bind_param("i", $themeid);
$stmtLayers->execute();
$stmtLayers->store_result();
$layers3 = null; $layers2 = null;
$stmtLayers->bind_result($layers3, $layers2);
$has = $stmtLayers->fetch();
$stmtLayers->free_result();
$lr = $has ? ['layers3' => $layers3, 'layers2' => $layers2] : null;
if (!$lr) {
$comment = 'no layer record';
} else {
$l3 = isset($lr['layers3']) ? trim((string)$lr['layers3']) : '';
$l2 = isset($lr['layers2']) ? trim((string)$lr['layers2']) : '';
if ($l3 === '' && $l2 === '') {
$comment = 'empty layers fields';
} else if ($l3 === '' && $l2 !== '') {
$d2 = json_decode($l2, true);
$comment = (json_last_error() !== JSON_ERROR_NONE) ? 'invalid json in layers2' : 'missing file';
} else if ($l3 !== '') {
$d3 = json_decode($l3, true);
$comment = (json_last_error() !== JSON_ERROR_NONE) ? 'invalid json in layers3' : 'missing file';
} else {
$comment = 'missing file';
}
}
$updateStmt->bind_param("si", $comment, $themeid);
$updateStmt->execute();
$missing++;
$updates[] = ["themeid" => $themeid, "status" => "missing", "reason" => $comment];
}
}
$updateStmt->close();
$stmtLayers->close();
$conn->close();
echo json_encode([
"success" => true,
"verified_count" => $verified,
"missing_count" => $missing,
"updates" => $updates
]);
?>