Skip to content

Commit

Permalink
merge r4730 from branch 2.0 to trunk
Browse files Browse the repository at this point in the history
bug 1396: when a photo was deleted, the code to avoid orphans as category
representative was 1) wrong (because a photo doesn't have to belong to a
category to represent it) 2) at the wrong place.


git-svn-id: http://piwigo.org/svn/trunk@4731 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Jan 23, 2010
1 parent 4e26a54 commit 4cc6d41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
12 changes: 0 additions & 12 deletions admin/element_set_global.php
Expand Up @@ -85,21 +85,9 @@

if (count($deletables) > 0)
{
// what will be the categories to update? (to avoid orphan on
// representative_picture_id)
$query = '
SELECT
category_id
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE image_id IN ('.implode(',', $deletables).')
;';
$categories_to_update = array_from_query($query, 'category_id');

$physical_deletion = true;
delete_elements($deletables, $physical_deletion);

update_category($categories_to_update);

array_push(
$page['infos'],
sprintf(
Expand Down
14 changes: 14 additions & 0 deletions admin/include/functions.php
Expand Up @@ -262,6 +262,20 @@ function delete_elements($ids, $physical_deletion=false)
;';
pwg_query($query);

// are the photo used as category representant?
$query = '
SELECT
id
FROM '.CATEGORIES_TABLE.'
WHERE representative_picture_id IN (
'.wordwrap(implode(', ', $ids), 80, "\n").')
;';
$category_ids = array_from_query($query, 'id');
if (count($category_ids) > 0)
{
update_category($category_ids);
}

trigger_action('delete_elements', $ids);
}

Expand Down

0 comments on commit 4cc6d41

Please sign in to comment.