mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-07-13 21:31:35 +02:00
merge r 2306 from trunk to branch-1_7
- merged function ordering() with update_global_rank() and also optimized the queries git-svn-id: http://piwigo.org/svn/branches/branch-1_7@2307 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
+2
-3
@@ -60,7 +60,7 @@ function save_categories_order($categories)
|
|||||||
$fields = array('primary' => array('id'), 'update' => array('rank'));
|
$fields = array('primary' => array('id'), 'update' => array('rank'));
|
||||||
mass_updates(CATEGORIES_TABLE, $fields, $datas);
|
mass_updates(CATEGORIES_TABLE, $fields, $datas);
|
||||||
|
|
||||||
update_global_rank(@$_GET['parent_id']);
|
update_global_rank();
|
||||||
}
|
}
|
||||||
|
|
||||||
// +-----------------------------------------------------------------------+
|
// +-----------------------------------------------------------------------+
|
||||||
@@ -82,7 +82,6 @@ if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser())
|
|||||||
{
|
{
|
||||||
delete_categories(array($_GET['delete']));
|
delete_categories(array($_GET['delete']));
|
||||||
array_push($page['infos'], l10n('cat_virtual_deleted'));
|
array_push($page['infos'], l10n('cat_virtual_deleted'));
|
||||||
ordering();
|
|
||||||
update_global_rank();
|
update_global_rank();
|
||||||
}
|
}
|
||||||
// request to add a virtual category
|
// request to add a virtual category
|
||||||
@@ -294,7 +293,7 @@ foreach ($categories as $category)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add a link to Page bottom only if needed (10 or more categories)
|
// Add a link to Page bottom only if needed (10 or more categories)
|
||||||
if ( isset($category['rank']) and $category['rank'] > 9 )
|
if ( isset($category['rank']) and $category['rank'] > 9 )
|
||||||
{
|
{
|
||||||
$template->assign_block_vars('eop_link', array('ICON'=>'Displayed'));
|
$template->assign_block_vars('eop_link', array('ICON'=>'Displayed'));
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-76
@@ -683,69 +683,72 @@ function mass_updates($tablename, $dbfields, $datas)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updates the global_rank of categories under the given 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
|
||||||
* @param int id_uppercat
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function update_global_rank($id_uppercat = 'all')
|
function update_global_rank()
|
||||||
{
|
{
|
||||||
$query = '
|
$query = '
|
||||||
SELECT id,rank
|
SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat, uppercats, rank, global_rank
|
||||||
FROM '.CATEGORIES_TABLE.'
|
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 ?
|
$cat_map = array();
|
||||||
$uppercats_array = 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);
|
$result = pwg_query($query);
|
||||||
while ($row = mysql_fetch_array($result))
|
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();
|
$datas = array();
|
||||||
foreach ($uppercats_array as $id => $uppercats)
|
|
||||||
|
foreach( $cat_map as $id=>$cat )
|
||||||
{
|
{
|
||||||
array_push(
|
$new_global_rank = preg_replace(
|
||||||
$datas,
|
|
||||||
array(
|
|
||||||
'id' => $id,
|
|
||||||
'global_rank' => preg_replace(
|
|
||||||
'/(\d+)/e',
|
'/(\d+)/e',
|
||||||
"\$ranks_array['$1']",
|
"\$cat_map['$1']['rank']",
|
||||||
str_replace(',', '.', $uppercats)
|
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(
|
mass_updates(
|
||||||
CATEGORIES_TABLE,
|
CATEGORIES_TABLE,
|
||||||
array(
|
array(
|
||||||
'primary' => array('id'),
|
'primary' => array('id'),
|
||||||
'update' => array('global_rank')
|
'update' => array('rank', 'global_rank')
|
||||||
),
|
),
|
||||||
$datas
|
$datas
|
||||||
);
|
);
|
||||||
|
return count($datas);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -893,43 +896,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
|
* returns the fulldir for each given category id
|
||||||
*
|
*
|
||||||
@@ -1370,7 +1336,6 @@ UPDATE '.CATEGORIES_TABLE.'
|
|||||||
pwg_query($query);
|
pwg_query($query);
|
||||||
|
|
||||||
update_uppercats();
|
update_uppercats();
|
||||||
ordering();
|
|
||||||
update_global_rank();
|
update_global_rank();
|
||||||
|
|
||||||
// status and related permissions management
|
// status and related permissions management
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ switch ($action)
|
|||||||
{
|
{
|
||||||
update_uppercats();
|
update_uppercats();
|
||||||
update_category('all');
|
update_category('all');
|
||||||
ordering();
|
|
||||||
update_global_rank();
|
update_global_rank();
|
||||||
invalidate_user_cache();
|
invalidate_user_cache();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id
|
|||||||
|
|
||||||
// If $_POST['subcats-included'] != 1 ("Search in subcategories" is unchecked)
|
// If $_POST['subcats-included'] != 1 ("Search in subcategories" is unchecked)
|
||||||
// $db_fulldirs doesn't include any subdirectories and $fs_fulldirs does
|
// $db_fulldirs doesn't include any subdirectories and $fs_fulldirs does
|
||||||
// So $fs_fulldirs will be limited to the selected basedir
|
// So $fs_fulldirs will be limited to the selected basedir
|
||||||
// (if that one is in $fs_fulldirs)
|
// (if that one is in $fs_fulldirs)
|
||||||
if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
|
if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
|
||||||
{
|
{
|
||||||
@@ -253,7 +253,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id
|
|||||||
// print_r( array_diff($fs_fulldirs, array_keys($db_fulldirs)) ); echo "<br>";
|
// print_r( array_diff($fs_fulldirs, array_keys($db_fulldirs)) ); echo "<br>";
|
||||||
// die('That\'s why dirs or files synchronizations were duplicating cats.');
|
// die('That\'s why dirs or files synchronizations were duplicating cats.');
|
||||||
|
|
||||||
$inserts = array();
|
$inserts = array();
|
||||||
// new categories are the directories not present yet in the database
|
// new categories are the directories not present yet in the database
|
||||||
foreach (array_diff($fs_fulldirs, array_keys($db_fulldirs)) as $fulldir)
|
foreach (array_diff($fs_fulldirs, array_keys($db_fulldirs)) as $fulldir)
|
||||||
{
|
{
|
||||||
@@ -670,7 +670,6 @@ if (isset($_POST['submit'])
|
|||||||
echo get_elapsed_time($start,get_moment());
|
echo get_elapsed_time($start,get_moment());
|
||||||
echo ' -->'."\n";
|
echo ' -->'."\n";
|
||||||
$start = get_moment();
|
$start = get_moment();
|
||||||
ordering();
|
|
||||||
update_global_rank();
|
update_global_rank();
|
||||||
echo '<!-- ordering categories : ';
|
echo '<!-- ordering categories : ';
|
||||||
echo get_elapsed_time($start, get_moment());
|
echo get_elapsed_time($start, get_moment());
|
||||||
@@ -828,14 +827,14 @@ SELECT id
|
|||||||
array_push($has_high_images, $row['id']);
|
array_push($has_high_images, $row['id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $files as $id=>$file )
|
foreach ( $files as $id=>$file )
|
||||||
{
|
{
|
||||||
$data = $site_reader->get_element_metadata(
|
$data = $site_reader->get_element_metadata(
|
||||||
$file,
|
$file,
|
||||||
in_array($id, $has_high_images)
|
in_array($id, $has_high_images)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( is_array($data) )
|
if ( is_array($data) )
|
||||||
{
|
{
|
||||||
$data['date_metadata_update'] = CURRENT_DATE;
|
$data['date_metadata_update'] = CURRENT_DATE;
|
||||||
@@ -872,7 +871,7 @@ SELECT id
|
|||||||
if (count($datas) > 0)
|
if (count($datas) > 0)
|
||||||
{
|
{
|
||||||
// echo '<pre>', print_r($datas); echo '</pre>';
|
// echo '<pre>', print_r($datas); echo '</pre>';
|
||||||
|
|
||||||
mass_updates(
|
mass_updates(
|
||||||
IMAGES_TABLE,
|
IMAGES_TABLE,
|
||||||
// fields
|
// fields
|
||||||
|
|||||||
+10
-11
@@ -71,7 +71,7 @@ ALTER TABLE phpwebgallery_categories
|
|||||||
ALTER TABLE phpwebgallery_categories
|
ALTER TABLE phpwebgallery_categories
|
||||||
ADD COLUMN commentable enum('true','false') NOT NULL default 'true'
|
ADD COLUMN commentable enum('true','false') NOT NULL default 'true'
|
||||||
;",
|
;",
|
||||||
|
|
||||||
"
|
"
|
||||||
ALTER TABLE phpwebgallery_categories
|
ALTER TABLE phpwebgallery_categories
|
||||||
ADD COLUMN global_rank varchar(255) default NULL
|
ADD COLUMN global_rank varchar(255) default NULL
|
||||||
@@ -91,7 +91,7 @@ ALTER TABLE phpwebgallery_comments
|
|||||||
UPDATE phpwebgallery_comments
|
UPDATE phpwebgallery_comments
|
||||||
SET date_temp = date
|
SET date_temp = date
|
||||||
;",
|
;",
|
||||||
|
|
||||||
"
|
"
|
||||||
ALTER TABLE phpwebgallery_comments
|
ALTER TABLE phpwebgallery_comments
|
||||||
CHANGE COLUMN date date datetime NOT NULL default '0000-00-00 00:00:00'
|
CHANGE COLUMN date date datetime NOT NULL default '0000-00-00 00:00:00'
|
||||||
@@ -126,7 +126,7 @@ ALTER TABLE phpwebgallery_history
|
|||||||
UPDATE phpwebgallery_history
|
UPDATE phpwebgallery_history
|
||||||
SET date_temp = date
|
SET date_temp = date
|
||||||
;",
|
;",
|
||||||
|
|
||||||
"
|
"
|
||||||
ALTER TABLE phpwebgallery_history
|
ALTER TABLE phpwebgallery_history
|
||||||
CHANGE COLUMN date date datetime NOT NULL default '0000-00-00 00:00:00'
|
CHANGE COLUMN date date datetime NOT NULL default '0000-00-00 00:00:00'
|
||||||
@@ -207,7 +207,7 @@ ALTER TABLE phpwebgallery_images
|
|||||||
ALTER TABLE phpwebgallery_images
|
ALTER TABLE phpwebgallery_images
|
||||||
ADD INDEX images_i5 (date_creation)
|
ADD INDEX images_i5 (date_creation)
|
||||||
;",
|
;",
|
||||||
|
|
||||||
"
|
"
|
||||||
ALTER TABLE phpwebgallery_sessions
|
ALTER TABLE phpwebgallery_sessions
|
||||||
DROP COLUMN ip
|
DROP COLUMN ip
|
||||||
@@ -222,7 +222,7 @@ ALTER TABLE phpwebgallery_sessions
|
|||||||
UPDATE phpwebgallery_sessions
|
UPDATE phpwebgallery_sessions
|
||||||
SET expiration_temp = expiration
|
SET expiration_temp = expiration
|
||||||
;",
|
;",
|
||||||
|
|
||||||
"
|
"
|
||||||
ALTER TABLE phpwebgallery_sessions
|
ALTER TABLE phpwebgallery_sessions
|
||||||
CHANGE COLUMN expiration expiration datetime NOT NULL default '0000-00-00 00:00:00'
|
CHANGE COLUMN expiration expiration datetime NOT NULL default '0000-00-00 00:00:00'
|
||||||
@@ -237,7 +237,7 @@ UPDATE phpwebgallery_sessions
|
|||||||
ALTER TABLE phpwebgallery_sessions
|
ALTER TABLE phpwebgallery_sessions
|
||||||
DROP COLUMN expiration_temp
|
DROP COLUMN expiration_temp
|
||||||
;",
|
;",
|
||||||
|
|
||||||
"
|
"
|
||||||
ALTER TABLE phpwebgallery_sites
|
ALTER TABLE phpwebgallery_sites
|
||||||
DROP INDEX galleries_url
|
DROP INDEX galleries_url
|
||||||
@@ -251,7 +251,7 @@ ALTER TABLE phpwebgallery_sites
|
|||||||
"
|
"
|
||||||
DROP TABLE phpwebgallery_user_category
|
DROP TABLE phpwebgallery_user_category
|
||||||
;",
|
;",
|
||||||
|
|
||||||
"
|
"
|
||||||
ALTER TABLE phpwebgallery_users
|
ALTER TABLE phpwebgallery_users
|
||||||
DROP COLUMN long_period
|
DROP COLUMN long_period
|
||||||
@@ -276,7 +276,7 @@ ALTER TABLE phpwebgallery_users
|
|||||||
ALTER TABLE phpwebgallery_users
|
ALTER TABLE phpwebgallery_users
|
||||||
ADD UNIQUE users_ui1 (username)
|
ADD UNIQUE users_ui1 (username)
|
||||||
;",
|
;",
|
||||||
|
|
||||||
"
|
"
|
||||||
CREATE TABLE phpwebgallery_rate (
|
CREATE TABLE phpwebgallery_rate (
|
||||||
user_id smallint(5) unsigned NOT NULL default '0',
|
user_id smallint(5) unsigned NOT NULL default '0',
|
||||||
@@ -342,7 +342,7 @@ $indexes_of = array(
|
|||||||
foreach (array_keys($indexes_of) as $table)
|
foreach (array_keys($indexes_of) as $table)
|
||||||
{
|
{
|
||||||
$existing_indexes = array();
|
$existing_indexes = array();
|
||||||
|
|
||||||
$query = '
|
$query = '
|
||||||
SHOW INDEX
|
SHOW INDEX
|
||||||
FROM '.PREFIX_TABLE.$table.'
|
FROM '.PREFIX_TABLE.$table.'
|
||||||
@@ -529,7 +529,6 @@ mass_inserts(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// refresh calculated datas
|
// refresh calculated datas
|
||||||
ordering();
|
|
||||||
update_global_rank();
|
update_global_rank();
|
||||||
update_category();
|
update_category();
|
||||||
|
|
||||||
@@ -587,7 +586,7 @@ $page['infos'] = array_merge(
|
|||||||
$page['infos'],
|
$page['infos'],
|
||||||
array(
|
array(
|
||||||
'all sub-categories of private categories become private',
|
'all sub-categories of private categories become private',
|
||||||
|
|
||||||
'user permissions and group permissions have been erased',
|
'user permissions and group permissions have been erased',
|
||||||
|
|
||||||
'only thumbnails prefix and webmaster mail address have been saved from
|
'only thumbnails prefix and webmaster mail address have been saved from
|
||||||
|
|||||||
Reference in New Issue
Block a user