Skip to content

Commit

Permalink
(cp 97b665d) issue #1827 new check on filesystem compared to what is …
Browse files Browse the repository at this point in the history
…listed in the database

While not fixing issue #1827 it helps users to detect if they have been
affected by the problem.
  • Loading branch information
plegall committed Dec 16, 2022
1 parent 6eda4f6 commit 5e002af
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 0 deletions.
25 changes: 25 additions & 0 deletions admin.php
Expand Up @@ -29,6 +29,31 @@
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 |
// +-----------------------------------------------------------------------+
Expand Down
73 changes: 73 additions & 0 deletions admin/include/functions.php
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions admin/include/updates.class.php
Expand Up @@ -552,6 +552,7 @@ static function upgrade_to($upgrade_to, &$step, $check_current_version=true)
// 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;
Expand Down
2 changes: 2 additions & 0 deletions admin/intro.php
Expand Up @@ -73,6 +73,8 @@
$page['warnings'][] = $message;
}

fs_quick_check();

// +-----------------------------------------------------------------------+
// | template init |
// +-----------------------------------------------------------------------+
Expand Down
2 changes: 2 additions & 0 deletions admin/maintenance_actions.php
Expand Up @@ -6,6 +6,8 @@
// | file that was distributed with this source code. |
// +-----------------------------------------------------------------------+

fs_quick_check();

// +-----------------------------------------------------------------------+
// | actions |
// +-----------------------------------------------------------------------+
Expand Down
7 changes: 7 additions & 0 deletions include/config_default.inc.php
Expand Up @@ -280,6 +280,13 @@
// 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 |
// +-----------------------------------------------------------------------+
Expand Down
1 change: 1 addition & 0 deletions language/en_UK/admin.lang.php
Expand Up @@ -1325,4 +1325,5 @@
$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
1 change: 1 addition & 0 deletions language/fr_FR/admin.lang.php
Expand Up @@ -1325,4 +1325,5 @@
$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

0 comments on commit 5e002af

Please sign in to comment.