mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-07-04 00:42:20 +02:00
Merge branch 'feature/606-delete-orphans-by-block'
This commit is contained in:
@@ -64,17 +64,15 @@ DELETE FROM '.CADDIE_TABLE.'
|
||||
redirect(get_root_url().'admin.php?page='.$_GET['page']);
|
||||
}
|
||||
|
||||
if ('delete_orphans' == $_GET['action'])
|
||||
if ('delete_orphans' == $_GET['action'] and isset($_GET['nb_orphans_deleted']))
|
||||
{
|
||||
check_pwg_token();
|
||||
check_input_parameter('nb_orphans_deleted', $_GET, false, '/^\d+$/');
|
||||
|
||||
$deleted_count = delete_elements(get_orphans(), true);
|
||||
|
||||
if ($deleted_count > 0)
|
||||
if ($_GET['nb_orphans_deleted'] > 0)
|
||||
{
|
||||
$_SESSION['page_infos'][] = l10n_dec(
|
||||
'%d photo was deleted', '%d photos were deleted',
|
||||
$deleted_count
|
||||
$_GET['nb_orphans_deleted']
|
||||
);
|
||||
|
||||
redirect(get_root_url().'admin.php?page='.$_GET['page']);
|
||||
|
||||
@@ -2964,6 +2964,7 @@ SELECT
|
||||
FROM '.IMAGES_TABLE.'
|
||||
LEFT JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
|
||||
WHERE category_id is null
|
||||
ORDER BY id ASC
|
||||
;';
|
||||
|
||||
return query2array($query, null, 'id');
|
||||
|
||||
@@ -327,3 +327,53 @@ function progressDelete(val, max, success) {
|
||||
jQuery("#action_delete input[name=confirm_deletion]").change(function() {
|
||||
jQuery("#action_delete span.errors").hide();
|
||||
});
|
||||
|
||||
|
||||
jQuery('#delete_orphans').click(function(e) {
|
||||
jQuery(this).hide();
|
||||
jQuery('#orphans_deletion').show();
|
||||
|
||||
var deleteBlockSize = Math.min(
|
||||
Number((jQuery('#orphans_to_delete').data('origin') / 2).toFixed()),
|
||||
1000
|
||||
);
|
||||
|
||||
delete_orphans_block(deleteBlockSize);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
function delete_orphans_block(blockSize) {
|
||||
jQuery.ajax({
|
||||
url: "ws.php?format=json&method=pwg.images.deleteOrphans",
|
||||
type:"POST",
|
||||
dataType: "json",
|
||||
data: {
|
||||
pwg_token: jQuery("input[name=pwg_token").val(),
|
||||
block_size: blockSize
|
||||
},
|
||||
success:function(data) {
|
||||
jQuery('#orphans_to_delete').html(data.result.nb_orphans);
|
||||
|
||||
var percent_remaining = Number(
|
||||
(data.result.nb_orphans * 100 / jQuery('#orphans_to_delete').data('origin')).toFixed()
|
||||
);
|
||||
var percent_done = 100 - percent_remaining;
|
||||
jQuery('#orphans_deleted').html(percent_done);
|
||||
|
||||
if (data.result.nb_orphans > 0) {
|
||||
delete_orphans_block();
|
||||
}
|
||||
else {
|
||||
// time to refresh the whole page
|
||||
var redirect_to = 'admin.php?page=batch_manager';
|
||||
redirect_to += '&action=delete_orphans';
|
||||
redirect_to += '&nb_orphans_deleted='+jQuery('#orphans_to_delete').data('origin');
|
||||
|
||||
document.location = redirect_to;
|
||||
}
|
||||
},
|
||||
error:function(XMLHttpRequest, textStatus, errorThrows) {
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -345,7 +345,16 @@ var sliders = {
|
||||
{/foreach}
|
||||
</select>
|
||||
<a id="empty_caddie" href="admin.php?page=batch_manager&action=empty_caddie" style="{if !isset($filter.prefilter) or $filter.prefilter ne 'caddie'}display:none{/if}">{'Empty caddie'|translate}</a>
|
||||
<a id="delete_orphans" href="admin.php?page=batch_manager&action=delete_orphans&pwg_token={$PWG_TOKEN}" style="{if !isset($filter.prefilter) or $filter.prefilter ne 'no_album'}display:none{/if}">{'Delete %d orphan photos'|translate:$NB_ORPHANS}</a>
|
||||
{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}
|
||||
|
||||
<span id="orphans_deletion" style="display:none">
|
||||
<img class="loading" src="themes/default/images/ajax-loader-small.gif">
|
||||
<span id="orphans_deleted">0</span>% -
|
||||
<span id="orphans_to_delete" data-origin="{$NB_ORPHANS}">{$NB_ORPHANS}</span>
|
||||
{'orphans to delete'|translate}
|
||||
</span>
|
||||
|
||||
<span id="duplicates_options" style="{if !isset($filter.prefilter) or $filter.prefilter ne 'duplicates'}display:none{/if}">
|
||||
{'based on'|translate}
|
||||
|
||||
@@ -1762,4 +1762,22 @@ function ws_images_checkUpload($params, $service)
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* API method
|
||||
* Deletes orphan photos, by block. Returns how many orphans were deleted and how many are remaining.
|
||||
* @param mixed[] $params
|
||||
* @option int block_size
|
||||
*/
|
||||
function ws_images_deleteOrphans($params, $service)
|
||||
{
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
|
||||
$orphan_ids_to_delete = array_slice(get_orphans(), 0, $params['block_size']);
|
||||
$deleted_count = delete_elements($orphan_ids_to_delete, true);
|
||||
|
||||
return array(
|
||||
'nb_deleted' => $deleted_count,
|
||||
'nb_orphans' => count(get_orphans()),
|
||||
);
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -999,4 +999,5 @@ $lang['delete album and all %d photos, even the %d associated to other albums']
|
||||
$lang['delete album and the %d orphan photos'] = 'delete album and the %d orphan photos';
|
||||
$lang['delete only album, not photos'] = 'delete only album, not photos';
|
||||
$lang['Confirm deletion'] = 'Confirm deletion';
|
||||
$lang['checksum'] = 'checksum';
|
||||
$lang['checksum'] = 'checksum';
|
||||
$lang['orphans to delete'] = 'orphans to delete';
|
||||
@@ -1001,4 +1001,5 @@ $lang['delete album and all %d photos, even the %d associated to other albums']
|
||||
$lang['delete album and the %d orphan photos'] = 'supprimer l\'album et les %d photos orphelines';
|
||||
$lang['delete only album, not photos'] = 'supprimer uniquement l\'album, pas les photos';
|
||||
$lang['Confirm deletion'] = 'Confirmer la suppression';
|
||||
$lang['checksum'] = 'somme de contrôle';
|
||||
$lang['checksum'] = 'somme de contrôle';
|
||||
$lang['orphans to delete'] = 'orphelines à supprimer';
|
||||
@@ -510,6 +510,18 @@ function ws_addDefaultMethods( $arr )
|
||||
array('admin_only'=>true, 'post_only'=>true)
|
||||
);
|
||||
|
||||
$service->addMethod(
|
||||
'pwg.images.deleteOrphans',
|
||||
'ws_images_deleteOrphans',
|
||||
array(
|
||||
'block_size' => array('default'=>1000, 'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
|
||||
'pwg_token' => array(),
|
||||
),
|
||||
'Deletes orphans, by blocks. Returns how many orphans were deleted and how many are remaining.',
|
||||
$ws_functions_root . 'pwg.images.php',
|
||||
array('admin_only'=>true, 'post_only'=>true)
|
||||
);
|
||||
|
||||
$service->addMethod(
|
||||
'pwg.categories.getAdminList',
|
||||
'ws_categories_getAdminList',
|
||||
|
||||
Reference in New Issue
Block a user