Changeset 1209


Ignore:
Timestamp:
Apr 19, 2006, 10:54:13 PM (18 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.

Location:
branches/branch-1_6
Files:
2 added
23 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1_6/doc/README_en.txt

    r870 r1209  
    2424
    2525 - file "include/mysql.inc.php"
     26 - file "include/config_local.inc.php" if you have one
    2627 - directory "galleries"
    2728 - your database (create a dump, using PhpMyAdmin for instance)
     
    3031   the previous listed elements)
    3132
    32 3. extract files from the downloaded file (using tar or unzip command, or
    33    softwares like 7-zip or winzip)
     333. extract files from the downloaded file
    3434
    35354. upload all the new version files to your website but the previous listed
  • branches/branch-1_6/doc/README_fr.txt

    r870 r1209  
    88============
    99
    10 1. décompresser à l'aide de winzip par exemple (winrar, winace et beaucoup
    11    d'autres le permettent également) le fichier téléchargé.
     101. décompresser l'archive téléchargée
    1211
    13122. placer les fichiers décompressés sur votre serveur web dans le répertoire
     
    2322
    2423 - fichier "include/mysql.inc.php"
     24 - fichier "include/config_local.inc.php" s'il existe
    2525 - répertoire "galleries"
    2626 - votre base de données (en créant un dump, avec PhpMyAdmin par exemple)
     
    2929   (sauf les éléments listés ci-dessus)
    3030
    31 3. décompresser à l'aide de winzip par exemple (winrar, winace et beaucoup
    32    d'autres le permettent également) le fichier téléchargé.
     313. décompresser l'archive contenant la dernière version
    3332
    34334. placer tous les fichiers de la nouvelle version sur votre site web sauf
  • branches/branch-1_6/install.php

    r1146 r1209  
    333333    // make PWG avoid upgrading, we must tell it upgrades have already been
    334334    // made.
     335    list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
     336    define('CURRENT_DATE', $dbnow);
     337    $datas = array();
    335338    foreach (get_available_upgrade_ids() as $upgrade_id)
    336339    {
    337       $query = '
    338 INSERT INTO '.UPGRADE_TABLE.'
    339   (id, applied, description)
    340   VALUES
    341   ('.$upgrade_id.', NOW(), \'upgrade included in installation\')
    342 ';
    343       mysql_query($query);
    344     }
     340      array_push(
     341        $datas,
     342        array(
     343          'id'          => $upgrade_id,
     344          'applied'     => CURRENT_DATE,
     345          'description' => 'upgrade included in installation',
     346          )
     347        );
     348    }
     349    mass_inserts(
     350      UPGRADE_TABLE,
     351      array_keys($datas[0]),
     352      $datas
     353      );
    345354  }
    346355}
  • branches/branch-1_6/install/upgrade_1.4.0.php

    r911 r1209  
    189189}
    190190
    191 $new_time = get_moment();
    192 echo '<pre>['.get_elapsed_time($last_time, $new_time).']';
    193 echo ' Basic database structure upgrade done</pre>';
    194 flush();
    195 $last_time = $new_time;
    196 
    197191// user datas migration from phpwebgallery_users to phpwebgallery_user_infos
    198192$query = '
     
    288282}
    289283
    290 $infos = array();
    291 
    292284if ($prefix_thumbnail != 'TN-')
    293285{
    294286  array_push(
    295     $infos,
     287    $page['infos'],
    296288    'the thumbnail prefix configuration parameter was moved to configuration
    297289file, copy config_local.inc.php from "tools" directory to "include" directory
     
    300292}
    301293
     294// now we upgrade from 1.5.0 to 1.6.0
     295include_once(PHPWG_ROOT_PATH.'install/upgrade_1.5.0.php');
    302296?>
  • branches/branch-1_6/install/upgrade_1.5.0.php

    r1174 r1209  
    3838}
    3939
     40/**
     41 * replace old style #images.keywords by #tags. Requires a big data
     42 * migration.
     43 *
     44 * @return void
     45 */
     46function tag_replace_keywords()
     47{
     48  // code taken from upgrades 19 and 22
     49 
     50  $query = '
     51CREATE TABLE '.PREFIX_TABLE.'tags (
     52  id smallint(5) UNSIGNED NOT NULL auto_increment,
     53  name varchar(255) BINARY NOT NULL,
     54  url_name varchar(255) BINARY NOT NULL,
     55  PRIMARY KEY (id)
     56)
     57;';
     58  pwg_query($query);
     59 
     60  $query = '
     61CREATE TABLE '.PREFIX_TABLE.'image_tag (
     62  image_id mediumint(8) UNSIGNED NOT NULL,
     63  tag_id smallint(5) UNSIGNED NOT NULL,
     64  PRIMARY KEY (image_id,tag_id)
     65)
     66;';
     67  pwg_query($query);
     68 
     69  //
     70  // Move keywords to tags
     71  //
     72
     73  // each tag label is associated to a numeric identifier
     74  $tag_id = array();
     75  // to each tag id (key) a list of image ids (value) is associated
     76  $tag_images = array();
     77
     78  $current_id = 1;
     79
     80  $query = '
     81SELECT id, keywords
     82  FROM '.PREFIX_TABLE.'images
     83  WHERE keywords IS NOT NULL
     84;';
     85  $result = pwg_query($query);
     86  while ($row = mysql_fetch_array($result))
     87  {
     88    foreach(preg_split('/[,]+/', $row['keywords']) as $keyword)
     89    {
     90      if (!isset($tag_id[$keyword]))
     91      {
     92        $tag_id[$keyword] = $current_id++;
     93      }
     94
     95      if (!isset($tag_images[ $tag_id[$keyword] ]))
     96      {
     97        $tag_images[ $tag_id[$keyword] ] = array();
     98      }
     99
     100      array_push(
     101        $tag_images[ $tag_id[$keyword] ],
     102        $row['id']
     103        );
     104    }
     105  }
     106
     107  $datas = array();
     108  foreach ($tag_id as $tag_name => $tag_id)
     109  {
     110    array_push(
     111      $datas,
     112      array(
     113        'id'       => $tag_id,
     114        'name'     => $tag_name,
     115        'url_name' => str2url($tag_name),
     116        )
     117      );
     118  }
     119 
     120  if (!empty($datas))
     121  {
     122    mass_inserts(
     123      PREFIX_TABLE.'tags',
     124      array_keys($datas[0]),
     125      $datas
     126      );
     127  }
     128
     129  $datas = array();
     130  foreach ($tag_images as $tag_id => $images)
     131  {
     132    foreach (array_unique($images) as $image_id)
     133    {
     134      array_push(
     135        $datas,
     136        array(
     137          'tag_id'   => $tag_id,
     138          'image_id' => $image_id,
     139          )
     140        );
     141    }
     142  }
     143 
     144  if (!empty($datas))
     145  {
     146    mass_inserts(
     147      PREFIX_TABLE.'image_tag',
     148      array_keys($datas[0]),
     149      $datas
     150      );
     151  }
     152
     153  //
     154  // Delete images.keywords
     155  //
     156  $query = '
     157ALTER TABLE '.PREFIX_TABLE.'images DROP COLUMN keywords
     158;';
     159  pwg_query($query);
     160
     161  //
     162  // Add useful indexes
     163  //
     164  $query = '
     165ALTER TABLE '.PREFIX_TABLE.'tags
     166  ADD INDEX tags_i1(url_name)
     167;';
     168  pwg_query($query);
     169
     170
     171  $query = '
     172ALTER TABLE '.PREFIX_TABLE.'image_tag
     173  ADD INDEX image_tag_i1(tag_id)
     174;';
     175  pwg_query($query);
     176
     177  // print_time('tags have replaced keywords');
     178}
     179
    40180tag_replace_keywords();
    41181
     
    298438pwg_query($query);
    299439
     440// depending on the way the 1.5.0 was installed (from scratch or by upgrade)
     441// the database structure has small differences that should be corrected.
     442
     443$query = '
     444ALTER TABLE '.PREFIX_TABLE.'users
     445  CHANGE COLUMN password password varchar(32) default NULL
     446;';
     447pwg_query($query);
     448
     449$to_keep = array('id', 'username', 'password', 'mail_address');
     450 
     451$query = '
     452DESC '.PREFIX_TABLE.'users
     453;';
     454
     455$result = pwg_query($query);
     456
     457while ($row = mysql_fetch_array($result))
     458{
     459  if (!in_array($row['Field'], $to_keep))
     460  {
     461    $query = '
     462ALTER TABLE '.PREFIX_TABLE.'users
     463  DROP COLUMN '.$row['Field'].'
     464;';
     465    pwg_query($query);
     466  }
     467}
     468
    300469?>
  • 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.