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

use new upgrade process

Location:
extensions/Subscribe_to_comments
Files:
1 added
2 edited

Legend:

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

    r16106 r17922  
    1313global $prefixeTable;
    1414
    15 define('SUBSCRIBE_TO_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
     15define('SUBSCRIBE_TO_PATH' , PHPWG_PLUGINS_PATH . 'Subscribe_to_comments/');
    1616define('SUBSCRIBE_TO_TABLE', $prefixeTable . 'subscribe_to_comments');
     17define('SUBSCRIBE_TO_VERSION', '2.0.3');
     18
    1719
    1820add_event_handler('init', 'stc_init');
    1921
     22
    2023function stc_init()
    2124{
    22   global $conf, $user;
     25  global $conf, $user, $pwg_loaded_plugins;
    2326 
    2427  // no comments on luciano
    2528  if ($user['theme'] == 'luciano') return;
    2629 
     30  // apply upgrade if needed
     31  if (
     32    $pwg_loaded_plugins['Subscribe_to_comments']['version'] == 'auto' or
     33    version_compare($pwg_loaded_plugins['Subscribe_to_comments']['version'], SUBSCRIBE_TO_VERSION, '<')
     34  )
     35  {
     36    include_once(SUBSCRIBE_TO_PATH . 'include/install.inc.php');
     37    stc_install();
     38   
     39    if ($pwg_loaded_plugins['Subscribe_to_comments']['version'] != 'auto')
     40    {
     41      $query = '
     42UPDATE '. PLUGINS_TABLE .'
     43SET version = "'. SUBSCRIBE_TO_VERSION .'"
     44WHERE id = "Subscribe_to_comments"';
     45      pwg_query($query);
     46     
     47      $pwg_loaded_plugins['Subscribe_to_comments']['version'] = SUBSCRIBE_TO_VERSION;
     48     
     49      if (defined('IN_ADMIN'))
     50      {
     51        $_SESSION['page_infos'][] = 'Subscribe to comments updated to version '. SUBSCRIBE_TO_VERSION;
     52      }
     53    }
     54  }
     55 
     56  // load language and conf
    2757  load_language('plugin.lang', SUBSCRIBE_TO_PATH);
    2858  $conf['Subscribe_to_Comments'] = unserialize($conf['Subscribe_to_Comments']);
     59 
    2960 
    3061  include_once(SUBSCRIBE_TO_PATH.'include/functions.inc.php');
    3162  include_once(SUBSCRIBE_TO_PATH.'include/subscribe_to_comments.inc.php');
    3263
     64 
    3365  // send mails
    3466  add_event_handler('user_comment_insertion', 'stc_comment_insertion');
     
    5486}
    5587
     88
    5689function stc_admin_menu($menu)
    5790{
     
    6295  return $menu;
    6396}
     97
    6498?>
  • 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.