aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2008-04-20 22:20:20 +0000
committerrvelices <rv-github@modusoptimus.com>2008-04-20 22:20:20 +0000
commit23fcaf6b6493c8d479a30201ea9fff3e5cffe4ff (patch)
treea0ce56162f8d37d244953b0f1e2cc74865cb04b3 /admin
parent57b03a7218475f365e8838bab029bc8a6de94a48 (diff)
- merged function ordering() with update_global_rank() and also optimized the queries
git-svn-id: http://piwigo.org/svn/trunk@2306 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--admin/cat_list.php9
-rw-r--r--admin/include/functions.php117
-rw-r--r--admin/maintenance.php1
-rw-r--r--admin/site_update.php7
4 files changed, 48 insertions, 86 deletions
diff --git a/admin/cat_list.php b/admin/cat_list.php
index 640754c70..1ec2d4422 100644
--- a/admin/cat_list.php
+++ b/admin/cat_list.php
@@ -57,7 +57,7 @@ function save_categories_order($categories)
$fields = array('primary' => array('id'), 'update' => array('rank'));
mass_updates(CATEGORIES_TABLE, $fields, $datas);
- update_global_rank(@$_GET['parent_id']);
+ update_global_rank();
}
// +-----------------------------------------------------------------------+
@@ -66,8 +66,8 @@ function save_categories_order($categories)
$categories = array();
-$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
-$navigation = '<a class="" href="'.$base_url.'">';
+$base_url = get_root_url().'admin.php?page=cat_list';
+$navigation = '<a href="'.$base_url.'">';
$navigation.= l10n('home');
$navigation.= '</a>';
@@ -79,7 +79,6 @@ if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser())
{
delete_categories(array($_GET['delete']));
array_push($page['infos'], l10n('cat_virtual_deleted'));
- ordering();
update_global_rank();
}
// request to add a virtual category
@@ -236,7 +235,7 @@ foreach ($categories as $category)
'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
'U_EDIT' => $base_url.'cat_modify&amp;cat_id='.$category['id'],
-
+
'IS_VIRTUAL' => empty($category['dir'])
);
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 63e173619..c6f72c5f4 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -665,69 +665,72 @@ function mass_updates($tablename, $dbfields, $datas)
}
/**
- * updates the global_rank of categories under the given id_uppercat
- *
- * @param int id_uppercat
+ * order categories (update categories.rank and global_rank database fields)
+ * so that rank field are consecutive integers starting at 1 for each child
* @return void
*/
-function update_global_rank($id_uppercat = 'all')
+function update_global_rank()
{
$query = '
-SELECT id,rank
+SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat, uppercats, rank, global_rank
FROM '.CATEGORIES_TABLE.'
+ ORDER BY id_uppercat,rank,name
;';
- $result = pwg_query($query);
- $ranks_array = array();
- while ($row = mysql_fetch_array($result))
- {
- $ranks_array[$row['id']] = $row['rank'];
- }
- // which categories to update ?
- $uppercats_array = array();
+ $cat_map = array();
+
+ $current_rank = 0;
+ $current_uppercat = '';
- $query = '
-SELECT id,uppercats
- FROM '.CATEGORIES_TABLE;
- if (is_numeric($id_uppercat))
- {
- $query.= '
- WHERE uppercats REGEXP \'(^|,)'.$id_uppercat.'(,|$)\'
- AND id != '.$id_uppercat.'
-';
- }
- $query.= '
-;';
$result = pwg_query($query);
while ($row = mysql_fetch_array($result))
{
- $uppercats_array[$row['id']] = $row['uppercats'];
+ if ($row['id_uppercat'] != $current_uppercat)
+ {
+ $current_rank = 0;
+ $current_uppercat = $row['id_uppercat'];
+ }
+ ++$current_rank;
+ $cat =
+ array(
+ 'rank' => $current_rank,
+ 'rank_changed' =>$current_rank!=$row['rank'],
+ 'global_rank' => $row['global_rank'],
+ 'uppercats' => $row['uppercats'],
+ );
+ $cat_map[ $row['id'] ] = $cat;
}
$datas = array();
- foreach ($uppercats_array as $id => $uppercats)
+
+ foreach( $cat_map as $id=>$cat )
{
- array_push(
- $datas,
- array(
- 'id' => $id,
- 'global_rank' => preg_replace(
+ $new_global_rank = preg_replace(
'/(\d+)/e',
- "\$ranks_array['$1']",
- str_replace(',', '.', $uppercats)
- ),
- )
- );
+ "\$cat_map['$1']['rank']",
+ str_replace(',', '.', $cat['uppercats'] )
+ );
+ if ( $cat['rank_changed']
+ or $new_global_rank!=$cat['global_rank']
+ )
+ {
+ $datas[] = array(
+ 'id' => $id,
+ 'rank' => $cat['rank'],
+ 'global_rank' => $new_global_rank,
+ );
+ }
}
mass_updates(
CATEGORIES_TABLE,
array(
'primary' => array('id'),
- 'update' => array('global_rank')
+ 'update' => array('rank', 'global_rank')
),
$datas
);
+ return count($datas);
}
/**
@@ -876,43 +879,6 @@ SELECT image_id
}
/**
- * order categories (update categories.rank and global_rank database fields)
- *
- * the purpose of this function is to give a rank for all categories
- * (insides its sub-category), even the newer that have none at te
- * beginning. For this, ordering function selects all categories ordered by
- * rank ASC then name ASC for each uppercat.
- *
- * @returns void
- */
-function ordering()
-{
- $current_rank = 0;
- $current_uppercat = '';
-
- $query = '
-SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat
- FROM '.CATEGORIES_TABLE.'
- ORDER BY id_uppercat,rank,name
-;';
- $result = pwg_query($query);
- $datas = array();
- while ($row = mysql_fetch_array($result))
- {
- if ($row['id_uppercat'] != $current_uppercat)
- {
- $current_rank = 0;
- $current_uppercat = $row['id_uppercat'];
- }
- $data = array('id' => $row['id'], 'rank' => ++$current_rank);
- array_push($datas, $data);
- }
-
- $fields = array('primary' => array('id'), 'update' => array('rank'));
- mass_updates(CATEGORIES_TABLE, $fields, $datas);
-}
-
-/**
* returns the fulldir for each given category id
*
* @param array cat_ids
@@ -1352,7 +1318,6 @@ UPDATE '.CATEGORIES_TABLE.'
pwg_query($query);
update_uppercats();
- ordering();
update_global_rank();
// status and related permissions management
diff --git a/admin/maintenance.php b/admin/maintenance.php
index a9733f31d..69268cf2c 100644
--- a/admin/maintenance.php
+++ b/admin/maintenance.php
@@ -45,7 +45,6 @@ switch ($action)
{
update_uppercats();
update_category('all');
- ordering();
update_global_rank();
invalidate_user_cache();
break;
diff --git a/admin/site_update.php b/admin/site_update.php
index 934366808..8dcf601d2 100644
--- a/admin/site_update.php
+++ b/admin/site_update.php
@@ -446,9 +446,9 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
continue;
}
- if ( isset( $conf['flip_picture_ext'][get_extension($filename)] )
+ if ( isset( $conf['flip_picture_ext'][get_extension($filename)] )
and !isset($fs[$path]['tn_ext']) )
- { // For a picture thumbnail is mandatory and for non picture element,
+ { // For a picture thumbnail is mandatory and for non picture element,
// thumbnail and representative are optionnal
array_push(
$errors,
@@ -470,7 +470,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
: null,
'storage_category_id' => $db_fulldirs[$dirname],
);
-
+
if ( $_POST['privacy_level']!=0 )
{
$insert['level'] = $_POST['privacy_level'];
@@ -621,7 +621,6 @@ if (isset($_POST['submit'])
. get_elapsed_time($start,get_moment())
. ' -->' );
$start = get_moment();
- ordering();
update_global_rank();
$template->append('footer_elements', '<!-- ordering categories : '
. get_elapsed_time($start, get_moment())