Created
November 16, 2016 10:49
-
-
Save cvonkleist/ec1308fd92e9298d2cf9299ca1843291 to your computer and use it in GitHub Desktop.
Archon regenerate thumbnails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
@include_once('patches.php'); // This has some custom patches for our Archon. | |
require_once('includes.inc.php'); | |
require_once("packages/digitallibrary/lib/file.inc.php"); | |
$query = "select id, length(FileContents) as fcsize, length(FilePreviewLong) as fplsize, length(FilePreviewShort) as fpssize from tblDigitalLibrary_Files where id=?"; // and (length(FileContents)=length(FilePreviewLong) or length(FileContents)=length(FilePreviewShort))"; | |
$prep = $_ARCHON->mdb2->prepare($query, array('integer'), MDB2_PREPARE_RESULT); | |
function needsResizing($id) { | |
global $prep; | |
$result = $prep->execute($id); | |
if(pear::isError($result)) { | |
echo("on ID $id: " . $result->getMessage() . "\n"); | |
return false; | |
} | |
$row = $result->fetchRow(); | |
$result->free(); | |
$fcsize = intval($row["fcsize"]); | |
$fplsize = intval($row["fplsize"]); | |
$fpssize = intval($row["fpssize"]); | |
// if image is smaller (width and height), long preview will be same as filecontents | |
// (see createImageThumbnail in Archon source) | |
return | |
(($fcsize == $fplsize) && ($fcsize == $fpssize)) // thumbnail data same (probably) as filecontents | |
|| | |
($fplsize == 0 || $fpssize == 0); // no thumbnail data | |
} | |
$report = fopen("regenerate_thumbnails_report.txt", "w"); | |
$arrDigitalContent = $_ARCHON->searchDigitalContent("", SEARCH_DIGITALCONTENT, 0, 0, 0, 0, 0, 0, 0, $Limit = 99999999); | |
foreach($arrDigitalContent as $ID => $objDigitalContent) { | |
if(!$objDigitalContent->Files) | |
$objDigitalContent->dbLoadFiles(); | |
foreach($objDigitalContent->Files as $ID => $objFile) { | |
//print_r($objFile); | |
if($objFile->FileType->FileType == 'JPEG Image') { | |
$nr = needsResizing($ID); | |
$nrt = $nr ? "true" : "false"; | |
printf("%s\t%s\n", $ID, $nrt); | |
fprintf($report, "%s\t%s\n", $ID, $nrt); | |
if ($nr) { | |
if (true) { | |
$objFile->dbLoad(); | |
$objFile->fopen(); | |
$objFile->FileContents = $objFile->fread(pow(2,32)); | |
$objFile->TempFileName = "/tmp/asdf"; | |
$fp = fopen($objFile->TempFileName, "w"); | |
fwrite($fp, $objFile->FileContents); | |
fclose($fp); | |
$objFile->dbStore(); | |
} | |
} | |
} else { | |
printf("%s\t(not a JPEG)\n", $ID, $nrt); | |
} | |
} | |
} | |
fclose($report); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment