Changeset 672


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)
Location:
trunk
Files:
6 added
6 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?>
  • trunk/include/functions.inc.php

    r667 r672  
    487487function pwg_query($query)
    488488{
    489   global $conf,$count_queries,$queries_time;
     489  global $conf,$page;
    490490 
    491491  $start = get_moment();
    492   $result = mysql_query($query);
     492  $result = mysql_query($query) or my_error($query."\n");
    493493 
    494494  $time = get_moment() - $start;
    495   $count_queries++;
    496   $queries_time+= $time;
     495
     496  if (!isset($page['count_queries']))
     497  {
     498    $page['count_queries'] = 0;
     499    $page['queries_time'] = 0;
     500  }
     501 
     502  $page['count_queries']++;
     503  $page['queries_time']+= $time;
    497504 
    498505  if ($conf['show_queries'])
    499506  {
    500507    $output = '';
    501     $output.= '<pre>['.$count_queries.'] '."\n".$query;
    502     $output.= "\n".'(this query time : '.number_format( $time, 3, '.', ' ').' s)</b>';
    503     $output.= "\n".'(total SQL time  : '.number_format( $queries_time, 3, '.', ' ').' s)';
     508    $output.= '<pre>['.$page['count_queries'].'] ';
     509    $output.= "\n".$query;
     510    $output.= "\n".'(this query time : ';
     511    $output.= number_format($time, 3, '.', ' ').' s)</b>';
     512    $output.= "\n".'(total SQL time  : ';
     513    $output.= number_format($page['queries_time'], 3, '.', ' ').' s)';
    504514    $output.= '</pre>';
    505515   
     
    625635  return $src;
    626636}
     637
     638// my_error returns (or send to standard output) the message concerning the
     639// error occured for the last mysql query.
     640function my_error($header, $echo = true)
     641{
     642  $error = '<pre>';
     643  $error.= $header;
     644  $error.= '[mysql error '.mysql_errno().'] ';
     645  $error.= mysql_error();
     646  $error.= '</pre>';
     647  if ($echo)
     648  {
     649    echo $error;
     650  }
     651  else
     652  {
     653    return $error;
     654  }
     655}
    627656?>
  • trunk/include/functions_category.inc.php

    r657 r672  
    222222  $cat['comment'] = nl2br($cat['comment']);
    223223
    224   $cat['name'] = array();
    225 
     224  $names = array();
    226225  $query = '
    227226SELECT name,id
    228227  FROM '.CATEGORIES_TABLE.'
    229228  WHERE id IN ('.$cat['uppercats'].')
    230   ORDER BY id ASC
    231229;';
    232230  $result = pwg_query($query);
    233231  while($row = mysql_fetch_array($result))
    234232  {
    235     $cat['name'][$row['id']] = $row['name'];
     233    $names[$row['id']] = $row['name'];
     234  }
     235
     236  // category names must be in the same order than uppercats list
     237  $cat['name'] = array();
     238  foreach (explode(',', $cat['uppercats']) as $cat_id)
     239  {
     240    $cat['name'][$cat_id] = $names[$cat_id];
    236241  }
    237242 
  • trunk/include/functions_user.inc.php

    r661 r672  
    209209function setup_style($style)
    210210{
    211   $template_path = 'template/' ;
    212   $template_name = $style ;
    213   $template = new Template(PHPWG_ROOT_PATH . $template_path . $template_name);
    214   return $template;
     211  return new Template(PHPWG_ROOT_PATH.'template/'.$style);
    215212}
    216213
  • trunk/include/page_tail.php

    r660 r672  
    4343  $time = get_elapsed_time($t2, get_moment());
    4444
    45   if (!isset($count_queries))
     45  if (!isset($page['count_queries']))
    4646  {
    47     $count_queries = 0;
    48     $queries_time = 0;
     47    $page['count_queries'] = 0;
     48    $page['queries_time'] = 0;
    4949  }
    5050 
     
    5252    'debug',
    5353    array('TIME' => $time,
    54           'NB_QUERIES' => $count_queries,
    55           'SQL_TIME' => number_format($queries_time, 3, '.', ' ').' s'));
     54          'NB_QUERIES' => $page['count_queries'],
     55          'SQL_TIME' => number_format($page['queries_time'],3,'.',' ').' s'));
    5656}
    5757
  • trunk/install/config.sql

    r653 r672  
    2121INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('recent_period','7','Period within which pictures are displayed as new (in days)');
    2222INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('auto_expand','false','Auto expand of the category tree');
    23 INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('show_nb_comments','true','Show the number of comments under the thumbnails');
     23INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('show_nb_comments','false','Show the number of comments under the thumbnails');
    2424INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('use_iptc','false','Use IPTC data during database synchronization with files metadata');
    2525INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('use_exif','true','Use EXIF data during database synchronization with files metadata');
Note: See TracChangeset for help on using the changeset viewer.