Index: /extensions/Subscribe_to_comments/include/install.inc.php
===================================================================
--- /extensions/Subscribe_to_comments/include/install.inc.php	(revision 17922)
+++ /extensions/Subscribe_to_comments/include/install.inc.php	(revision 17922)
@@ -0,0 +1,94 @@
+<?php
+defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
+
+function stc_install() 
+{
+  global $conf, $prefixeTable;
+  
+  $stc_table = $prefixeTable . 'subscribe_to_comments';
+  
+  // config parameter
+  if (empty($conf['Subscribe_to_Comments']))
+  {
+    $stc_default_config = serialize(array(
+      'notify_admin_on_subscribe' => false,
+      'allow_global_subscriptions' => true,
+      ));
+  
+    conf_update_param('Subscribe_to_Comments', $stc_default_config);
+    $conf['Subscribe_to_Comments'] = $stc_default_config;
+  }
+  
+  // subscriptions table
+	pwg_query('
+CREATE TABLE IF NOT EXISTS `'.$stc_table.'` (
+  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+  `type` enum("image","album-images","album","all-images","all-albums") NOT NULL DEFAULT "image",
+  `element_id` mediumint(8) DEFAULT NULL,
+  `language` varchar(64) NOT NULL,
+  `email` varchar(255) NOT NULL,
+  `registration_date` datetime NOT NULL,
+  `validated` enum("true","false") NOT NULL DEFAULT "false",
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `UNIQUE` (`email` , `type` , `element_id`)
+) DEFAULT CHARSET=utf8
+;');
+
+  // table structure upgrade in 1.1
+  $result = pwg_query('SHOW COLUMNS FROM `'.$stc_table.'` LIKE "element_id";');
+  if (!pwg_db_num_rows($result))
+  {
+    // backup subscriptions
+    $query = 'SELECT * FROM `'.$stc_table.'` ORDER BY registration_date;';
+    $subscriptions = hash_from_query($query, 'id');
+    
+    // upgrade the table
+    pwg_query('TRUNCATE TABLE `'.$stc_table.'`;');
+    pwg_query('ALTER TABLE `'.$stc_table.'` DROP `image_id`, DROP `category_id`;');
+    pwg_query('ALTER TABLE `'.$stc_table.'` AUTO_INCREMENT = 1;');
+    
+    $query = '
+ALTER TABLE `'.$stc_table.'` 
+  ADD `type` enum("image", "album-images", "album", "all-images", "all-albums") NOT NULL DEFAULT "image" AFTER `id`,
+  ADD `element_id` mediumint(8) NULL AFTER `type`,
+  ADD `language` varchar(64) NOT NULL AFTER `element_id` 
+;';
+    pwg_query($query);
+    
+    pwg_query('ALTER TABLE `'.$stc_table.'`  DROP INDEX `UNIQUE`, ADD UNIQUE `UNIQUE` (`email`, `type`, `element_id`);');
+    
+    // convert datas and fill the table
+    $inserts = array();
+    
+    foreach ($subscriptions as $row)
+    {
+      if (!empty($row['category_id']))
+      {
+        $row['type'] = 'album';
+        $row['element_id'] = $row['category_id'];
+      }
+      else if (!empty($row['image_id']))
+      {
+        $row['type'] = 'image';
+        $row['element_id'] = $row['image_id'];
+      }
+      else
+      {
+        continue;
+      }
+      
+      unset($row['id'], $row['image_id'], $row['category_id']);
+      $row['language'] = 'en_UK';
+      
+      array_push($inserts, $row);
+    }
+    
+    if (count($inserts) > 0)
+    {
+      $dbfields = array('type', 'element_id', 'language', 'email', 'registration_date', 'validated');
+      mass_inserts($stc_table, $dbfields, $inserts);
+    }
+  }
+}
+
+?>
Index: /extensions/Subscribe_to_comments/main.inc.php
===================================================================
--- /extensions/Subscribe_to_comments/main.inc.php	(revision 17921)
+++ /extensions/Subscribe_to_comments/main.inc.php	(revision 17922)
@@ -13,22 +13,54 @@
 global $prefixeTable;
 
-define('SUBSCRIBE_TO_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
+define('SUBSCRIBE_TO_PATH' , PHPWG_PLUGINS_PATH . 'Subscribe_to_comments/');
 define('SUBSCRIBE_TO_TABLE', $prefixeTable . 'subscribe_to_comments');
+define('SUBSCRIBE_TO_VERSION', '2.0.3');
+
 
 add_event_handler('init', 'stc_init');
 
+
 function stc_init()
 {
-  global $conf, $user;
+  global $conf, $user, $pwg_loaded_plugins;
   
   // no comments on luciano
   if ($user['theme'] == 'luciano') return;
   
+  // apply upgrade if needed
+  if (
+    $pwg_loaded_plugins['Subscribe_to_comments']['version'] == 'auto' or
+    version_compare($pwg_loaded_plugins['Subscribe_to_comments']['version'], SUBSCRIBE_TO_VERSION, '<')
+  )
+  {
+    include_once(SUBSCRIBE_TO_PATH . 'include/install.inc.php');
+    stc_install();
+    
+    if ($pwg_loaded_plugins['Subscribe_to_comments']['version'] != 'auto')
+    {
+      $query = '
+UPDATE '. PLUGINS_TABLE .'
+SET version = "'. SUBSCRIBE_TO_VERSION .'"
+WHERE id = "Subscribe_to_comments"';
+      pwg_query($query);
+      
+      $pwg_loaded_plugins['Subscribe_to_comments']['version'] = SUBSCRIBE_TO_VERSION;
+      
+      if (defined('IN_ADMIN'))
+      {
+        $_SESSION['page_infos'][] = 'Subscribe to comments updated to version '. SUBSCRIBE_TO_VERSION;
+      }
+    }
+  }
+  
+  // load language and conf
   load_language('plugin.lang', SUBSCRIBE_TO_PATH);
   $conf['Subscribe_to_Comments'] = unserialize($conf['Subscribe_to_Comments']);
+  
   
   include_once(SUBSCRIBE_TO_PATH.'include/functions.inc.php');
   include_once(SUBSCRIBE_TO_PATH.'include/subscribe_to_comments.inc.php');
 
+  
   // send mails
   add_event_handler('user_comment_insertion', 'stc_comment_insertion');
@@ -54,4 +86,5 @@
 }
 
+
 function stc_admin_menu($menu) 
 {
@@ -62,3 +95,4 @@
   return $menu;
 }
+
 ?>
Index: /extensions/Subscribe_to_comments/maintain.inc.php
===================================================================
--- /extensions/Subscribe_to_comments/maintain.inc.php	(revision 17921)
+++ /extensions/Subscribe_to_comments/maintain.inc.php	(revision 17922)
@@ -2,103 +2,18 @@
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 
-global $prefixeTable;
-
-define('STC_TABLE', $prefixeTable . 'subscribe_to_comments');
-
-define(
-  'stc_default_config', 
-  serialize(array(
-    'notify_admin_on_subscribe' => false,
-    'allow_global_subscriptions' => true,
-    ))
-  );
+include_once(PHPWG_PLUGINS_PATH . 'Subscribe_to_comments/include/install.inc.php');
   
 
 function plugin_install() 
 {
-  /* create table to store subscribtions */
-	pwg_query('
-CREATE TABLE IF NOT EXISTS '.STC_TABLE.' (
-  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
-  `type` enum("image","album-images","album","all-images","all-albums") NOT NULL DEFAULT "image",
-  `element_id` mediumint(8) DEFAULT NULL,
-  `language` varchar(64) NOT NULL,
-  `email` varchar(255) NOT NULL,
-  `registration_date` datetime NOT NULL,
-  `validated` enum("true","false") NOT NULL DEFAULT "false",
-  PRIMARY KEY (`id`),
-  UNIQUE KEY `UNIQUE` (`email` , `type` , `element_id`)
-) DEFAULT CHARSET=utf8
-;');
-
-  /* config parameter */
-  conf_update_param('Subscribe_to_Comments', stc_default_config);
-
+  stc_install();
+  define('stc_installed', true);
 }
 
 function plugin_activate()
 {
-  global $conf;
-  
-  // new config in 1.1
-  if (empty($conf['Subscribe_to_Comments']))
+  if (!defined('stc_installed'))
   {
-    conf_update_param('Subscribe_to_Comments', stc_default_config);
-  }
-  
-  // table structure upgrade in 1.1
-  $result = pwg_query('SHOW COLUMNS FROM '.STC_TABLE.' LIKE "element_id";');
-  if (!pwg_db_num_rows($result))
-  {
-    // backup subscriptions
-    $query = 'SELECT * FROM '.STC_TABLE.' ORDER BY registration_date;';
-    $subscriptions = hash_from_query($query, 'id');
-    
-    // upgrade the table
-    pwg_query('TRUNCATE TABLE '.STC_TABLE.';');
-    pwg_query('ALTER TABLE '.STC_TABLE.' DROP `image_id`, DROP `category_id`;');
-    pwg_query('ALTER TABLE '.STC_TABLE.' AUTO_INCREMENT = 1;');
-    
-    $query = '
-ALTER TABLE '.STC_TABLE.' 
-  ADD `type` ENUM( "image", "album-images", "album", "all-images", "all-albums" ) NOT NULL DEFAULT "image" AFTER `id`,
-  ADD `element_id` MEDIUMINT( 8 ) NULL AFTER `type`,
-  ADD `language` VARCHAR( 64 ) NOT NULL AFTER `element_id` 
-;';
-    pwg_query($query);
-    
-    pwg_query('ALTER TABLE '.STC_TABLE.'  DROP INDEX `UNIQUE`, ADD UNIQUE `UNIQUE` ( `email` , `type` , `element_id` );');
-    
-    // convert datas and fill the table
-    $inserts = array();
-    
-    foreach ($subscriptions as $row)
-    {
-      if (!empty($row['category_id']))
-      {
-        $row['type'] = 'album';
-        $row['element_id'] = $row['category_id'];
-      }
-      else if (!empty($row['image_id']))
-      {
-        $row['type'] = 'image';
-        $row['element_id'] = $row['image_id'];
-      }
-      else
-      {
-        continue;
-      }
-      
-      unset($row['id'], $row['image_id'], $row['category_id']);
-      $row['language'] = 'en_UK';
-      
-      array_push($inserts, $row);
-    }
-    
-    if (count($inserts) > 0)
-    {
-      $dbfields = array('type', 'element_id', 'language', 'email', 'registration_date', 'validated');
-      mass_inserts(STC_TABLE, $dbfields, $inserts);
-    }
+    stc_install();
   }
 }
@@ -106,6 +21,7 @@
 function plugin_uninstall() 
 {
-  /* delete table and config */
-  pwg_query('DROP TABLE '.STC_TABLE.';');
+  global $prefixeTable;
+  
+  pwg_query('DROP TABLE `'. $prefixeTable . 'subscribe_to_comments`;');
   pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "Subscribe_to_Comments" LIMIT 1;');
 }
