Changeset 8265


Ignore:
Timestamp:
Dec 23, 2010, 9:48:28 PM (10 years ago)
Author:
plg
Message:

feature 2081 added: ability to choose what to do with photos when deleting an
album : no_delete, delete_orphans, force_delete. Backend only.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r8247 r8265  
    5353// The function delete_categories deletes the categories identified by the
    5454// (numeric) key of the array $ids. It also deletes (in the database) :
    55 //    - all the elements of the category (delete_elements, see further)
     55//    - all the elements physically linked to the category (delete_elements, see further)
    5656//    - all the links between elements and this category
    5757//    - all the restrictions linked to the category
    5858// The function works recursively.
    59 function delete_categories($ids)
     59//
     60// the $photo_deletion_mode is for photos virtually linked to the categorty
     61//   * no_delete : delete no photo, may create orphans
     62//   * delete_orphans : delete photos that are no longer linked to any category
     63//   * force_delete : delete photos even if they are linked to another category
     64function delete_categories($ids, $photo_deletion_mode='no_delete')
    6065{
    6166  if (count($ids) == 0)
     
    6873  $ids = get_subcat_ids($ids);
    6974
    70   // destruction of all the related elements
     75  // destruction of all photos physically linked to the category
    7176  $query = '
    7277SELECT id
     
    8287  }
    8388  delete_elements($element_ids);
     89
     90  // now, should we delete photos that are virtually linked to the category?
     91  if ('delete_orphans' == $photo_deletion_mode or 'force_delete' == $photo_deletion_mode)
     92  {
     93    $query = '
     94SELECT
     95    DISTINCT(image_id)
     96  FROM '.IMAGE_CATEGORY_TABLE.'
     97  WHERE category_id IN ('.implode(',', $ids).')
     98;';
     99    $image_ids_linked = array_from_query($query, 'image_id');
     100   
     101    if ('delete_orphans' == $photo_deletion_mode)
     102    {
     103      $query = '
     104SELECT
     105    DISTINCT(image_id)
     106  FROM '.IMAGE_CATEGORY_TABLE.'
     107  WHERE image_id IN ('.implode(',', $image_ids_linked).')
     108    AND category_id NOT IN ('.implode(',', $ids).')
     109;';
     110      $image_ids_not_orphans = array_from_query($query, 'image_id');
     111      $image_ids_to_delete = array_diff($image_ids_linked, $image_ids_not_orphans);
     112    }
     113
     114    if ('force_delete' == $photo_deletion_mode)
     115    {
     116      $image_ids_to_delete = $image_ids_linked;
     117    }
     118
     119    delete_elements($image_ids_to_delete, true);
     120  }
    84121
    85122  // destruction of the links between images and this category
Note: See TracChangeset for help on using the changeset viewer.