Bug 18300: Delete missing upload records
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Sun, 19 Mar 2017 16:25:01 +0000 (17:25 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 21 Apr 2017 00:11:39 +0000 (00:11 +0000)
commit8c80c9b8e127145e638963eb0eaa8fdb420ff4cd
treedba6564e4d86f5202b5a08c2e1b27d802a5fcaf8
parent1183cfff75773c4ac2acf8fb3386f2fd7f97d4ff
Bug 18300: Delete missing upload records

If you deleted files from the upload directories manually, or you rebooted
with files in the temporary upload folder, or for some other reason have
records without a file, you may want to cleanup your records in the
uploaded_files table.

This patch adds the method delete_missing to Koha::UploadedFiles. It also
supports a keep_record parameter to do a dry run (count the missing files
first).

Also, we add an option --uploads-missing to cleanup_database. If you add
the flag 1 after this option, you will delete missing files. If you add the
flag 0 or only use the option, you will count missing files.

A subtest is added to Upload.t for delete_missing tests.

Test plan:
[1] Run t/db_dependent/Upload.t
[2] Upload a file and delete the file manually.
[3] Run cleanup_database.pl --uploads-missing
    It should report at least one missing file now.
    Check that the record has not been deleted.
[4] Run cleanup_database.pl --uploads-missing 1
    It should report that it removed at least one file.
    Check that the record is gone.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Mirko Tietgen <mirko@abunchofthings.net>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Koha/UploadedFiles.pm
misc/cronjobs/cleanup_database.pl
t/db_dependent/Upload.t