aboutsummaryrefslogtreecommitdiffstats
path: root/admin/element_set_global.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2006-03-05 22:44:32 +0000
committerplegall <plg@piwigo.org>2006-03-05 22:44:32 +0000
commit8615119a8088ba77819601f50393ad05b6ce0208 (patch)
treecf4cacb41aaccf7fe13fe04bdef8c370d72ea4f7 /admin/element_set_global.php
parentc08fa6f67ef5b149fdeb3bcc57045e629df8fff4 (diff)
bug fixed: table #categories_link was created with an hardcoded prefix
bug fixed: on source/destination links, if an image/category association is added to a source, destinations must be filled. If an image/category association is delete from a source, the same association must be deleted in the destinations. git-svn-id: http://piwigo.org/svn/trunk@1065 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin/element_set_global.php')
-rw-r--r--admin/element_set_global.php43
1 files changed, 31 insertions, 12 deletions
diff --git a/admin/element_set_global.php b/admin/element_set_global.php
index 7bea890ef..f2b69ca6b 100644
--- a/admin/element_set_global.php
+++ b/admin/element_set_global.php
@@ -136,32 +136,51 @@ SELECT image_id
array('image_id', 'category_id'),
$datas
);
-
+
+ check_links();
update_category(array($_POST['associate']));
}
}
if ($_POST['dissociate'] != 0 and count($collection) > 0)
{
- // physical links must not be broken, so we must first retrieve image_id
- // which create virtual links with the category to "dissociate from".
+ // First, we must identify which elements in the collection are really
+ // virtually associated with the category
$query = '
-SELECT id
- FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
+SELECT image_id
+ FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id = '.$_POST['dissociate'].'
- AND category_id != storage_category_id
- AND id IN ('.implode(',', $collection).')
+ AND image_id IN ('.implode(',', $collection).')
+ AND is_storage = \'false\'
;';
- $dissociables = array_from_query($query, 'id');
+ $associated_images = array_from_query($query, 'image_id');
+
+ // If the same element is associated to a source and its destinations,
+ // dissociating the element with the source implies dissociating the
+ // element fwith the destination.
+ $destinations_of = get_destinations($_POST['dissociate']);
+ $associated_categories = array_merge(
+ array($_POST['dissociate']),
+ $destinations_of[ $_POST['dissociate'] ]
+ );
+
+ // Eventually, deletion of associations
$query = '
-DELETE FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id = '.$_POST['dissociate'].'
- AND image_id IN ('.implode(',', $dissociables).')
+DELETE
+ FROM '.IMAGE_CATEGORY_TABLE.'
+ WHERE category_id IN ('.implode(',', $associated_categories).'
+ AND image_id IN ('.implode(',', $associated_images).')
';
pwg_query($query);
- update_category(array($_POST['dissociate']));
+ // check source/destination links. If category C has for sources A and
+ // B, if picture 1 was associated to A and B, the previous code lines
+ // have deleted the link between C and 1, while it should be kept due to
+ // B. Who said "complicated"?
+ check_links();
+
+ update_category($associated_categories);
}
$datas = array();