mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-07-06 09:52:29 +02:00
Fixes #272 missing md5sum
* dashboard: add warning if missing checksums * add a "compute all missing md5sum" option in batch manager (inspired by delete orphans) * progress bar when computing md5sums
This commit is contained in:
+17
-1
@@ -79,8 +79,21 @@ DELETE FROM '.CADDIE_TABLE.'
|
||||
redirect(get_root_url().'admin.php?page='.$_GET['page']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ('sync_md5sum' == $_GET['action'] and isset($_GET['nb_md5sum_added']))
|
||||
{
|
||||
check_input_parameter('nb_md5sum_added', $_GET, false, '/^\d+$/');
|
||||
if ($_GET['nb_md5sum_added'] > 0)
|
||||
{
|
||||
$_SESSION['page_infos'][] = l10n_dec(
|
||||
'%d checksums were added', '%d checksums were added',
|
||||
$_GET['nb_md5sum_added']
|
||||
);
|
||||
|
||||
redirect(get_root_url().'admin.php?page='.$_GET['page']);
|
||||
}
|
||||
}
|
||||
}
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | initialize current set |
|
||||
// +-----------------------------------------------------------------------+
|
||||
@@ -369,6 +382,9 @@ SELECT id
|
||||
case 'no_album':
|
||||
$filter_sets[] = get_orphans();
|
||||
break;
|
||||
case 'no_sync_md5sum':
|
||||
$filter_sets[] = get_photos_no_md5sum();
|
||||
break;
|
||||
|
||||
case 'no_tag':
|
||||
$query = '
|
||||
|
||||
@@ -458,6 +458,7 @@ $prefilters = array(
|
||||
if ($conf['enable_synchronization'])
|
||||
{
|
||||
$prefilters[] = array('ID' => 'no_virtual_album', 'NAME' => l10n('With no virtual album'));
|
||||
$prefilters[] = array('ID' => 'no_sync_md5sum', 'NAME' => l10n('With no checksum'));
|
||||
}
|
||||
|
||||
$prefilters = trigger_change('get_batch_manager_prefilters', $prefilters);
|
||||
|
||||
@@ -2993,6 +2993,56 @@ SELECT CONCAT(
|
||||
return $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of image ids where md5sum is null
|
||||
*
|
||||
* @return int[] image_ids
|
||||
*/
|
||||
function get_photos_no_md5sum()
|
||||
{
|
||||
$query = '
|
||||
SELECT id
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE md5sum is null
|
||||
;';
|
||||
return query2array($query, null, 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute and add the md5sum of image ids (where md5sum is null)
|
||||
* @param int[] list of image ids and there paths
|
||||
* @return int number of md5sum added
|
||||
*/
|
||||
function add_md5sum($ids)
|
||||
{
|
||||
$query = '
|
||||
SELECT path
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE id IN ('.implode(', ',$ids).')
|
||||
;';
|
||||
$paths = query2array($query, null, 'path');
|
||||
$imgs_ids_paths = array_combine($ids, $paths);
|
||||
$updates = array();
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
$file = PHPWG_ROOT_PATH.$imgs_ids_paths[$id];
|
||||
$md5sum = md5_file($file);
|
||||
$updates[] = array(
|
||||
'id' => $id,
|
||||
'md5sum' => $md5sum,
|
||||
);
|
||||
}
|
||||
mass_updates(
|
||||
IMAGES_TABLE,
|
||||
array(
|
||||
'primary' => array('id'),
|
||||
'update' => array('md5sum')
|
||||
),
|
||||
$updates
|
||||
);
|
||||
return count($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of image ids associated to no album
|
||||
*
|
||||
|
||||
@@ -53,6 +53,28 @@ $tabsheet->assign();
|
||||
// | actions |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
||||
//check if images have no md5sum in database
|
||||
$query = '
|
||||
SELECT COUNT(*)
|
||||
FROM '.CATEGORIES_TABLE.'
|
||||
WHERE dir IS NOT NULL
|
||||
;';
|
||||
list($counter) = pwg_db_fetch_row(pwg_query($query));
|
||||
if ($counter > 0)
|
||||
{
|
||||
$query = '
|
||||
SELECT COUNT(*)
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE storage_category_id IS NOT NULL
|
||||
AND md5sum IS NULL
|
||||
;';
|
||||
list($counter) = pwg_db_fetch_row(pwg_query($query));
|
||||
if ($counter > 0)
|
||||
{
|
||||
$page['warnings'][] = '<a href="admin.php?page=batch_manager&filter=prefilter-no_sync_md5sum">'.l10n('Some checksums are missing.').'<i class="icon-right"></i></a>';
|
||||
}
|
||||
}
|
||||
|
||||
// Check for upgrade : code inspired from punbb
|
||||
if (isset($_GET['action']) and 'check_upgrade' == $_GET['action'])
|
||||
{
|
||||
|
||||
@@ -329,11 +329,58 @@ function progressDelete(val, max, success) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
jQuery("#action_delete input[name=confirm_deletion]").change(function() {
|
||||
jQuery("#action_delete span.errors").hide();
|
||||
});
|
||||
|
||||
jQuery('#sync_md5sum').click(function(e) {
|
||||
jQuery(this).hide();
|
||||
jQuery('#add_md5sum').show();
|
||||
|
||||
var addBlockSize = Math.min(
|
||||
Number((jQuery('#md5sum_to_add').data('origin') / 2).toFixed()),
|
||||
1000
|
||||
);
|
||||
add_md5sum_block(addBlockSize);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
function add_md5sum_block(blockSize){
|
||||
jQuery.ajax({
|
||||
url: "ws.php?format=json&method=pwg.images.setMd5sum",
|
||||
type:"POST",
|
||||
dataType: "json",
|
||||
data: {
|
||||
pwg_token: jQuery("input[name=pwg_token").val(),
|
||||
block_size: blockSize
|
||||
},
|
||||
success:function(data) {
|
||||
jQuery('#md5sum_to_add').html(data.result.nb_no_md5sum);
|
||||
|
||||
var percent_remaining = Number(
|
||||
(data.result.nb_no_md5sum * 100 / jQuery('#md5sum_to_add').data('origin')).toFixed()
|
||||
);
|
||||
var percent_done = 100 - percent_remaining;
|
||||
jQuery('#md5sum_added').html(percent_done);
|
||||
if (data.result.nb_no_md5sum > 0) {
|
||||
add_md5sum_block();
|
||||
}
|
||||
else {
|
||||
// time to refresh the whole page
|
||||
var redirect_to = 'admin.php?page=batch_manager';
|
||||
redirect_to += '&action=sync_md5sum';
|
||||
redirect_to += '&nb_md5sum_added='+jQuery('#md5sum_to_add').data('origin');
|
||||
|
||||
document.location = redirect_to;
|
||||
}
|
||||
},
|
||||
error:function(XMLHttpRequest) {
|
||||
jQuery('#add_md5sum').hide();
|
||||
jQuery('#add_md5sum_error').show().html('error '+XMLHttpRequest.status+' : '+XMLHttpRequest.statusText);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
jQuery('#delete_orphans').click(function(e) {
|
||||
jQuery(this).hide();
|
||||
@@ -384,4 +431,4 @@ function delete_orphans_block(blockSize) {
|
||||
jQuery('#orphans_deletion_error').show().html('error '+XMLHttpRequest.status+' : '+XMLHttpRequest.statusText);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,6 +275,7 @@ $(document).ready(function() {
|
||||
jQuery("#empty_caddie").toggle(jQuery(this).val() == "caddie");
|
||||
jQuery("#duplicates_options").toggle(jQuery(this).val() == "duplicates");
|
||||
jQuery("#delete_orphans").toggle(jQuery(this).val() == "no_album");
|
||||
jQuery("#sync_md5sum").toggle(jQuery(this).val() == "no_sync_md5sum");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -348,6 +349,18 @@ var sliders = {
|
||||
{if $NB_ORPHANS > 0}
|
||||
<a id="delete_orphans" href="#" style="{if !isset($filter.prefilter) or $filter.prefilter ne 'no_album'}display:none{/if}" class="icon-trash">{'Delete %d orphan photos'|translate:$NB_ORPHANS}</a>
|
||||
{/if}
|
||||
{if $NB_NO_MD5SUM > 0}
|
||||
<a id="sync_md5sum" href="#" style="{if !isset($filter.prefilter) or $filter.prefilter ne 'no_sync_md5sum'}display:none{/if}" class="icon-arrows-cw">{'Compute %d missing checksums'|translate:{$NB_NO_MD5SUM}}</a>
|
||||
{/if}
|
||||
|
||||
<span id="add_md5sum" style="display:none">
|
||||
<img class="loading" src="themes/default/images/ajax-loader-small.gif">
|
||||
<span id="md5sum_added">0</span>% -
|
||||
<span id="md5sum_to_add" data-origin="{$NB_NO_MD5SUM}">{$NB_NO_MD5SUM}</span>
|
||||
{'checksums to add'|translate}
|
||||
</span>
|
||||
|
||||
<span id="add_md5sum_error" class="errors" style="display:none"></span>
|
||||
|
||||
<span id="orphans_deletion" style="display:none">
|
||||
<img class="loading" src="themes/default/images/ajax-loader-small.gif">
|
||||
|
||||
Reference in New Issue
Block a user