Changeset 15641 for extensions/Subscribe_to_comments/maintain.inc.php
- Timestamp:
- Jun 11, 2012, 10:10:56 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Subscribe_to_comments/maintain.inc.php
r12600 r15641 2 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 3 3 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 ); 15 16 4 17 function plugin_install() 5 18 { 6 global $prefixeTable;7 8 19 /* create table to store subscribtions */ 9 20 pwg_query(' 10 CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'subscribe_to_comments` ( 11 `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , 12 `email` VARCHAR( 255 ) NOT NULL , 13 `image_id` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT "0", 14 `category_id` SMALLINT( 5 ) UNSIGNED NOT NULL DEFAULT "0", 15 `registration_date` DATETIME NOT NULL, 16 `validated` ENUM( "true", "false" ) NOT NULL DEFAULT "false", 17 UNIQUE KEY `UNIQUE` (`email`, `image_id`, `category_id`) 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`) 18 31 ) DEFAULT CHARSET=utf8 19 32 ;'); 33 34 /* config parameter */ 35 conf_update_param('Subscribe_to_Comments', stc_default_config); 36 37 } 38 39 function plugin_activate() 40 { 41 global $conf; 42 43 // new config in 1.1 44 if (empty($conf['Subscribe_to_Comments'])) 45 { 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 } 20 91 21 /* config parameter */ 22 // pwg_query(' 23 // INSERT INTO `' . CONFIG_TABLE . '` 24 // VALUES ( 25 // "Subscribe_to_Comments", 26 // "'.serialize(array()).'", 27 // "Configuration for Subscribe_to_Comments plugin" 28 // ) 29 // ;'); 30 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 } 103 } 31 104 } 32 105 33 106 function plugin_uninstall() 34 107 { 35 global $prefixeTable;36 37 108 /* delete table and config */ 38 pwg_query('DROP TABLE `' . $prefixeTable . 'subscribe_to_comments`;');39 // pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = "Subscribe_to_Comments";');109 pwg_query('DROP TABLE '.STC_TABLE.';'); 110 pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "Subscribe_to_Comments" LIMIT 1;'); 40 111 } 41 112 ?>
Note: See TracChangeset
for help on using the changeset viewer.