From: Alexander Sadleir Date: Sat, 17 Sep 2011 10:15:55 +0000 Subject: Add diagnostics to check integrity of data folder X-Git-Url: https://maxious.lambdacomplex.org/git/?p=photocalendar.git&a=commitdiff&h=43fdddd0dea802db94ca084342354b43cc7b5e48 --- Add diagnostics to check integrity of data folder --- --- a/common.inc.php +++ b/common.inc.php @@ -103,6 +103,15 @@ return false; } } +function getFirstDate() { + // not romance help + $datedFiles = scandir(DATA_DIR); // sorted descendingly by default + if (sizeof($datedFiles) > 2) {// always at least 2 even for an empty folder because of ./ and ../ + return getDateFromFilename($datedFiles[2]); + } else { + return false; + } +} function getPhoto($displayDate) { $cacheFile = CACHE_DIR . $displayDate . ".png"; @@ -149,7 +158,6 @@ } $date = strtotime($displayDate); -// First we create our bounding box for the first text $textDayName = date("l", $date); $sizeDayName = 24 + round(($source_image_height - 1000) / 1000) * 2; $fontDayName = "./img/mplus-1p-medium.ttf"; --- /dev/null +++ b/diagnostics.php @@ -1,1 +1,55 @@ +"; + } else if (sizeof($results) > 1) { + echo "Error on $currentDate, more than one photo found for that date:
"; + var_dump($results); + echo "
"; + } else { + // normal day + $fname = basename($results[0]); + $fnParts = explode(".", $fname); + if (sizeof($fnParts) < 3) { + echo "Error on $currentDate, malformed file name {$fname}
"; + } else { + if (strtotime($currentDate) != strtotime($fnParts[0])) { + echo "Error on $currentDate, file name {$fname} date does not match expected date
"; + } + if ($imgsize = getimagesize($results[0])) { + if ($imgsize[0] < MIN_IMAGE_SIZE || $imgsize[1] < MIN_IMAGE_SIZE || $imgsize[0] != $imgsize[1]) { + echo "Error on $currentDate, file name {$fname} is not large enough dimensions or non-square dimensions
"; + } + } else { + echo "Error on $currentDate, file name {$fname} could not be opened as an image file. File may have been corrupted
"; + } + $hash = md5_file($results[0]); + if ($hash != $fnParts[1]) { + echo "Error on $currentDate, file name {$fname} hash does not match expected hash. File may have been corrupted or altered
"; + } + if (in_array($hash, array_keys($hashes))) { + echo "Error on $currentDate, file {$fname} hash matches that of {$hashes[$hash]}. Files may be identitical duplicates of the same image
"; + } + $hashes[$hash] = $fname; + + if (sizeof($fnParts[2]) > 3 || ($fnParts[2] != "png" && $fnParts[2] != "jpg")) { + echo "Error on $currentDate, file name {$fname} extension unexpected
"; + } + } + } + + // go to next day + $currentDate = date("Y-m-d", strtotime("+1 day", strtotime($currentDate))); +} +echo "Scanned files from $firstDate to $currentDate, no errors detected
"; +?> +