mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-03-28 17:42:57 +01:00
related to #1381 changed name of the api function that calculates orphans
This commit is contained in:
@@ -106,7 +106,7 @@ jQuery(document).ready(function() {
|
||||
|
||||
$(".deleteAlbum").on("click", function() {
|
||||
$.ajax({
|
||||
url: "ws.php?format=json&method=pwg.images.calculateOrphansOnAlbumDeletion",
|
||||
url: "ws.php?format=json&method=pwg.categories.calculateOrphans",
|
||||
type: "GET",
|
||||
data: {
|
||||
category_id: {$CAT_ID},
|
||||
|
||||
@@ -1054,4 +1054,115 @@ SELECT id, name, dir
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API method
|
||||
* Return the number of orphan photos if an album is deleted
|
||||
*/
|
||||
|
||||
function ws_categories_calculateOrphans($param, &$service)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$category_id = $param['category_id'][0];
|
||||
|
||||
$query = '
|
||||
SELECT DISTINCT
|
||||
category_id
|
||||
FROM
|
||||
'.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE
|
||||
category_id = '.$category_id.'
|
||||
LIMIT 1';
|
||||
$result = pwg_query($query);
|
||||
$category['has_images'] = pwg_db_num_rows($result)>0 ? true : false;
|
||||
|
||||
// number of sub-categories
|
||||
$subcat_ids = get_subcat_ids(array($category_id));
|
||||
|
||||
$category['nb_subcats'] = count($subcat_ids) - 1;
|
||||
|
||||
// total number of images under this category (including sub-categories)
|
||||
$query = '
|
||||
SELECT DISTINCT
|
||||
(image_id)
|
||||
FROM
|
||||
'.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE
|
||||
category_id IN ('.implode(',', $subcat_ids).')
|
||||
;';
|
||||
$image_ids_recursive = query2array($query, null, 'image_id');
|
||||
|
||||
$category['nb_images_recursive'] = count($image_ids_recursive);
|
||||
|
||||
// number of images that would become orphan on album deletion
|
||||
$category['nb_images_becoming_orphan'] = 0;
|
||||
$category['nb_images_associated_outside'] = 0;
|
||||
|
||||
if ($category['nb_images_recursive'] > 0)
|
||||
{
|
||||
// if we don't have "too many" photos, it's faster to compute the orphans with MySQL
|
||||
if ($category['nb_images_recursive'] < 1000)
|
||||
{
|
||||
$query = '
|
||||
SELECT DISTINCT
|
||||
(image_id)
|
||||
FROM
|
||||
'.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE
|
||||
category_id
|
||||
NOT IN
|
||||
('.implode(',', $subcat_ids).')
|
||||
AND
|
||||
image_id
|
||||
IN
|
||||
('.implode(',', $image_ids_recursive).')
|
||||
;';
|
||||
|
||||
$image_ids_associated_outside = query2array($query, null, 'image_id');
|
||||
$category['nb_images_associated_outside'] = count($image_ids_associated_outside);
|
||||
|
||||
$image_ids_becoming_orphan = array_diff($image_ids_recursive, $image_ids_associated_outside);
|
||||
$category['nb_images_becoming_orphan'] = count($image_ids_becoming_orphan);
|
||||
}
|
||||
// else it's better to avoid sending a huge SQL request, we compute the orphan list with PHP
|
||||
else
|
||||
{
|
||||
$image_ids_recursive_keys = array_flip($image_ids_recursive);
|
||||
|
||||
$query = '
|
||||
SELECT
|
||||
image_id
|
||||
FROM
|
||||
'.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE
|
||||
category_id
|
||||
NOT IN
|
||||
('.implode(',', $subcat_ids).')
|
||||
;';
|
||||
$image_ids_associated_outside = query2array($query, null, 'image_id');
|
||||
$image_ids_not_orphan = array();
|
||||
|
||||
foreach ($image_ids_associated_outside as $image_id)
|
||||
{
|
||||
if (isset($image_ids_recursive_keys[$image_id]))
|
||||
{
|
||||
$image_ids_not_orphan[] = $image_id;
|
||||
}
|
||||
}
|
||||
|
||||
$category['nb_images_associated_outside'] = count(array_unique($image_ids_not_orphan));
|
||||
$image_ids_becoming_orphan = array_diff($image_ids_recursive, $image_ids_not_orphan);
|
||||
$category['nb_images_becoming_orphan'] = count($image_ids_becoming_orphan);
|
||||
}
|
||||
}
|
||||
|
||||
$output[] = array(
|
||||
'nb_images_associated_outside' => $category['nb_images_associated_outside'],
|
||||
'nb_images_becoming_orphan' => $category['nb_images_becoming_orphan'],
|
||||
'nb_images_recursive' => $category['nb_images_recursive'],
|
||||
);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -555,116 +555,4 @@ SELECT
|
||||
fclose($f);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* API method
|
||||
* Return the number of orphan photos if an album is deleted
|
||||
*/
|
||||
|
||||
function ws_images_calculateOrphansOnAlbumDeletion($param, &$service)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$category_id = $param['category_id'][0];
|
||||
|
||||
$query = '
|
||||
SELECT DISTINCT
|
||||
category_id
|
||||
FROM
|
||||
'.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE
|
||||
category_id = '.$category_id.'
|
||||
LIMIT 1';
|
||||
$result = pwg_query($query);
|
||||
$category['has_images'] = pwg_db_num_rows($result)>0 ? true : false;
|
||||
|
||||
// number of sub-categories
|
||||
$subcat_ids = get_subcat_ids(array($category_id));
|
||||
|
||||
$category['nb_subcats'] = count($subcat_ids) - 1;
|
||||
|
||||
// total number of images under this category (including sub-categories)
|
||||
$query = '
|
||||
SELECT DISTINCT
|
||||
(image_id)
|
||||
FROM
|
||||
'.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE
|
||||
category_id IN ('.implode(',', $subcat_ids).')
|
||||
;';
|
||||
$image_ids_recursive = query2array($query, null, 'image_id');
|
||||
|
||||
$category['nb_images_recursive'] = count($image_ids_recursive);
|
||||
|
||||
// number of images that would become orphan on album deletion
|
||||
$category['nb_images_becoming_orphan'] = 0;
|
||||
$category['nb_images_associated_outside'] = 0;
|
||||
|
||||
if ($category['nb_images_recursive'] > 0)
|
||||
{
|
||||
// if we don't have "too many" photos, it's faster to compute the orphans with MySQL
|
||||
if ($category['nb_images_recursive'] < 1000)
|
||||
{
|
||||
$query = '
|
||||
SELECT DISTINCT
|
||||
(image_id)
|
||||
FROM
|
||||
'.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE
|
||||
category_id
|
||||
NOT IN
|
||||
('.implode(',', $subcat_ids).')
|
||||
AND
|
||||
image_id
|
||||
IN
|
||||
('.implode(',', $image_ids_recursive).')
|
||||
;';
|
||||
|
||||
$image_ids_associated_outside = query2array($query, null, 'image_id');
|
||||
$category['nb_images_associated_outside'] = count($image_ids_associated_outside);
|
||||
|
||||
$image_ids_becoming_orphan = array_diff($image_ids_recursive, $image_ids_associated_outside);
|
||||
$category['nb_images_becoming_orphan'] = count($image_ids_becoming_orphan);
|
||||
}
|
||||
// else it's better to avoid sending a huge SQL request, we compute the orphan list with PHP
|
||||
else
|
||||
{
|
||||
$image_ids_recursive_keys = array_flip($image_ids_recursive);
|
||||
|
||||
$query = '
|
||||
SELECT
|
||||
image_id
|
||||
FROM
|
||||
'.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE
|
||||
category_id
|
||||
NOT IN
|
||||
('.implode(',', $subcat_ids).')
|
||||
;';
|
||||
$image_ids_associated_outside = query2array($query, null, 'image_id');
|
||||
$image_ids_not_orphan = array();
|
||||
|
||||
foreach ($image_ids_associated_outside as $image_id)
|
||||
{
|
||||
if (isset($image_ids_recursive_keys[$image_id]))
|
||||
{
|
||||
$image_ids_not_orphan[] = $image_id;
|
||||
}
|
||||
}
|
||||
|
||||
$category['nb_images_associated_outside'] = count(array_unique($image_ids_not_orphan));
|
||||
$image_ids_becoming_orphan = array_diff($image_ids_recursive, $image_ids_not_orphan);
|
||||
$category['nb_images_becoming_orphan'] = count($image_ids_becoming_orphan);
|
||||
}
|
||||
}
|
||||
|
||||
$output[] = array(
|
||||
'nb_images_associated_outside' => $category['nb_images_associated_outside'],
|
||||
'nb_images_becoming_orphan' => $category['nb_images_becoming_orphan'],
|
||||
'nb_images_recursive' => $category['nb_images_recursive'],
|
||||
);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
?>
|
||||
6
ws.php
6
ws.php
@@ -594,14 +594,14 @@ function ws_addDefaultMethods( $arr )
|
||||
);
|
||||
|
||||
$service->addMethod(
|
||||
'pwg.images.calculateOrphansOnAlbumDeletion',
|
||||
'ws_images_calculateOrphansOnAlbumDeletion',
|
||||
'pwg.categories.calculateOrphans',
|
||||
'ws_categories_calculateOrphans',
|
||||
array(
|
||||
'category_id' => array('type'=>WS_TYPE_ID,
|
||||
'flags'=>WS_PARAM_FORCE_ARRAY),
|
||||
),
|
||||
'Return the number of orphan photos if an album is deleted.',
|
||||
$ws_functions_root . 'pwg.php',
|
||||
$ws_functions_root . 'pwg.categories.php',
|
||||
array('admin_only'=>true)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user