diff --git a/admin.php b/admin.php index 6eafcc099..469acb469 100644 --- a/admin.php +++ b/admin.php @@ -29,6 +29,31 @@ check_status(ACCESS_ADMINISTRATOR); check_input_parameter('page', $_GET, false, '/^[a-zA-Z\d_-]+$/'); check_input_parameter('section', $_GET, false, '/^[a-z]+[a-z_\/-]*(\.php)?$/i'); +// +-----------------------------------------------------------------------+ +// | Filesystem checks | +// +-----------------------------------------------------------------------+ + +if ($conf['fs_quick_check_period'] > 0) +{ + $perform_fsqc = false; + if (isset($conf['fs_quick_check_last_check'])) + { + if (strtotime($conf['fs_quick_check_last_check']) < strtotime($conf['fs_quick_check_period'].' seconds ago')) + { + $perform_fsqc = true; + } + } + else + { + $perform_fsqc = true; + } + + if ($perform_fsqc) + { + fs_quick_check(); + } +} + // +-----------------------------------------------------------------------+ // | Direct actions | // +-----------------------------------------------------------------------+ diff --git a/admin/include/functions.php b/admin/include/functions.php index 0a310415b..654995856 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -3458,6 +3458,79 @@ function get_cache_size_derivatives($path) return $msizes; } +/** + * Displays a header warning if we find missing photos on a random sample. + * + * @since 13.4.0 + */ +function fs_quick_check() +{ + global $page, $conf; + + if ($conf['fs_quick_check_period'] == 0) + { + return; + } + + if (isset($page[__FUNCTION__.'_already_called'])) + { + return; + } + + $page[__FUNCTION__.'_already_called'] = true; + conf_update_param('fs_quick_check_last_check', date('c')); + + $query = ' +SELECT + id + FROM '.IMAGES_TABLE.' + WHERE date_available < \'2022-12-08 00:00:00\' + AND path LIKE \'./upload/%\' + LIMIT 5000 +;'; + $issue1827_ids = query2array($query, null, 'id'); + shuffle($issue1827_ids); + $issue1827_ids = array_slice($issue1827_ids, 0, 50); + + $query = ' +SELECT + id + FROM '.IMAGES_TABLE.' + LIMIT 5000 +;'; + $random_image_ids = query2array($query, null, 'id'); + shuffle($random_image_ids); + $random_image_ids = array_slice($random_image_ids, 0, 50); + + $fs_quick_check_ids = array_unique(array_merge($issue1827_ids, $random_image_ids)); + + $query = ' +SELECT + id, + path + FROM '.IMAGES_TABLE.' + WHERE id IN ('.implode(',', $fs_quick_check_ids).') +;'; + $fsqc_paths = query2array($query, 'id', 'path'); + + foreach ($fsqc_paths as $id => $path) + { + if (!file_exists($path)) + { + global $template; + + $template->assign( + 'header_msgs', + array( + l10n('Some photos are missing from your file system. Details provided by plugin Check Uploads'), + ) + ); + + return; + } + } +} + /** * Return news from piwigo.org. * diff --git a/admin/include/updates.class.php b/admin/include/updates.class.php index 934fde731..18ca8d7ca 100644 --- a/admin/include/updates.class.php +++ b/admin/include/updates.class.php @@ -552,6 +552,7 @@ class updates // changes. Anyway, a compiled template purge will be performed // by upgrade.php $template->delete_compiled_templates(); + conf_delete_param('fs_quick_check_last_check'); $page['infos'][] = l10n('Update Complete'); $page['infos'][] = $upgrade_to; diff --git a/admin/intro.php b/admin/intro.php index 4c7cf0d0d..3c1606a6a 100644 --- a/admin/intro.php +++ b/admin/intro.php @@ -73,6 +73,8 @@ if ($nb_orphans > 0) $page['warnings'][] = $message; } +fs_quick_check(); + // +-----------------------------------------------------------------------+ // | template init | // +-----------------------------------------------------------------------+ diff --git a/admin/maintenance_actions.php b/admin/maintenance_actions.php index 4ad1d550e..fa53c9ac8 100644 --- a/admin/maintenance_actions.php +++ b/admin/maintenance_actions.php @@ -6,6 +6,8 @@ // | file that was distributed with this source code. | // +-----------------------------------------------------------------------+ +fs_quick_check(); + // +-----------------------------------------------------------------------+ // | actions | // +-----------------------------------------------------------------------+ diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 8d135b14e..cba091535 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -280,6 +280,13 @@ $conf['stat_compare_year_displayed'] = 5; // Limit for linked albums search $conf['linked_album_search_limit'] = 100; +// how often should we check for missing photos in the filesystem. Only in the +// administration. Consider the fs_quick_check is always performed on +// dashboard and maintenance pages. This setting is only for any other +// administration page. +// 0 to disable. +$conf['fs_quick_check_period'] = 24*60*60; + // +-----------------------------------------------------------------------+ // | email | // +-----------------------------------------------------------------------+ diff --git a/language/en_UK/admin.lang.php b/language/en_UK/admin.lang.php index f96442345..3bbbd3e63 100644 --- a/language/en_UK/admin.lang.php +++ b/language/en_UK/admin.lang.php @@ -1325,4 +1325,5 @@ $lang['If anything bad happens during the update, you would be able to restore a $lang['Apply to root albums'] = 'Apply to root albums'; $lang['Album name must not be empty'] = 'Album name must not be empty'; $lang['Visit history'] = 'Visit history'; +$lang['Some photos are missing from your file system. Details provided by plugin Check Uploads'] = 'Some photos are missing from your file system. Details provided by plugin Check Uploads'; // Leave this line empty diff --git a/language/fr_FR/admin.lang.php b/language/fr_FR/admin.lang.php index c7c862ec1..ed991b996 100644 --- a/language/fr_FR/admin.lang.php +++ b/language/fr_FR/admin.lang.php @@ -1325,4 +1325,5 @@ $lang['If anything bad happens during the update, you would be able to restore a $lang['Apply to root albums'] = 'Appliquer aux albums racine'; $lang['Album name must not be empty'] = 'Le nom de l\'album ne doit pas être vide'; $lang['Visit history'] = 'Historique des visites'; +$lang['Some photos are missing from your file system. Details provided by plugin Check Uploads'] = 'Des photos sont absentes de votre système de fichier. À contrôler avec le plugin Check Uploads.'; // Leave this line empty