mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-06-02 04:15:05 +02:00
fixes #1735 new API method pwg.images.setCategory to associate/dissociate/move a list of images
This commit is contained in:
@@ -207,31 +207,10 @@ DELETE
|
||||
|
||||
else if ('dissociate' == $action)
|
||||
{
|
||||
// physical links must not be broken, so we must first retrieve image_id
|
||||
// which create virtual links with the category to "dissociate from".
|
||||
$query = '
|
||||
SELECT id
|
||||
FROM '.IMAGE_CATEGORY_TABLE.'
|
||||
INNER JOIN '.IMAGES_TABLE.' ON image_id = id
|
||||
WHERE category_id = '.$_POST['dissociate'].'
|
||||
AND id IN ('.implode(',', $collection).')
|
||||
AND (
|
||||
category_id != storage_category_id
|
||||
OR storage_category_id IS NULL
|
||||
)
|
||||
;';
|
||||
$dissociables = array_from_query($query, 'id');
|
||||
$nb_dissociated = dissociate_images_from_category($collection, $_POST['dissociate']);
|
||||
|
||||
if (!empty($dissociables))
|
||||
if ($nb_dissociated > 0)
|
||||
{
|
||||
$query = '
|
||||
DELETE
|
||||
FROM '.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE category_id = '.$_POST['dissociate'].'
|
||||
AND image_id IN ('.implode(',', $dissociables).')
|
||||
';
|
||||
pwg_query($query);
|
||||
|
||||
$_SESSION['page_infos'] = array(
|
||||
l10n('Information data registered in database')
|
||||
);
|
||||
|
||||
@@ -2102,6 +2102,43 @@ SELECT
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dissociate a list of images from a category.
|
||||
*
|
||||
* @param int[] $images
|
||||
* @param int $categories
|
||||
*/
|
||||
function dissociate_images_from_category($images, $category)
|
||||
{
|
||||
// physical links must not be broken, so we must first retrieve image_id
|
||||
// which create virtual links with the category to "dissociate from".
|
||||
$query = '
|
||||
SELECT id
|
||||
FROM '.IMAGE_CATEGORY_TABLE.'
|
||||
INNER JOIN '.IMAGES_TABLE.' ON image_id = id
|
||||
WHERE category_id ='.$category.'
|
||||
AND id IN ('.implode(',', $images).')
|
||||
AND (
|
||||
category_id != storage_category_id
|
||||
OR storage_category_id IS NULL
|
||||
)
|
||||
;';
|
||||
$dissociables = array_from_query($query, 'id');
|
||||
|
||||
if (!empty($dissociables))
|
||||
{
|
||||
$query = '
|
||||
DELETE
|
||||
FROM '.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE category_id = '.$category.'
|
||||
AND image_id IN ('.implode(',', $dissociables).')
|
||||
';
|
||||
pwg_query($query);
|
||||
}
|
||||
|
||||
return count($dissociables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dissociate images from all old categories except their storage category and
|
||||
* associate to new categories.
|
||||
|
||||
Reference in New Issue
Block a user