aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2006-04-04 22:29:35 +0000
committerplegall <plg@piwigo.org>2006-04-04 22:29:35 +0000
commitd8c15ddf65ba90a8853504420a8d4839450ad4b0 (patch)
treef287793690ce347fc5ad3b7fc73b892f3f818b96 /admin
parentf33fdc91b2a5cb4ce0681df52b37ca5781660503 (diff)
feature deleted: code for categories link was too complicated for such a
simple fature. Replaced by static association. Links are not persistent anymore. modification removed: #image_category.is_storage replaced by #images.storage_category_id as in branche 1.5.. git-svn-id: http://piwigo.org/svn/trunk@1121 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin')
-rw-r--r--admin/cat_modify.php154
-rw-r--r--admin/element_set_global.php77
-rw-r--r--admin/include/functions.php545
-rw-r--r--admin/include/functions_metadata.php4
-rw-r--r--admin/maintenance.php1
-rw-r--r--admin/picture_modify.php49
-rw-r--r--admin/rating.php6
-rw-r--r--admin/site_update.php28
8 files changed, 161 insertions, 703 deletions
diff --git a/admin/cat_modify.php b/admin/cat_modify.php
index cfff0d31f..4f4617224 100644
--- a/admin/cat_modify.php
+++ b/admin/cat_modify.php
@@ -114,104 +114,50 @@ else if (isset($_POST['submitAdd']))
array_push($page['infos'], $output_create['info']);
// Link the new category to the current category
- $query = '
-INSERT
- INTO '.CATEGORIES_LINK_TABLE.'
- (source, destination)
- VALUES
- ('.$_GET['cat_id'].', '.$output_create['id'].')
-;';
- pwg_query($query);
+ associate_categories_to_categories(
+ array($_GET['cat_id']),
+ array($output_create['id'])
+ );
- check_links(array($output_create['id']));
- update_category(array($output_create['id']));
- }
-}
-else if (isset($_POST['destination_trueify'])
- and isset($_POST['destination_false'])
- and count($_POST['destination_false']))
-{
- $datas = array();
-
- foreach ($_POST['destination_false'] as $category_id)
- {
+ // information
array_push(
- $datas,
- array(
- 'source' => $_GET['cat_id'],
- 'destination' => $category_id,
+ $page['infos'],
+ sprintf(
+ l10n('Category elements associated to the following categories: %s'),
+ '<ul><li>'
+ .get_cat_display_name_from_id($output_create['id'])
+ .'</li></ul>'
)
);
}
-
- mass_inserts(
- CATEGORIES_LINK_TABLE,
- array('source', 'destination'),
- $datas
- );
-
- check_links($_POST['destination_false']);
- update_category(
- $_POST['destination_false'],
- true // recursive update
- );
}
-else if (isset($_POST['destination_falsify'])
- and isset($_POST['destination_true'])
- and count($_POST['destination_true']))
+else if (isset($_POST['submitDestinations'])
+ and isset($_POST['destinations'])
+ and count($_POST['destinations']) > 0)
{
- foreach ($_POST['destination_true'] as $destination)
- {
- delete_sources($destination, array($_GET['cat_id']));
- }
-
- update_category(
- $_POST['destination_true'],
- true // recursive update
+ associate_categories_to_categories(
+ array($_GET['cat_id']),
+ $_POST['destinations']
);
-}
-else if (isset($_POST['source_trueify'])
- and isset($_POST['source_false'])
- and count($_POST['source_false']))
-{
- $datas = array();
-
- foreach ($_POST['source_false'] as $category_id)
+
+ $category_names = array();
+ foreach ($_POST['destinations'] as $category_id)
{
array_push(
- $datas,
- array(
- 'source' => $category_id,
- 'destination' => $_GET['cat_id'],
- )
+ $category_names,
+ get_cat_display_name_from_id($category_id)
);
}
-
- mass_inserts(
- CATEGORIES_LINK_TABLE,
- array('source', 'destination'),
- $datas
- );
- check_links(array($_GET['cat_id']));
- update_category(
- array($_GET['cat_id']),
- true // recursive update
- );
-}
-else if (isset($_POST['source_falsify'])
- and isset($_POST['source_true'])
- and count($_POST['source_true']))
-{
- delete_sources($_GET['cat_id'], $_POST['source_true']);
-
- update_category(
- array($_GET['cat_id']),
- true // recursive update
+ array_push(
+ $page['infos'],
+ sprintf(
+ l10n('Category elements associated to the following categories: %s'),
+ '<ul><li>'.implode('</li><li>', $category_names).'</li></ul>'
+ )
);
}
-
$query = '
SELECT *
FROM '.CATEGORIES_TABLE.'
@@ -381,7 +327,7 @@ SELECT tn_ext,path
}
}
-if (!$category['is_virtual']) //!empty($category['dir']))
+if (!$category['is_virtual'])
{
$template->assign_block_vars(
'storage',
@@ -469,47 +415,17 @@ display_select_cat_wrapper(
// destination categories
$query = '
-SELECT DISTINCT id, name, uppercats, global_rank
- FROM '.CATEGORIES_TABLE.'
- INNER JOIN '.CATEGORIES_LINK_TABLE.' ON destination = id
- WHERE source = '.$_GET['cat_id'].'
-;';
-display_select_cat_wrapper($query, array(), 'destination_option_true');
-
-// non destination categories
-$destinations = array_merge(
- array($_GET['cat_id']),
- array_from_query($query, 'id')
- );
-
-$query = '
-SELECT DISTINCT id, name, uppercats, global_rank
- FROM '.CATEGORIES_TABLE.'
- WHERE id NOT IN ('.implode(',', $destinations).')
-;';
-display_select_cat_wrapper($query, array(), 'destination_option_false');
-
-// source categories
-$query = '
-SELECT DISTINCT id, name, uppercats, global_rank
+SELECT id,name,uppercats,global_rank
FROM '.CATEGORIES_TABLE.'
- INNER JOIN '.CATEGORIES_LINK_TABLE.' ON source = id
- WHERE destination = '.$_GET['cat_id'].'
+ WHERE id != '.$category['id'].'
;';
-display_select_cat_wrapper($query, array(), 'source_option_true');
-// non source categories
-$sources = array_merge(
- array($_GET['cat_id']),
- array_from_query($query, 'id')
+display_select_cat_wrapper(
+ $query,
+ array(),
+ 'category_option_destination'
);
-$query = '
-SELECT DISTINCT id, name, uppercats, global_rank
- FROM '.CATEGORIES_TABLE.'
- WHERE id NOT IN ('.implode(',', $sources).')
-;';
-display_select_cat_wrapper($query, array(), 'source_option_false');
//----------------------------------------------------------- sending html code
$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
diff --git a/admin/element_set_global.php b/admin/element_set_global.php
index 22ea2df13..041cbe0cf 100644
--- a/admin/element_set_global.php
+++ b/admin/element_set_global.php
@@ -95,80 +95,35 @@ DELETE
if ($_POST['associate'] != 0 and count($collection) > 0)
{
- $datas = array();
-
- $query = '
-SELECT image_id
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id = '.$_POST['associate'].'
-;';
- $associated = array_from_query($query, 'image_id');
-
- $associable = array_diff($collection, $associated);
-
- if (count($associable) != 0)
- {
- foreach ($associable as $item)
- {
- array_push(
- $datas,
- array(
- 'category_id' => $_POST['associate'],
- 'image_id' => $item
- )
- );
- }
-
- mass_inserts(
- IMAGE_CATEGORY_TABLE,
- array('image_id', 'category_id'),
- $datas
- );
-
- check_links();
- update_category(array($_POST['associate']));
- }
+ associate_images_to_categories(
+ $collection,
+ array($_POST['associate'])
+ );
}
if ($_POST['dissociate'] != 0 and count($collection) > 0)
{
- // First, we must identify which elements in the collection are really
- // virtually associated with the 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 image_id
+SELECT id
FROM '.IMAGE_CATEGORY_TABLE.'
+ INNER JOIN '.IMAGES_TABLE.' ON image_id = id
WHERE category_id = '.$_POST['dissociate'].'
- AND image_id IN ('.implode(',', $collection).')
- AND is_storage = \'false\'
+ AND id IN ('.implode(',', $collection).')
+ AND category_id != storage_category_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']);
+ $dissociables = array_from_query($query, 'id');
- $associated_categories = array_merge(
- array($_POST['dissociate']),
- $destinations_of[ $_POST['dissociate'] ]
- );
-
- // Eventually, deletion of associations
$query = '
DELETE
FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id IN ('.implode(',', $associated_categories).'
- AND image_id IN ('.implode(',', $associated_images).')
+ WHERE category_id = '.$_POST['dissociate'].'
+ AND image_id IN ('.implode(',', $dissociables).')
';
pwg_query($query);
-
- // 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);
+
+ update_category($_POST['dissociate']);
}
$datas = array();
@@ -318,7 +273,7 @@ SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank
WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).')
AND ic.category_id = c.id
AND ic.image_id = i.id
- AND ic.is_storage = \'false\'
+ AND ic.category_id != i.storage_category_id
;';
display_select_cat_wrapper($query, array(), $blockname, true);
}
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 3a8c6b506..f9435b1f1 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -152,22 +152,16 @@ function delete_categories($ids)
// destruction of all the related elements
$query = '
-SELECT image_id
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE is_storage = \'true\'
- AND category_id IN ('.
- wordwrap(
- implode(', ', $ids),
- 80,
- "\n"
- ).
- ')
+SELECT id
+ FROM '.IMAGES_TABLE.'
+ WHERE storage_category_id IN (
+'.wordwrap(implode(', ', $ids), 80, "\n").')
;';
$result = pwg_query($query);
$element_ids = array();
while ($row = mysql_fetch_array($result))
{
- array_push($element_ids, $row['image_id']);
+ array_push($element_ids, $row['id']);
}
delete_elements($element_ids);
@@ -194,37 +188,6 @@ DELETE FROM '.GROUP_ACCESS_TABLE.'
;';
pwg_query($query);
- // source/destination links deletion
- $query = '
-SELECT destination, source
- FROM '.CATEGORIES_LINK_TABLE.'
- WHERE source IN ('.implode(',', $ids).')
- OR destination IN ('.implode(',', $ids).')
-;';
- $result = pwg_query($query);
-
- $sources_of = array();
-
- while ($row = mysql_fetch_array($result))
- {
- if (!isset($sources_of[ $row['destination'] ]))
- {
- $sources_of[ $row['destination'] ] = array();
- }
-
- array_push(
- $sources_of[ $row['destination'] ],
- $row['source']
- );
- }
-
- foreach ($sources_of as $destination => $sources)
- {
- delete_sources($destination, $sources);
- }
-
- update_category();
-
// destruction of the category
$query = '
DELETE FROM '.CATEGORIES_TABLE.'
@@ -441,15 +404,14 @@ SELECT id
SELECT category_id,
COUNT(image_id) AS nb_images,
MAX(date_available) AS date_last
- FROM '.IMAGES_TABLE.'
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
+ FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
WHERE category_id IN ('.wordwrap(implode(', ', $cat_ids), 80, "\n").')
GROUP BY category_id
;';
$result = pwg_query($query);
$datas = array();
$query_ids = array();
- while ($row = mysql_fetch_array($result))
+ while ( $row = mysql_fetch_array( $result ) )
{
array_push($query_ids, $row['category_id']);
@@ -466,23 +428,12 @@ SELECT category_id,
// is returned but the update must be done !
foreach (array_diff($cat_ids, $query_ids) as $id)
{
- array_push(
- $datas,
- array(
- 'id' => $id,
- 'nb_images' => 0,
- )
- );
+ array_push($datas, array('id' => $id, 'nb_images' => 0));
}
- mass_updates(
- CATEGORIES_TABLE,
- array(
- 'primary' => array('id'),
- 'update' => array('date_last', 'nb_images')
- ),
- $datas
- );
+ $fields = array('primary' => array('id'),
+ 'update' => array('date_last', 'nb_images'));
+ mass_updates(CATEGORIES_TABLE, $fields, $datas);
// representative pictures
if (count($cat_ids) > 0)
@@ -1357,42 +1308,19 @@ SELECT id, id_uppercat
*/
function update_path()
{
- $images_of = array();
-
$query = '
-SELECT category_id, image_id
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE is_storage = \'true\'
+SELECT DISTINCT(storage_category_id)
+ FROM '.IMAGES_TABLE.'
;';
- $result = pwg_query($query);
- while ($row = mysql_fetch_array($result))
- {
- if (!isset($images_of[ $row['category_id'] ]))
- {
- $images_of[ $row['category_id'] ] = array();
- }
+ $cat_ids = array_from_query($query, 'storage_category_id');
+ $fulldirs = get_fulldirs($cat_ids);
- array_push(
- $images_of[ $row['category_id'] ],
- $row['image_id']
- );
- }
-
- $fulldirs = get_fulldirs(
- array_keys($images_of)
- );
-
- foreach ($images_of as $cat_id => $image_ids)
+ foreach ($cat_ids as $cat_id)
{
$query = '
UPDATE '.IMAGES_TABLE.'
SET path = CONCAT(\''.$fulldirs[$cat_id].'\',\'/\',file)
- WHERE id IN ('.
- wordwrap(
- implode(', ', $image_ids),
- 80,
- "\n").
- ')
+ WHERE storage_category_id = '.$cat_id.'
;';
pwg_query($query);
}
@@ -1613,371 +1541,6 @@ DELETE FROM '.$table.'
}
/**
- * Returns all destinations of a list of source categories. This function
- * solves transitivity.
- *
- * @param mixed array of category ids, empty for all categories
- */
-function get_destinations($categories = 'all')
-{
- $query = '
-SELECT source, destination
- FROM '.CATEGORIES_LINK_TABLE.'
-';
- $result = pwg_query($query);
-
- $destinations_of = array();
-
- while ($row = mysql_fetch_array($result))
- {
- if (!isset($destinations_of[ $row['source'] ]))
- {
- $destinations_of[ $row['source'] ] = array();
- }
-
- array_push(
- $destinations_of[ $row['source'] ],
- $row['destination']
- );
- }
-
- // transitivity resolution: if " => " means "source of", if A=>B=>C
- // implies A=>B and A=>C. So A has 2 destinations: B and C.
- do
- {
- // let's suppose we only need a single turn
- $need_new_turn = false;
-
- foreach ($destinations_of as $source => $destinations)
- {
- foreach ($destinations as $destination)
- {
- // does the current destination has destinations itself?
- if (isset($destinations_of[$destination]))
- {
- // are there destinations of current destination not already among
- // destinations of the current source? (advise: take a piece of
- // paper and draw a schema). The source itself must not be counted
- // as a destination, thus avoiding cyclic links.
- $missing_destinations = array_diff(
- $destinations_of[$destination],
- $destinations,
- array($source) // no cyclic link
- );
-
- if (count($missing_destinations) > 0)
- {
- $destinations_of[$source] = array_unique(
- array_merge(
- $destinations,
- $missing_destinations
- )
- );
-
- // a category has a least one new destination, we have to check
- // one more time that it doesn't generate more destinations
- $need_new_turn = true;
- }
- }
- }
- }
- } while ($need_new_turn);
-
- if (is_array($categories))
- {
- $filtered_destinations_of = array();
-
- // Even if there is no destinations for the requested categories, we
- // return empty arrays
- foreach ($categories as $category)
- {
- $filtered_destinations_of[$category] = array();
- }
-
- foreach ($destinations_of as $source => $destinations)
- {
- if (in_array($source, $categories))
- {
- $filtered_destinations_of[$source] = $destinations;
- }
- }
-
- return $filtered_destinations_of;
- }
- else
- {
- return $destinations_of;
- }
-}
-
-/**
- * Returns all sources of a list of destination categories. This function
- * solves transitivity.
- *
- * @param mixed array of category ids, empty for all categories
- */
-function get_sources($categories = 'all')
-{
- $destinations_of = get_destinations();
-
- $sources_of = array();
-
- foreach ($destinations_of as $source => $destinations)
- {
- foreach ($destinations as $destination)
- {
- if (!isset($sources_of[$destination]))
- {
- $sources_of[$destination] = array();
- }
-
- array_push($sources_of[$destination], $source);
- }
- }
-
- // eventually, filter
- if (is_array($categories))
- {
- $filtered_sources_of = array();
-
- // Even if there is no sources for the requested categories, we return
- // empty arrays
- foreach ($categories as $category)
- {
- $filtered_sources_of[$category] = array();
- }
-
- foreach ($sources_of as $destination => $sources)
- {
- if (in_array($destination, $categories))
- {
- $filtered_sources_of[$destination] = $sources;
- }
- }
-
- return $filtered_sources_of;
- }
- else
- {
- return $sources_of;
- }
-}
-
-/**
- * Checks categories links are respected for a given list of destinations.
- *
- * Checking categories links means that each destination must be associated
- * to the images of its sources.
- *
- * @param mixed source category ids
- */
-function check_links($destinations = 'all')
-{
- $sources_of = get_sources($destinations);
-
- if (empty($sources_of))
- {
- return true;
- }
-
- // we need to search images of all sources and destinations
- $images_of = array();
-
- foreach ($sources_of as $destination => $sources)
- {
- $images_of[$destination] = array();
-
- foreach ($sources as $source)
- {
- $images_of[$source] = array();
- }
- }
-
- $query = '
-SELECT image_id, category_id
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id IN ('.
- implode(',', array_keys($images_of)).
- ')
-;';
- $result = pwg_query($query);
-
- while ($row = mysql_fetch_array($result))
- {
- array_push(
- $images_of[ $row['category_id'] ],
- $row['image_id']
- );
- }
-
- $inserts = array();
-
- foreach ($sources_of as $destination => $sources)
- {
- // merge all images from the sources of this destination
- $sources_images = array();
-
- foreach ($sources as $source)
- {
- $sources_images = array_merge(
- $sources_images,
- $images_of[$source]
- );
- }
-
- $sources_images = array_unique($sources_images);
-
- // are there images among the sources that are not linked to the
- // destination?
- $missing_images = array_diff(
- $sources_images,
- $images_of[$destination]
- );
-
- // if we find missing images (missing links in reality), we prepare the
- // final mass_inserts
- if (count($missing_images) > 0)
- {
- foreach ($missing_images as $missing_image)
- {
- array_push(
- $inserts,
- array(
- 'category_id' => $destination,
- 'image_id' => $missing_image,
- )
- );
- }
- }
- }
-
- if (count($inserts) > 0)
- {
- mass_inserts(
- IMAGE_CATEGORY_TABLE,
- array_keys($inserts[0]),
- $inserts
- );
- }
-}
-
-/**
- * Based on categories links, delete image_category links on destinations.
- *
- * The rule is the following: if an image belong to the category and to the
- * source, we suppose it comes from the source. If the source/destination
- * link is broken, we delete the image/category link if the only origin of
- * the link was the broken categories link.
- *
- * Example: "=>" means "source of". Between brackets the associated images.
- *
- * A (1,2,9) => \
- * |=> C (1,2,3,4,5,9) => D (1,2,3,4,5,6,9)
- * B (3,4,9) => /
- *
- * In category C, we suppose (1,2) come from A, (3,4) from B, 9 from A or B
- * and 5 was manually added. In category D, 6 was added manually.
- *
- * If we break A=>C, C and D loose (1,2) but not 9 because it can come from
- * B. If we break C=>D, D loose (3,4,5,9) but not 6 because it was
- * associated manually to 9.
- *
- * Warning: only virtual links can be removed, physical links are protected.
- *
- * @param int destination
- * @param array sources
- */
-function delete_sources($destination, $sources)
-{
- // if no sources to unlink, we stop with OK status
- if (count($sources) == 0)
- {
- return true;
- }
-
- $query = '
-DELETE
- FROM '.CATEGORIES_LINK_TABLE.'
- WHERE destination = '.$destination.'
- AND source IN ('.implode(',', $sources).')
-;';
- pwg_query($query);
-
- // The strategy is the following:
- //
- // * first we brutally delete the image/category associations on
- // destinations categories for all images belonging to sources.
- //
- // * then we check_links on destinations to rebuild missing image/category
- // associations.
-
- // what are the images associated to the sources to unlink
- $query = '
-SELECT image_id
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id IN ('.
- implode(',', $sources).
- ')
-;';
- $sources_images = array_unique(
- array_from_query($query, 'image_id')
- );
-
- if (count($sources_images) == 0)
- {
- return true;
- }
-
- // retrieve all direct and indirect destinations of the current
- // destination
- $destinations_of = get_destinations(array($destination));
-
- $destinations = array_merge(
- array($destination),
- $destinations_of[$destination]
- );
-
- // unlink sources images from destinations
- $query = '
-DELETE
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id IN ('.implode(',', $destinations).')
- AND image_id IN ('.implode(',', $sources_images).')
- AND is_storage = \'false\'
-;';
- pwg_query($query);
-
- // if the representative thumbnail of destinations was a picture from
- // $sources_images, we request a new random representant
- $query = '
-SELECT id, representative_picture_id
- FROM '.CATEGORIES_TABLE.'
- WHERE id IN ('.implode(',', $destinations).')
-;';
- $result = pwg_query($query);
-
- $request_random = array();
-
- while ($row = mysql_fetch_array($result))
- {
- if (isset($row['representative_picture_id']))
- {
- if (in_array($row['representative_picture_id'], $sources_images))
- {
- array_push($request_random, $row['id']);
- }
- }
- }
-
- set_random_representant($request_random);
-
- // eventually, we check_links to rebuild missing associations
- check_links($destinations);
-
- return true;
-}
-
-/**
* create a virtual category
*
* @param string category name
@@ -2299,4 +1862,78 @@ function do_maintenance_all_tables()
pwg_query($query);
}
+
+/**
+ * Associate a list of images to a list of categories.
+ *
+ * The function will not duplicate links
+ *
+ * @param array images
+ * @param array categories
+ * @return void
+ */
+function associate_images_to_categories($images, $categories)
+{
+ if (count($images) == 0
+ or count($categories) == 0)
+ {
+ return false;
+ }
+
+ $query = '
+DELETE
+ FROM '.IMAGE_CATEGORY_TABLE.'
+ WHERE image_id IN ('.implode(',', $images).')
+ AND category_id IN ('.implode(',', $categories).')
+;';
+ pwg_query($query);
+
+ $inserts = array();
+ foreach ($categories as $category_id)
+ {
+ foreach ($images as $image_id)
+ {
+ array_push(
+ $inserts,
+ array(
+ 'image_id' => $image_id,
+ 'category_id' => $category_id,
+ )
+ );
+ }
+ }
+
+ mass_inserts(
+ IMAGE_CATEGORY_TABLE,
+ array_keys($inserts[0]),
+ $inserts
+ );
+
+ update_category($categories);
+}
+
+/**
+ * Associate images associated to a list of source categories to a list of
+ * destination categories.
+ *
+ * @param array sources
+ * @param array destinations
+ * @return void
+ */
+function associate_categories_to_categories($sources, $destinations)
+{
+ if (count($sources) == 0)
+ {
+ return false;
+ }
+
+ $query = '
+SELECT image_id
+ FROM '.IMAGE_CATEGORY_TABLE.'
+ WHERE category_id IN ('.implode(',', $sources).')
+;';
+ $images = array_from_query($query, 'image_id');
+
+ associate_images_to_categories($images, $destinations);
+}
?>
diff --git a/admin/include/functions_metadata.php b/admin/include/functions_metadata.php
index 21897c2cd..d4324a763 100644
--- a/admin/include/functions_metadata.php
+++ b/admin/include/functions_metadata.php
@@ -246,9 +246,7 @@ SELECT id
$query = '
SELECT id, path
FROM '.IMAGES_TABLE.'
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
- WHERE is_storage = \'true\'
- AND category_id IN ('.implode(',', $cat_ids).')';
+ WHERE storage_category_id IN ('.implode(',', $cat_ids).')';
if ($only_new)
{
$query.= '
diff --git a/admin/maintenance.php b/admin/maintenance.php
index de6c2a4a1..2fa60696c 100644
--- a/admin/maintenance.php
+++ b/admin/maintenance.php
@@ -47,7 +47,6 @@ switch ($action)
{
case 'categories' :
{
- check_links();
update_uppercats();
update_category('all');
ordering();
diff --git a/admin/picture_modify.php b/admin/picture_modify.php
index 83bf09a23..ac7310ddd 100644
--- a/admin/picture_modify.php
+++ b/admin/picture_modify.php
@@ -121,56 +121,23 @@ if (isset($_POST['associate'])
and isset($_POST['cat_dissociated'])
and count($_POST['cat_dissociated']) > 0)
{
- $datas = array();
-
- foreach ($_POST['cat_dissociated'] as $category_id)
- {
- array_push(
- $datas,
- array(
- 'image_id' => $_GET['image_id'],
- 'category_id' => $category_id
- )
- );
- }
-
- mass_inserts(
- IMAGE_CATEGORY_TABLE,
- array('image_id', 'category_id'),
- $datas
+ associate_images_to_categories(
+ array($_GET['image_id']),
+ $_POST['cat_dissociated']
);
-
- check_links();
- update_category($_POST['cat_dissociated']);
}
// dissociate the element from categories (but not from its storage category)
if (isset($_POST['dissociate'])
and isset($_POST['cat_associated'])
and count($_POST['cat_associated']) > 0)
{
- $associated_categories = $_POST['cat_associated'];
-
- // 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['cat_associated']);
- foreach ($destinations_of as $source => $destinations)
- {
- $associated_categories = array_merge(
- $associated_categories,
- $destinations
- );
- }
-
$query = '
DELETE FROM '.IMAGE_CATEGORY_TABLE.'
WHERE image_id = '.$_GET['image_id'].'
- AND category_id IN ('.implode(',', $associated_categories).')
- AND is_storage = \'false\'
+ AND category_id IN ('.implode(',', $_POST['cat_associated']).')
';
pwg_query($query);
-
- check_links();
+
update_category($_POST['cat_associated']);
}
// elect the element to represent the given categories
@@ -201,13 +168,11 @@ if (isset($_POST['dismiss'])
$query = '
SELECT *
FROM '.IMAGES_TABLE.'
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
WHERE id = '.$_GET['image_id'].'
- AND is_storage = \'true\'
;';
$row = mysql_fetch_array(pwg_query($query));
-$storage_category_id = $row['category_id'];
+$storage_category_id = $row['storage_category_id'];
$image_file = $row['file'];
// tags
@@ -396,7 +361,7 @@ SELECT id,name,uppercats,global_rank
FROM '.CATEGORIES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
WHERE image_id = '.$_GET['image_id'].'
- AND is_storage = \'false\'
+ AND id != '.$storage_category_id.'
;';
display_select_cat_wrapper($query, array(), 'associated_option');
diff --git a/admin/rating.php b/admin/rating.php
index 76b4aa865..86f95205a 100644
--- a/admin/rating.php
+++ b/admin/rating.php
@@ -182,16 +182,14 @@ SELECT i.id,
i.file,
i.tn_ext,
i.average_rate,
+ i.storage_category_id,
MAX(r.date) AS recently_rated,
COUNT(r.rate) AS nb_rates,
SUM(r.rate) AS sum_rates,
- ROUND(STD(r.rate),2) AS std_rates,
- ic.category_id AS storage_category_id
+ ROUND(STD(r.rate),2) AS std_rates
FROM '.RATE_TABLE.' AS r
LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id
WHERE 1 = 1 ' . $display_filter . '
- AND ic.is_storage = \'true\'
GROUP BY r.element_id
ORDER BY ' . $available_order_by[$order_by_index][1] .'
LIMIT '.$start.','.$elements_per_page.'
diff --git a/admin/site_update.php b/admin/site_update.php
index c7c31106c..3562046ae 100644
--- a/admin/site_update.php
+++ b/admin/site_update.php
@@ -368,15 +368,12 @@ if (isset($_POST['submit']) and $_POST['sync'] == 'files'
$query = '
SELECT id, path
FROM '.IMAGES_TABLE.'
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
- WHERE is_storage = \'true\'
- AND category_id IN ('.
- wordwrap(
+ WHERE storage_category_id IN ('
+ .wordwrap(
implode(', ', $cat_ids),
80,
"\n"
- ).
- ')
+ ).')
;';
$result = pwg_query($query);
while ($row = mysql_fetch_array($result))
@@ -458,6 +455,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
? $fs[$path]['has_high']
: null,
'path' => $path,
+ 'storage_category_id' => $db_fulldirs[$dirname],
);
array_push(
@@ -469,8 +467,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
$insert_links,
array(
'image_id' => $insert{'id'},
- 'category_id' => $db_fulldirs[$dirname],
- 'is_storage' => 'true',
+ 'category_id' => $insert['storage_category_id'],
)
);
array_push(
@@ -508,6 +505,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
'representative_ext' => isset($fs[$path]['representative_ext'])
? $fs[$path]['representative_ext']
: null,
+ 'storage_category_id' => $db_fulldirs[$dirname],
);
array_push(
@@ -519,8 +517,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
$insert_links,
array(
'image_id' => $insert{'id'},
- 'category_id' => $db_fulldirs[$dirname],
- 'is_storage' => 'true',
+ 'category_id' => $insert['storage_category_id'],
)
);
@@ -552,7 +549,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
mass_inserts(
IMAGE_CATEGORY_TABLE,
array(
- 'image_id','category_id', 'is_storage',
+ 'image_id','category_id',
),
$insert_links
);
@@ -609,9 +606,7 @@ SELECT id,file,storage_category_id,infos
$query = '
SELECT id
FROM '.IMAGES_TABLE.'
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
- WHERE is_storage = \'true\'
- AND category_id = '.$row['storage_category_id'].'
+ WHERE storage_category_id = '.$row['storage_category_id'].'
AND file = \''.$row['file'].'\'
;';
list($data['id']) = mysql_fetch_array(pwg_query($query));
@@ -659,11 +654,6 @@ if (isset($_POST['submit'])
if (!$simulate)
{
$start = get_moment();
- check_links('all');
- echo '<!-- check_links(all) : ';
- echo get_elapsed_time($start,get_moment());
- echo ' -->'."\n";
- $start = get_moment();
update_category('all');
echo '<!-- update_category(all) : ';
echo get_elapsed_time($start,get_moment());