From 63638b9b6dcdcef8baf5363419f0f6c5130c62df Mon Sep 17 00:00:00 2001 From: rub Date: Fri, 1 Dec 2006 23:31:19 +0000 Subject: Resolved Issue ID 0000299: o Add (new) icon of parent category with children categories including new images o Improved display text for images count o Improved (a little) mass_* functions More explications on the forum. You must call directly upgrade_feep.php (http://127.0.0.1/BSF/upgrade_feed.php for example) git-svn-id: http://piwigo.org/svn/trunk@1624 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/functions.php | 258 +++++++++++++++++++++++--------------------- 1 file changed, 136 insertions(+), 122 deletions(-) (limited to 'admin') diff --git a/admin/include/functions.php b/admin/include/functions.php index bbd5ee80f..1aec5b1db 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -257,6 +257,13 @@ DELETE FROM '.USER_CACHE_TABLE.' ;'; pwg_query($query); + // deletion of computed cache data linked to the user + $query = ' +DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.' + WHERE user_id = '.$user_id.' +;'; + pwg_query($query); + // deletion of phpwebgallery specific informations $query = ' DELETE FROM '.USER_INFOS_TABLE.' @@ -514,41 +521,44 @@ function get_fs_directories($path, $recursive = true) */ function mass_inserts($table_name, $dbfields, $datas) { - // inserts all found categories - $query = ' -INSERT INTO '.$table_name.' - ('.implode(',', $dbfields).') - VALUES'; - foreach ($datas as $insert_id => $insert) + if (count($datas) != 0) { - $query.= ' - '; - if ($insert_id > 0) - { - $query.= ','; - } - $query.= '('; - foreach ($dbfields as $field_id => $dbfield) + // inserts all found categories + $query = ' + INSERT INTO '.$table_name.' + ('.implode(',', $dbfields).') + VALUES'; + foreach ($datas as $insert_id => $insert) { - if ($field_id > 0) + $query.= ' + '; + if ($insert_id > 0) { $query.= ','; } - - if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') - { - $query.= 'NULL'; - } - else + $query.= '('; + foreach ($dbfields as $field_id => $dbfield) { - $query.= "'".$insert[$dbfield]."'"; + if ($field_id > 0) + { + $query.= ','; + } + + if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') + { + $query.= 'NULL'; + } + else + { + $query.= "'".$insert[$dbfield]."'"; + } } + $query.=')'; } - $query.=')'; - } - $query.= ' + $query.= ' ;'; - pwg_query($query); + pwg_query($query); + } } /** @@ -561,119 +571,122 @@ INSERT INTO '.$table_name.' */ function mass_updates($tablename, $dbfields, $datas) { - // depending on the MySQL version, we use the multi table update or N - // update queries - $query = 'SELECT VERSION() AS version;'; - list($mysql_version) = mysql_fetch_array(pwg_query($query)); - if (count($datas) < 10 or version_compare($mysql_version, '4.0.4') < 0) - { - // MySQL is prior to version 4.0.4, multi table update feature is not - // available - foreach ($datas as $data) + if (count($datas) != 0) + { + // depending on the MySQL version, we use the multi table update or N + // update queries + $query = 'SELECT VERSION() AS version;'; + list($mysql_version) = mysql_fetch_array(pwg_query($query)); + if (count($datas) < 10 or version_compare($mysql_version, '4.0.4') < 0) { - $query = ' -UPDATE '.$tablename.' - SET '; - $is_first = true; - foreach ($dbfields['update'] as $num => $key) + // MySQL is prior to version 4.0.4, multi table update feature is not + // available + foreach ($datas as $data) { - if (!$is_first) - { - $query.= ",\n "; - } - $query.= $key.' = '; - if (isset($data[$key]) and $data[$key] != '') + $query = ' + UPDATE '.$tablename.' + SET '; + $is_first = true; + foreach ($dbfields['update'] as $num => $key) { - $query.= '\''.$data[$key].'\''; + if (!$is_first) + { + $query.= ",\n "; + } + $query.= $key.' = '; + if (isset($data[$key]) and $data[$key] != '') + { + $query.= '\''.$data[$key].'\''; + } + else + { + $query.= 'NULL'; + } + $is_first = false; } - else + $query.= ' + WHERE '; + foreach ($dbfields['primary'] as $num => $key) { - $query.= 'NULL'; - } - $is_first = false; - } - $query.= ' - WHERE '; - foreach ($dbfields['primary'] as $num => $key) - { - if ($num > 1) - { - $query.= ' AND '; + if ($num > 1) + { + $query.= ' AND '; + } + $query.= $key.' = \''.$data[$key].'\''; } - $query.= $key.' = \''.$data[$key].'\''; + $query.= ' + ;'; + pwg_query($query); } - $query.= ' -;'; - pwg_query($query); } - } - else - { - // creation of the temporary table - $query = ' -SHOW FULL COLUMNS FROM '.$tablename.' -;'; - $result = pwg_query($query); - $columns = array(); - $all_fields = array_merge($dbfields['primary'], $dbfields['update']); - while ($row = mysql_fetch_array($result)) + else { - if (in_array($row['Field'], $all_fields)) + // creation of the temporary table + $query = ' + SHOW FULL COLUMNS FROM '.$tablename.' +;'; + $result = pwg_query($query); + $columns = array(); + $all_fields = array_merge($dbfields['primary'], $dbfields['update']); + while ($row = mysql_fetch_array($result)) { - $column = $row['Field']; - $column.= ' '.$row['Type']; - if (!isset($row['Null']) or $row['Null'] == '') + if (in_array($row['Field'], $all_fields)) { - $column.= ' NOT NULL'; - } - if (isset($row['Default'])) - { - $column.= " default '".$row['Default']."'"; - } - if (isset($row['Collation']) and $row['Collation'] != 'NULL') - { - $column.= " collate '".$row['Collation']."'"; + $column = $row['Field']; + $column.= ' '.$row['Type']; + if (!isset($row['Null']) or $row['Null'] == '') + { + $column.= ' NOT NULL'; + } + if (isset($row['Default'])) + { + $column.= " default '".$row['Default']."'"; + } + if (isset($row['Collation']) and $row['Collation'] != 'NULL') + { + $column.= " collate '".$row['Collation']."'"; + } + array_push($columns, $column); } - array_push($columns, $column); } - } - $temporary_tablename = $tablename.'_'.micro_seconds(); + $temporary_tablename = $tablename.'_'.micro_seconds(); - $query = ' -CREATE TABLE '.$temporary_tablename.' -( -'.implode(",\n", $columns).', -PRIMARY KEY ('.implode(',', $dbfields['primary']).') -) -;'; - pwg_query($query); - mass_inserts($temporary_tablename, $all_fields, $datas); - // update of images table by joining with temporary table - $query = ' -UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2 - SET '. - implode( - "\n , ", - array_map( - create_function('$s', 'return "t1.$s = t2.$s";'), - $dbfields['update'] - ) - ).' - WHERE '. - implode( - "\n AND ", - array_map( - create_function('$s', 'return "t1.$s = t2.$s";'), - $dbfields['primary'] - ) - ).' + $query = ' + CREATE TABLE '.$temporary_tablename.' + ( + '.implode(",\n", $columns).', + PRIMARY KEY ('.implode(',', $dbfields['primary']).') + ) ;'; - pwg_query($query); - $query = ' -DROP TABLE '.$temporary_tablename.' + pwg_query($query); + mass_inserts($temporary_tablename, $all_fields, $datas); + // update of images table by joining with temporary table + $query = ' + UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2 + SET '. + implode( + "\n , ", + array_map( + create_function('$s', 'return "t1.$s = t2.$s";'), + $dbfields['update'] + ) + ).' + WHERE '. + implode( + "\n AND ", + array_map( + create_function('$s', 'return "t1.$s = t2.$s";'), + $dbfields['primary'] + ) + ).' + ;'; + pwg_query($query); + $query = ' + DROP TABLE '.$temporary_tablename.' ;'; - pwg_query($query); + pwg_query($query); + } } } @@ -1159,6 +1172,7 @@ SELECT user_id USER_INFOS_TABLE, USER_ACCESS_TABLE, USER_CACHE_TABLE, + USER_CACHE_CATEGORIES_TABLE, USER_GROUP_TABLE ); -- cgit v1.2.3