X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fupgrade.php;h=2873146b3d90dce5e143cdc474acceb08890fdc4;hb=b53e1439969bfa2c0b551d8cc2fc8fe15652c62a;hp=c221a495af1cc04489643ce24bb3ce8a10bc1cd8;hpb=e7c6c6fc763ee94c34214f31980eabe83177a265;p=quix0rs-gnu-social.git diff --git a/scripts/upgrade.php b/scripts/upgrade.php index c221a495af..2873146b3d 100644 --- a/scripts/upgrade.php +++ b/scripts/upgrade.php @@ -29,7 +29,7 @@ Upgrade database schema and data to latest software END_OF_UPGRADE_HELP; -require_once INSTALLDIR.'/scripts/commandline.inc'; +require_once INSTALLDIR.'/scripts/commandline.inc.php'; function main() { @@ -48,6 +48,7 @@ function main() fixupFileGeometry(); deleteLocalFileThumbnailsWithoutFilename(); deleteMissingLocalFileThumbnails(); + setFilehashOnLocalFiles(); initGroupProfileId(); initLocalGroup(); @@ -490,7 +491,9 @@ function deleteMissingLocalFileThumbnails() // Checking if there were any File_thumbnail entries without filename if ($thumbs->find()) { while ($thumbs->fetch()) { - if (!file_exists(File_thumbnail::path($thumbs->filename))) { + try { + $thumbs->getPath(); + } catch (FileNotFoundException $e) { $thumbs->delete(); } } @@ -499,4 +502,30 @@ function deleteMissingLocalFileThumbnails() printfnq("DONE.\n"); } +/* + * Files are now stored with their hash, so let's generate for previously uploaded files. + */ +function setFilehashOnLocalFiles() +{ + printfnq('Ensuring all local files have the filehash field set...'); + + $file = new File(); + $file->whereAdd('filename IS NOT NULL'); // local files + $file->whereAdd('filehash IS NULL', 'AND'); // without filehash value + + if ($file->find()) { + while ($file->fetch()) { + try { + $orig = clone($file); + $file->filehash = hash_file(File::FILEHASH_ALG, $file->getPath()); + $file->update($orig); + } catch (FileNotFoundException $e) { + echo "\n WARNING: file ID {$file->id} does not exist on path '{$e->path}'. Clean up the file table?"; + } + } + } + + printfnq("DONE.\n"); +} + main();