Ignore:
Timestamp:
Dec 2, 2006, 12:31:19 AM (17 years ago)
Author:
rub
Message:

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)

File:
1 edited

Legend:

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

    r1605 r1624  
    258258  pwg_query($query);
    259259
     260  // deletion of computed cache data linked to the user
     261  $query = '
     262DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
     263  WHERE user_id = '.$user_id.'
     264;';
     265  pwg_query($query);
     266
    260267  // deletion of phpwebgallery specific informations
    261268  $query = '
     
    515522function mass_inserts($table_name, $dbfields, $datas)
    516523{
    517   // inserts all found categories
    518   $query = '
    519 INSERT INTO '.$table_name.'
    520   ('.implode(',', $dbfields).')
    521    VALUES';
    522   foreach ($datas as $insert_id => $insert)
    523   {
    524     $query.= '
    525   ';
    526     if ($insert_id > 0)
    527     {
    528       $query.= ',';
    529     }
    530     $query.= '(';
    531     foreach ($dbfields as $field_id => $dbfield)
    532     {
    533       if ($field_id > 0)
     524  if (count($datas) != 0)
     525  {
     526    // inserts all found categories
     527    $query = '
     528  INSERT INTO '.$table_name.'
     529    ('.implode(',', $dbfields).')
     530     VALUES';
     531    foreach ($datas as $insert_id => $insert)
     532    {
     533      $query.= '
     534    ';
     535      if ($insert_id > 0)
    534536      {
    535537        $query.= ',';
    536538      }
    537 
    538       if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
     539      $query.= '(';
     540      foreach ($dbfields as $field_id => $dbfield)
    539541      {
    540         $query.= 'NULL';
     542        if ($field_id > 0)
     543        {
     544          $query.= ',';
     545        }
     546
     547        if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
     548        {
     549          $query.= 'NULL';
     550        }
     551        else
     552        {
     553          $query.= "'".$insert[$dbfield]."'";
     554        }
    541555      }
    542       else
    543       {
    544         $query.= "'".$insert[$dbfield]."'";
    545       }
    546     }
    547     $query.=')';
    548   }
    549   $query.= '
    550 ;';
    551   pwg_query($query);
     556      $query.=')';
     557    }
     558    $query.= '
     559;';
     560    pwg_query($query);
     561  }
    552562}
    553563
     
    562572function mass_updates($tablename, $dbfields, $datas)
    563573{
    564   // depending on the MySQL version, we use the multi table update or N
    565   // update queries
    566   $query = 'SELECT VERSION() AS version;';
    567   list($mysql_version) = mysql_fetch_array(pwg_query($query));
    568   if (count($datas) < 10 or version_compare($mysql_version, '4.0.4') < 0)
    569   {
    570     // MySQL is prior to version 4.0.4, multi table update feature is not
    571     // available
    572     foreach ($datas as $data)
    573     {
     574  if (count($datas) != 0)
     575  {
     576    // depending on the MySQL version, we use the multi table update or N
     577    // update queries
     578    $query = 'SELECT VERSION() AS version;';
     579    list($mysql_version) = mysql_fetch_array(pwg_query($query));
     580    if (count($datas) < 10 or version_compare($mysql_version, '4.0.4') < 0)
     581    {
     582      // MySQL is prior to version 4.0.4, multi table update feature is not
     583      // available
     584      foreach ($datas as $data)
     585      {
     586        $query = '
     587  UPDATE '.$tablename.'
     588    SET ';
     589        $is_first = true;
     590        foreach ($dbfields['update'] as $num => $key)
     591        {
     592          if (!$is_first)
     593          {
     594            $query.= ",\n      ";
     595          }
     596          $query.= $key.' = ';
     597          if (isset($data[$key]) and $data[$key] != '')
     598          {
     599            $query.= '\''.$data[$key].'\'';
     600          }
     601          else
     602          {
     603            $query.= 'NULL';
     604          }
     605          $is_first = false;
     606        }
     607        $query.= '
     608    WHERE ';
     609        foreach ($dbfields['primary'] as $num => $key)
     610        {
     611          if ($num > 1)
     612          {
     613            $query.= ' AND ';
     614          }
     615          $query.= $key.' = \''.$data[$key].'\'';
     616        }
     617        $query.= '
     618  ;';
     619        pwg_query($query);
     620      }
     621    }
     622    else
     623    {
     624      // creation of the temporary table
    574625      $query = '
    575 UPDATE '.$tablename.'
    576   SET ';
    577       $is_first = true;
    578       foreach ($dbfields['update'] as $num => $key)
     626  SHOW FULL COLUMNS FROM '.$tablename.'
     627;';
     628      $result = pwg_query($query);
     629      $columns = array();
     630      $all_fields = array_merge($dbfields['primary'], $dbfields['update']);
     631      while ($row = mysql_fetch_array($result))
    579632      {
    580         if (!$is_first)
     633        if (in_array($row['Field'], $all_fields))
    581634        {
    582           $query.= ",\n      ";
     635          $column = $row['Field'];
     636          $column.= ' '.$row['Type'];
     637          if (!isset($row['Null']) or $row['Null'] == '')
     638          {
     639            $column.= ' NOT NULL';
     640          }
     641          if (isset($row['Default']))
     642          {
     643            $column.= " default '".$row['Default']."'";
     644          }
     645          if (isset($row['Collation']) and $row['Collation'] != 'NULL')
     646          {
     647            $column.= " collate '".$row['Collation']."'";
     648          }
     649          array_push($columns, $column);
    583650        }
    584         $query.= $key.' = ';
    585         if (isset($data[$key]) and $data[$key] != '')
    586         {
    587           $query.= '\''.$data[$key].'\'';
    588         }
    589         else
    590         {
    591           $query.= 'NULL';
    592         }
    593         $is_first = false;
    594651      }
    595       $query.= '
    596   WHERE ';
    597       foreach ($dbfields['primary'] as $num => $key)
    598       {
    599         if ($num > 1)
    600         {
    601           $query.= ' AND ';
    602         }
    603         $query.= $key.' = \''.$data[$key].'\'';
    604       }
    605       $query.= '
     652
     653      $temporary_tablename = $tablename.'_'.micro_seconds();
     654
     655      $query = '
     656  CREATE TABLE '.$temporary_tablename.'
     657  (
     658  '.implode(",\n", $columns).',
     659  PRIMARY KEY ('.implode(',', $dbfields['primary']).')
     660  )
    606661;';
    607662      pwg_query($query);
    608     }
    609   }
    610   else
    611   {
    612     // creation of the temporary table
    613     $query = '
    614 SHOW FULL COLUMNS FROM '.$tablename.'
    615 ;';
    616     $result = pwg_query($query);
    617     $columns = array();
    618     $all_fields = array_merge($dbfields['primary'], $dbfields['update']);
    619     while ($row = mysql_fetch_array($result))
    620     {
    621       if (in_array($row['Field'], $all_fields))
    622       {
    623         $column = $row['Field'];
    624         $column.= ' '.$row['Type'];
    625         if (!isset($row['Null']) or $row['Null'] == '')
    626         {
    627           $column.= ' NOT NULL';
    628         }
    629         if (isset($row['Default']))
    630         {
    631           $column.= " default '".$row['Default']."'";
    632         }
    633         if (isset($row['Collation']) and $row['Collation'] != 'NULL')
    634         {
    635           $column.= " collate '".$row['Collation']."'";
    636         }
    637         array_push($columns, $column);
    638       }
    639     }
    640 
    641     $temporary_tablename = $tablename.'_'.micro_seconds();
    642 
    643     $query = '
    644 CREATE TABLE '.$temporary_tablename.'
    645 (
    646 '.implode(",\n", $columns).',
    647 PRIMARY KEY ('.implode(',', $dbfields['primary']).')
    648 )
    649 ;';
    650     pwg_query($query);
    651     mass_inserts($temporary_tablename, $all_fields, $datas);
    652     // update of images table by joining with temporary table
    653     $query = '
    654 UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2
    655   SET '.
    656       implode(
    657         "\n    , ",
    658         array_map(
    659           create_function('$s', 'return "t1.$s = t2.$s";'),
    660           $dbfields['update']
    661           )
    662         ).'
    663   WHERE '.
    664       implode(
    665         "\n    AND ",
    666         array_map(
    667           create_function('$s', 'return "t1.$s = t2.$s";'),
    668           $dbfields['primary']
    669           )
    670         ).'
    671 ;';
    672     pwg_query($query);
    673     $query = '
    674 DROP TABLE '.$temporary_tablename.'
    675 ;';
    676     pwg_query($query);
     663      mass_inserts($temporary_tablename, $all_fields, $datas);
     664      // update of images table by joining with temporary table
     665      $query = '
     666  UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2
     667    SET '.
     668        implode(
     669          "\n    , ",
     670          array_map(
     671            create_function('$s', 'return "t1.$s = t2.$s";'),
     672            $dbfields['update']
     673            )
     674          ).'
     675    WHERE '.
     676        implode(
     677          "\n    AND ",
     678          array_map(
     679            create_function('$s', 'return "t1.$s = t2.$s";'),
     680            $dbfields['primary']
     681            )
     682          ).'
     683  ;';
     684      pwg_query($query);
     685      $query = '
     686  DROP TABLE '.$temporary_tablename.'
     687;';
     688      pwg_query($query);
     689    }
    677690  }
    678691}
     
    11601173    USER_ACCESS_TABLE,
    11611174    USER_CACHE_TABLE,
     1175    USER_CACHE_CATEGORIES_TABLE,
    11621176    USER_GROUP_TABLE
    11631177    );
Note: See TracChangeset for help on using the changeset viewer.