Ignore:
Timestamp:
Jan 6, 2005, 11:16:21 PM (19 years ago)
Author:
plg
Message:
  • upgrade scripts added for releases 1.3.x
  • my_error function moved from admin/include/functions.php to include/functions.inc.php
  • because MySQL temporary tables are not always authorized on creation, use a temporary table name (with the current microsecond) on a non temporary table (in mass_updates function)
  • ability to retrieve distant full directories (usefull in upgrade scripts)
  • global variables $count_queries and $queries_time moved into global array $page
  • get_cat_display_name displays category names in correct order : the one given by uppercats
  • function setup_style simplified
  • default value for configuration parameter "show_nb_comments" set to false (less queries by default)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r670 r672  
    768768}
    769769
    770 // my_error returns (or send to standard output) the message concerning the
    771 // error occured for the last mysql query.
    772 function my_error($header, $echo = true)
    773 {
    774   $error = $header.'<span style="font-weight:bold;">N°= '.mysql_errno();
    775   $error.= ' -->> '.mysql_error()."</span><br /><br />\n";
    776   if ($echo)
    777   {
    778     echo $error;
    779   }
    780   else
    781   {
    782     return $error;
    783   }
    784 }
    785 
    786770/**
    787771 * inserts multiple lines in a table
     
    911895      }
    912896    }
     897   
     898    $temporary_tablename = $tablename.'_'.micro_seconds();
     899   
    913900    $query = '
    914 CREATE TEMPORARY TABLE '.$tablename.'_temporary
     901CREATE TABLE '.$temporary_tablename.'
    915902(
    916903'.implode(",\n", $columns).',
     
    919906;';
    920907    pwg_query($query);
    921     mass_inserts($tablename.'_temporary', $all_fields, $datas);
     908    mass_inserts($temporary_tablename, $all_fields, $datas);
    922909    // update of images table by joining with temporary table
    923910    $query = '
    924 UPDATE '.$tablename.' AS t1, '.$tablename.'_temporary AS t2
     911UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2
    925912  SET '.implode("\n    , ",
    926913                array_map(
     
    934921    pwg_query($query);
    935922    $query = '
    936 DROP TABLE '.$tablename.'_temporary
     923DROP TABLE '.$temporary_tablename.'
    937924;';
    938925    pwg_query($query);
     
    11941181  }
    11951182
    1196   // filling $uppercats_array : to each category id the uppercats list is
    1197   // associated
    1198   $uppercats_array = array();
    1199  
    1200   $query = '
    1201 SELECT id, uppercats
     1183  // caching galleries_url
     1184  $query = '
     1185SELECT id, galleries_url
     1186  FROM '.SITES_TABLE.'
     1187;';
     1188  $result = pwg_query($query);
     1189  $galleries_url = array();
     1190  while ($row = mysql_fetch_array($result))
     1191  {
     1192    $galleries_url[$row['id']] = $row['galleries_url'];
     1193  }
     1194
     1195  // categories : id, site_id, uppercats
     1196  $categories = array();
     1197 
     1198  $query = '
     1199SELECT id, uppercats, site_id
    12021200  FROM '.CATEGORIES_TABLE.'
    12031201  WHERE id IN (
     
    12071205  while ($row = mysql_fetch_array($result))
    12081206  {
    1209     $uppercats_array[$row['id']] = $row['uppercats'];
    1210   }
    1211  
    1212   $query = '
    1213 SELECT galleries_url
    1214   FROM '.SITES_TABLE.'
    1215   WHERE id = 1
    1216 ';
    1217   $row = mysql_fetch_array(pwg_query($query));
    1218   $basedir = $row['galleries_url'];
     1207    array_push($categories, $row);
     1208  }
    12191209 
    12201210  // filling $cat_fulldirs
    12211211  $cat_fulldirs = array();
    1222   foreach ($uppercats_array as $cat_id => $uppercats)
    1223   {
    1224     $uppercats = str_replace(',', '/', $uppercats);
    1225     $cat_fulldirs[$cat_id] = $basedir.preg_replace('/(\d+)/e',
    1226                                                    "\$cat_dirs['$1']",
    1227                                                    $uppercats);
     1212  foreach ($categories as $category)
     1213  {
     1214    $uppercats = str_replace(',', '/', $category['uppercats']);
     1215    $cat_fulldirs[$category['id']] = $galleries_url[$category['site_id']];
     1216    $cat_fulldirs[$category['id']].= preg_replace('/(\d+)/e',
     1217                                                  "\$cat_dirs['$1']",
     1218                                                  $uppercats);
    12281219  }
    12291220
     
    13181309  return $fs;
    13191310}
     1311
     1312/**
     1313 * stupidly returns the current microsecond since Unix epoch
     1314 */
     1315function micro_seconds()
     1316{
     1317  $t1 = explode(' ', microtime());
     1318  $t2 = explode('.', $t1[0]);
     1319  $t2 = $t1[1].substr($t2[1], 0, 6);
     1320  return $t2;
     1321}
    13201322?>
Note: See TracChangeset for help on using the changeset viewer.