Ignore:
Timestamp:
Sep 15, 2012, 11:14:27 AM (12 years ago)
Author:
mistic100
Message:

use new upgrade process

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Subscribe_to_comments/maintain.inc.php

    r15641 r17922  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    33
    4 global $prefixeTable;
    5 
    6 define('STC_TABLE', $prefixeTable . 'subscribe_to_comments');
    7 
    8 define(
    9   'stc_default_config',
    10   serialize(array(
    11     'notify_admin_on_subscribe' => false,
    12     'allow_global_subscriptions' => true,
    13     ))
    14   );
     4include_once(PHPWG_PLUGINS_PATH . 'Subscribe_to_comments/include/install.inc.php');
    155 
    166
    177function plugin_install()
    188{
    19   /* create table to store subscribtions */
    20         pwg_query('
    21 CREATE TABLE IF NOT EXISTS '.STC_TABLE.' (
    22   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    23   `type` enum("image","album-images","album","all-images","all-albums") NOT NULL DEFAULT "image",
    24   `element_id` mediumint(8) DEFAULT NULL,
    25   `language` varchar(64) NOT NULL,
    26   `email` varchar(255) NOT NULL,
    27   `registration_date` datetime NOT NULL,
    28   `validated` enum("true","false") NOT NULL DEFAULT "false",
    29   PRIMARY KEY (`id`),
    30   UNIQUE KEY `UNIQUE` (`email` , `type` , `element_id`)
    31 ) DEFAULT CHARSET=utf8
    32 ;');
    33 
    34   /* config parameter */
    35   conf_update_param('Subscribe_to_Comments', stc_default_config);
    36 
     9  stc_install();
     10  define('stc_installed', true);
    3711}
    3812
    3913function plugin_activate()
    4014{
    41   global $conf;
    42  
    43   // new config in 1.1
    44   if (empty($conf['Subscribe_to_Comments']))
     15  if (!defined('stc_installed'))
    4516  {
    46     conf_update_param('Subscribe_to_Comments', stc_default_config);
    47   }
    48  
    49   // table structure upgrade in 1.1
    50   $result = pwg_query('SHOW COLUMNS FROM '.STC_TABLE.' LIKE "element_id";');
    51   if (!pwg_db_num_rows($result))
    52   {
    53     // backup subscriptions
    54     $query = 'SELECT * FROM '.STC_TABLE.' ORDER BY registration_date;';
    55     $subscriptions = hash_from_query($query, 'id');
    56    
    57     // upgrade the table
    58     pwg_query('TRUNCATE TABLE '.STC_TABLE.';');
    59     pwg_query('ALTER TABLE '.STC_TABLE.' DROP `image_id`, DROP `category_id`;');
    60     pwg_query('ALTER TABLE '.STC_TABLE.' AUTO_INCREMENT = 1;');
    61    
    62     $query = '
    63 ALTER TABLE '.STC_TABLE.'
    64   ADD `type` ENUM( "image", "album-images", "album", "all-images", "all-albums" ) NOT NULL DEFAULT "image" AFTER `id`,
    65   ADD `element_id` MEDIUMINT( 8 ) NULL AFTER `type`,
    66   ADD `language` VARCHAR( 64 ) NOT NULL AFTER `element_id`
    67 ;';
    68     pwg_query($query);
    69    
    70     pwg_query('ALTER TABLE '.STC_TABLE.'  DROP INDEX `UNIQUE`, ADD UNIQUE `UNIQUE` ( `email` , `type` , `element_id` );');
    71    
    72     // convert datas and fill the table
    73     $inserts = array();
    74    
    75     foreach ($subscriptions as $row)
    76     {
    77       if (!empty($row['category_id']))
    78       {
    79         $row['type'] = 'album';
    80         $row['element_id'] = $row['category_id'];
    81       }
    82       else if (!empty($row['image_id']))
    83       {
    84         $row['type'] = 'image';
    85         $row['element_id'] = $row['image_id'];
    86       }
    87       else
    88       {
    89         continue;
    90       }
    91      
    92       unset($row['id'], $row['image_id'], $row['category_id']);
    93       $row['language'] = 'en_UK';
    94      
    95       array_push($inserts, $row);
    96     }
    97    
    98     if (count($inserts) > 0)
    99     {
    100       $dbfields = array('type', 'element_id', 'language', 'email', 'registration_date', 'validated');
    101       mass_inserts(STC_TABLE, $dbfields, $inserts);
    102     }
     17    stc_install();
    10318  }
    10419}
     
    10621function plugin_uninstall()
    10722{
    108   /* delete table and config */
    109   pwg_query('DROP TABLE '.STC_TABLE.';');
     23  global $prefixeTable;
     24 
     25  pwg_query('DROP TABLE `'. $prefixeTable . 'subscribe_to_comments`;');
    11026  pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "Subscribe_to_Comments" LIMIT 1;');
    11127}
Note: See TracChangeset for help on using the changeset viewer.