From bd833ee9bcd52d7e5c1cc52c220ead224beb1225 Mon Sep 17 00:00:00 2001 From: rvelices Date: Fri, 29 Aug 2008 12:35:16 +0000 Subject: synchro improvements: - able to sync metadata at the same time as the files/dirs - by default empty metadata does not overwrite database infos (checkbox can switch to previous behaviour) (bug 132) - the form is shown again even after a successfull non simulated run git-svn-id: http://piwigo.org/svn/trunk@2491 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/functions.php | 215 +++++++++++++++++++++----------------------- 1 file changed, 101 insertions(+), 114 deletions(-) (limited to 'admin/include/functions.php') diff --git a/admin/include/functions.php b/admin/include/functions.php index db95ab383..e700d662e 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -377,7 +377,7 @@ function mass_inserts($table_name, $dbfields, $datas) { $first = true; - $query = 'SHOW VARIABLES LIKE \'max_allowed_packet\';'; + $query = 'SHOW VARIABLES LIKE \'max_allowed_packet\''; list(, $packet_size) = mysql_fetch_row(pwg_query($query)); $packet_size = $packet_size - 2000; // The last list of values MUST not exceed 2000 character*/ $query = ''; @@ -386,8 +386,6 @@ function mass_inserts($table_name, $dbfields, $datas) { if (strlen($query) >= $packet_size) { - $query .= ' -;'; pwg_query($query); $first = true; } @@ -425,57 +423,53 @@ INSERT INTO '.$table_name.' } $query .= ')'; } - - $query .= ' -;'; pwg_query($query); } } +define('MASS_UPDATES_SKIP_EMPTY', 1); /** * updates multiple lines in a table * * @param string table_name * @param array dbfields * @param array datas + * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones * @return void */ -function mass_updates($tablename, $dbfields, $datas) +function mass_updates($tablename, $dbfields, $datas, $flags=0) { - if (count($datas) != 0) - { - // depending on the MySQL version, we use the multi table update or N - // update queries - if (count($datas) < 10 or version_compare(mysql_get_server_info(), '4.0.4') < 0) + if (count($datas) == 0) + return; + // depending on the MySQL version, we use the multi table update or N update queries + if (count($datas) < 10 or version_compare(mysql_get_server_info(), '4.0.4') < 0) + { // MySQL is prior to version 4.0.4, multi table update feature is not available + foreach ($datas as $data) { - // MySQL is prior to version 4.0.4, multi table update feature is not - // available - foreach ($datas as $data) - { - $query = ' + $query = ' UPDATE '.$tablename.' SET '; - $is_first = true; - foreach ($dbfields['update'] as $key) + $is_first = true; + foreach ($dbfields['update'] as $key) + { + $separator = $is_first ? '' : ",\n "; + + if (isset($data[$key]) and $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; + $query.= $separator.$key.' = \''.$data[$key].'\''; + } + else + { + if ($flags & MASS_UPDATES_SKIP_EMPTY ) + continue; // next field + $query.= "$separator$key = NULL"; } + $is_first = false; + } + if (!$is_first) + {// only if one field at least updated $query.= ' WHERE '; - $is_first = true; foreach ($dbfields['primary'] as $key) { @@ -493,87 +487,83 @@ UPDATE '.$tablename.' } $is_first = false; } - $query.= ' -;'; pwg_query($query); } - } - else + } // foreach update + } // if mysql_ver or count all its child categories become locked @@ -678,8 +667,7 @@ UPDATE '.CATEGORIES_TABLE.' $query = ' UPDATE '.CATEGORIES_TABLE.' SET visible = \'false\' - WHERE id IN ('.implode(',', $subcats).') -;'; + WHERE id IN ('.implode(',', $subcats).')'; pwg_query($query); } } @@ -695,6 +683,7 @@ function set_cat_status($categories, $value) { if (!in_array($value, array('public', 'private'))) { + trigger_error("set_cat_status invalid param $value", E_USER_WARNING); return false; } @@ -716,8 +705,7 @@ UPDATE '.CATEGORIES_TABLE.' $query = ' UPDATE '.CATEGORIES_TABLE.' SET status = \'private\' - WHERE id IN ('.implode(',', $subcats).') -;'; + WHERE id IN ('.implode(',', $subcats).')'; pwg_query($query); } } @@ -1582,7 +1570,7 @@ function do_maintenance_all_tables() $all_tables = array(); // List all tables - $query = 'SHOW TABLES LIKE \''.$prefixeTable.'%\';'; + $query = 'SHOW TABLES LIKE \''.$prefixeTable.'%\''; $result = pwg_query($query); while ($row = mysql_fetch_array($result)) { @@ -1590,7 +1578,7 @@ function do_maintenance_all_tables() } // Repair all tables - $query = 'REPAIR TABLE '.implode(', ', $all_tables).';'; + $query = 'REPAIR TABLE '.implode(', ', $all_tables); $mysql_rc = pwg_query($query); // Re-Order all tables @@ -1616,7 +1604,7 @@ function do_maintenance_all_tables() } // Optimize all tables - $query = 'OPTIMIZE TABLE '.implode(', ', $all_tables).';'; + $query = 'OPTIMIZE TABLE '.implode(', ', $all_tables); $mysql_rc = $mysql_rc && pwg_query($query); if ($mysql_rc) { @@ -1832,8 +1820,7 @@ function invalidate_user_cache() { $query = ' UPDATE '.USER_CACHE_TABLE.' - SET need_update = \'true\' -;'; + SET need_update = \'true\''; pwg_query($query); trigger_action('invalidate_user_cache'); } -- cgit v1.2.3