Ignore:
Timestamp:
Apr 19, 2006, 10:54:13 PM (19 years ago)
Author:
plg
Message:

bug fixed: during installation, upgrades from install/db with complex
identifier (X.x) were not correctly inserted.

bug fixed: available upgrades from install/db need to be inserted in
#upgrade table.

deletion: all upgrades from install/db coming from trunk are removed.

new: complete upgrade from any previous release from 1.3.0 to 1.5.2 with
automatic detection detection of the previous release.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1_6/upgrade.php

    r1174 r1209  
    132132}
    133133
    134 /**
    135  * replace old style #images.keywords by #tags. Requires a big data
    136  * migration.
    137  *
    138  * @return void
    139  */
    140 function tag_replace_keywords()
    141 {
    142   // code taken from upgrades 19 and 22
    143  
    144   $query = '
    145 CREATE TABLE '.PREFIX_TABLE.'tags (
    146   id smallint(5) UNSIGNED NOT NULL auto_increment,
    147   name varchar(255) BINARY NOT NULL,
    148   url_name varchar(255) BINARY NOT NULL,
    149   PRIMARY KEY (id)
    150 )
    151 ;';
    152   pwg_query($query);
    153  
    154   $query = '
    155 CREATE TABLE '.PREFIX_TABLE.'image_tag (
    156   image_id mediumint(8) UNSIGNED NOT NULL,
    157   tag_id smallint(5) UNSIGNED NOT NULL,
    158   PRIMARY KEY (image_id,tag_id)
    159 )
    160 ;';
    161   pwg_query($query);
    162  
    163   //
    164   // Move keywords to tags
    165   //
    166 
    167   // each tag label is associated to a numeric identifier
    168   $tag_id = array();
    169   // to each tag id (key) a list of image ids (value) is associated
    170   $tag_images = array();
    171 
    172   $current_id = 1;
    173 
    174   $query = '
    175 SELECT id, keywords
    176   FROM '.PREFIX_TABLE.'images
    177   WHERE keywords IS NOT NULL
    178 ;';
    179   $result = pwg_query($query);
    180   while ($row = mysql_fetch_array($result))
    181   {
    182     foreach(preg_split('/[,]+/', $row['keywords']) as $keyword)
    183     {
    184       if (!isset($tag_id[$keyword]))
    185       {
    186         $tag_id[$keyword] = $current_id++;
    187       }
    188 
    189       if (!isset($tag_images[ $tag_id[$keyword] ]))
    190       {
    191         $tag_images[ $tag_id[$keyword] ] = array();
    192       }
    193 
    194       array_push(
    195         $tag_images[ $tag_id[$keyword] ],
    196         $row['id']
    197         );
    198     }
    199   }
    200 
    201   $datas = array();
    202   foreach ($tag_id as $tag_name => $tag_id)
    203   {
    204     array_push(
    205       $datas,
    206       array(
    207         'id'       => $tag_id,
    208         'name'     => $tag_name,
    209         'url_name' => str2url($tag_name),
    210         )
    211       );
    212   }
    213  
    214   if (!empty($datas))
    215   {
    216     mass_inserts(
    217       PREFIX_TABLE.'tags',
    218       array_keys($datas[0]),
    219       $datas
    220       );
    221   }
    222 
    223   $datas = array();
    224   foreach ($tag_images as $tag_id => $images)
    225   {
    226     foreach (array_unique($images) as $image_id)
    227     {
    228       array_push(
    229         $datas,
    230         array(
    231           'tag_id'   => $tag_id,
    232           'image_id' => $image_id,
    233           )
    234         );
    235     }
    236   }
    237  
    238   if (!empty($datas))
    239   {
    240     mass_inserts(
    241       PREFIX_TABLE.'image_tag',
    242       array_keys($datas[0]),
    243       $datas
    244       );
    245   }
    246 
    247   //
    248   // Delete images.keywords
    249   //
    250   $query = '
    251 ALTER TABLE '.PREFIX_TABLE.'images DROP COLUMN keywords
    252 ;';
    253   pwg_query($query);
    254 
    255   //
    256   // Add useful indexes
    257   //
    258   $query = '
    259 ALTER TABLE '.PREFIX_TABLE.'tags
    260   ADD INDEX tags_i1(url_name)
    261 ;';
    262   pwg_query($query);
    263 
    264 
    265   $query = '
    266 ALTER TABLE '.PREFIX_TABLE.'image_tag
    267   ADD INDEX image_tag_i1(tag_id)
    268 ;';
    269   pwg_query($query);
    270 
    271   print_time('tags have replaced keywords');
    272 }
    273 
    274134// +-----------------------------------------------------------------------+
    275135// |                             playing zone                              |
     
    278138// echo implode('<br>', get_tables());
    279139// echo '<pre>'; print_r(get_columns_of(get_tables())); echo '</pre>';
     140
     141// foreach (get_available_upgrade_ids() as $upgrade_id)
     142// {
     143//   echo $upgrade_id, '<br>';
     144// }
    280145
    281146// +-----------------------------------------------------------------------+
     
    341206  if (is_file($upgrade_file))
    342207  {
     208    $page['infos'] = array();
    343209    $page['upgrade_start'] = get_moment();
    344210    $conf['die_on_sql_error'] = false;
    345211    include($upgrade_file);
     212
     213    // Available upgrades must be ignored after a fresh installation. To
     214    // make PWG avoid upgrading, we must tell it upgrades have already been
     215    // made.
     216    list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
     217    define('CURRENT_DATE', $dbnow);
     218    $datas = array();
     219    foreach (get_available_upgrade_ids() as $upgrade_id)
     220    {
     221      array_push(
     222        $datas,
     223        array(
     224          'id'          => $upgrade_id,
     225          'applied'     => CURRENT_DATE,
     226          'description' => 'upgrade included in upgrade',
     227          )
     228        );
     229    }
     230    mass_inserts(
     231      UPGRADE_TABLE,
     232      array_keys($datas[0]),
     233      $datas
     234      );
     235   
    346236    $page['upgrade_end'] = get_moment();
    347237
     
    364254      );
    365255
    366     if (!isset($infos))
    367     {
    368       $infos = array();
    369     }
    370256    array_push(
    371       $infos,
     257      $page['infos'],
    372258      '[security] delete files "upgrade.php", "install.php" and "install"
    373259directory'
     
    375261
    376262    array_push(
    377       $infos,
     263      $page['infos'],
    378264      'in include/mysql.inc.php, remove
    379265<pre style="background-color:lightgray">
     
    383269
    384270    array_push(
    385       $infos,
     271      $page['infos'],
    386272      'Perform a maintenance check in [Administration>General>Maintenance]
    387273if you encounter any problem.'
     
    390276    $template->assign_block_vars('upgrade.infos', array());
    391277   
    392     foreach ($infos as $info)
     278    foreach ($page['infos'] as $info)
    393279    {
    394280      $template->assign_block_vars(
     
    399285        );
    400286    }
    401   }
    402   else
    403   {
    404     die('Hacking attempt');
    405   }
    406 }
    407 
    408 $query = '
     287
     288    $query = '
    409289UPDATE '.USER_CACHE_TABLE.'
    410290  SET need_update = \'true\'
    411291;';
    412 pwg_query($query);
     292    pwg_query($query);
     293  }
     294  else
     295  {
     296    die('Hacking attempt');
     297  }
     298}
    413299
    414300// +-----------------------------------------------------------------------+
Note: See TracChangeset for help on using the changeset viewer.