Changeset 1065


Ignore:
Timestamp:
Mar 5, 2006, 11:44:32 PM (18 years ago)
Author:
plg
Message:

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.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/element_set_global.php

    r916 r1065  
    137137        $datas
    138138        );
    139      
     139
     140      check_links();
    140141      update_category(array($_POST['associate']));
    141142    }
     
    144145  if ($_POST['dissociate'] != 0 and count($collection) > 0)
    145146  {
    146     // physical links must not be broken, so we must first retrieve image_id
    147     // which create virtual links with the category to "dissociate from".
     147    // First, we must identify which elements in the collection are really
     148    // virtually associated with the category
    148149    $query = '
    149 SELECT id
    150   FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
     150SELECT image_id
     151  FROM '.IMAGE_CATEGORY_TABLE.'
    151152  WHERE category_id = '.$_POST['dissociate'].'
    152     AND category_id != storage_category_id
    153     AND id IN ('.implode(',', $collection).')
    154 ;';
    155     $dissociables = array_from_query($query, 'id');
    156 
     153    AND image_id IN ('.implode(',', $collection).')
     154    AND is_storage = \'false\'
     155;';
     156    $associated_images = array_from_query($query, 'image_id');
     157
     158    // If the same element is associated to a source and its destinations,
     159    // dissociating the element with the source implies dissociating the
     160    // element fwith the destination.
     161    $destinations_of = get_destinations($_POST['dissociate']);
     162
     163    $associated_categories = array_merge(
     164      array($_POST['dissociate']),
     165      $destinations_of[ $_POST['dissociate'] ]
     166      );
     167   
     168    // Eventually, deletion of associations
    157169    $query = '
    158 DELETE FROM '.IMAGE_CATEGORY_TABLE.'
    159   WHERE category_id = '.$_POST['dissociate'].'
    160   AND image_id IN ('.implode(',', $dissociables).')
     170DELETE
     171  FROM '.IMAGE_CATEGORY_TABLE.'
     172  WHERE category_id IN ('.implode(',', $associated_categories).'
     173    AND image_id IN ('.implode(',', $associated_images).')
    161174';
    162175    pwg_query($query);
    163176
    164     update_category(array($_POST['dissociate']));
     177    // check source/destination links. If category C has for sources A and
     178    // B, if picture 1 was associated to A and B, the previous code lines
     179    // have deleted the link between C and 1, while it should be kept due to
     180    // B. Who said "complicated"?
     181    check_links();
     182   
     183    update_category($associated_categories);
    165184  }
    166185
  • trunk/admin/picture_modify.php

    r1064 r1065  
    122122{
    123123  $datas = array();
     124 
    124125  foreach ($_POST['cat_dissociated'] as $category_id)
    125126  {
    126     array_push($datas, array('image_id' => $_GET['image_id'],
    127                              'category_id' => $category_id));
    128   }
    129   mass_inserts(IMAGE_CATEGORY_TABLE, array('image_id', 'category_id'), $datas);
    130 
     127    array_push(
     128      $datas,
     129      array(
     130        'image_id' => $_GET['image_id'],
     131        'category_id' => $category_id
     132        )
     133      );
     134  }
     135 
     136  mass_inserts(
     137    IMAGE_CATEGORY_TABLE,
     138    array('image_id', 'category_id'),
     139    $datas
     140    );
     141
     142  check_links();
    131143  update_category($_POST['cat_dissociated']);
    132144}
     
    136148    and count($_POST['cat_associated']) > 0)
    137149{
     150  $associated_categories = $_POST['cat_associated'];
     151
     152  // If the same element is associated to a source and its destinations,
     153  // dissociating the element with the source implies dissociating the
     154  // element fwith the destination.
     155  $destinations_of = get_destinations($_POST['cat_associated']);
     156  foreach ($destinations_of as $source => $destinations)
     157  {
     158    $associated_categories = array_merge(
     159      $associated_categories,
     160      $destinations
     161      );
     162  }
     163 
    138164  $query = '
    139165DELETE FROM '.IMAGE_CATEGORY_TABLE.'
    140166  WHERE image_id = '.$_GET['image_id'].'
    141     AND category_id IN ('.implode(',',$_POST['cat_associated'] ).')
     167    AND category_id IN ('.implode(',', $associated_categories).')
     168    AND is_storage = \'false\'
    142169';
    143170  pwg_query($query);
     171
     172  check_links();
    144173  update_category($_POST['cat_associated']);
    145174}
Note: See TracChangeset for help on using the changeset viewer.