File_thumbnail fixes (run scripts/upgrade.php)

We're now capable of doing image rotation for thumbnails based on
EXIF orientation data. Also, thumbnails are tracked by filenames and
thus we can delete them from storage when we feel like it.
This commit is contained in:
Mikael Nordfeldth
2014-05-12 14:33:41 +02:00
parent cd3cff451f
commit 214a10ddec
4 changed files with 136 additions and 35 deletions

View File

@@ -44,6 +44,8 @@ function main()
initConversation();
fixupGroupURI();
fixupFileGeometry();
deleteLocalFileThumbnailsWithoutFilename();
deleteMissingLocalFileThumbnails();
initGroupProfileId();
initLocalGroup();
@@ -451,4 +453,55 @@ function fixupFileGeometry()
printfnq("DONE.\n");
}
/*
* File_thumbnail objects for local Files store their own filenames in the database.
*/
function deleteLocalFileThumbnailsWithoutFilename()
{
printfnq("Removing all local File_thumbnail entries without filename property...");
$file = new File();
$file->whereAdd('filename IS NOT NULL'); // local files
if ($file->find()) {
// Looping through local File entries
while ($file->fetch()) {
$thumbs = new File_thumbnail();
$thumbs->file_id = $file->id;
$thumbs->whereAdd('filename IS NULL');
// Checking if there were any File_thumbnail entries without filename
if (!$thumbs->find()) {
continue;
}
// deleting incomplete entry to allow regeneration
while ($thumbs->fetch()) {
$thumbs->delete();
}
}
}
printfnq("DONE.\n");
}
/*
* Delete File_thumbnail entries where the referenced file does not exist.
*/
function deleteMissingLocalFileThumbnails()
{
printfnq("Removing all local File_thumbnail entries without existing files...");
$thumbs = new File_thumbnail();
$thumbs->whereAdd('filename IS NOT NULL'); // only fill in names where they're missing
// Checking if there were any File_thumbnail entries without filename
if ($thumbs->find()) {
while ($thumbs->fetch()) {
if (!file_exists(File_thumbnail::path($thumbs->filename))) {
$thumbs->delete();
}
}
}
printfnq("DONE.\n");
}
main();