Changeset 26139 for extensions/Subscribe_to_comments/maintain.inc.php
- Timestamp:
- Dec 23, 2013, 9:17:28 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Subscribe_to_comments/maintain.inc.php
r21441 r26139 1 1 <?php 2 if (!defined('PHPWG_ROOT_PATH'))die('Hacking attempt!');2 defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); 3 3 4 defined('SUBSCRIBE_TO_ID') or define('SUBSCRIBE_TO_ID', basename(dirname(__FILE__))); 5 include_once(PHPWG_PLUGINS_PATH . SUBSCRIBE_TO_ID . '/include/install.inc.php'); 6 4 class Subscribe_to_Comments_maintain extends PluginMaintain 5 { 6 private $installed = false; 7 7 8 function plugin_install() 9 { 10 stc_install(); 11 define('stc_installed', true); 12 } 8 private $default_conf = array( 9 'notify_admin_on_subscribe' => false, 10 'allow_global_subscriptions' => true, 11 ); 13 12 14 function plugin_activate() 15 { 16 if (!defined('stc_installed'))13 private $table; 14 15 function __construct($plugin_id) 17 16 { 18 stc_install(); 17 parent::__construct($plugin_id); 18 19 global $prefixeTable; 20 $this->table = $prefixeTable . 'subscribe_to_comments'; 21 } 22 23 function install($plugin_version, &$errors=array()) 24 { 25 global $conf; 26 27 // config parameter 28 if (empty($conf['Subscribe_to_Comments'])) 29 { 30 $conf['Subscribe_to_Comments'] = serialize($this->default_config); 31 conf_update_param('Subscribe_to_Comments', $conf['Subscribe_to_Comments']); 32 } 33 34 // subscriptions table 35 pwg_query(' 36 CREATE TABLE IF NOT EXISTS `'. $this->table .'` ( 37 `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 38 `type` enum("image","album-images","album","all-images","all-albums") NOT NULL DEFAULT "image", 39 `element_id` mediumint(8) DEFAULT NULL, 40 `language` varchar(64) NOT NULL, 41 `email` varchar(255) NOT NULL, 42 `registration_date` datetime NOT NULL, 43 `validated` enum("true","false") NOT NULL DEFAULT "false", 44 PRIMARY KEY (`id`), 45 UNIQUE KEY `UNIQUE` (`email` , `type` , `element_id`) 46 ) DEFAULT CHARSET=utf8 47 ;'); 48 49 // table structure upgrade in 1.1 50 $result = pwg_query('SHOW COLUMNS FROM `'. $this->table .'` LIKE "element_id";'); 51 if (!pwg_db_num_rows($result)) 52 { 53 // backup subscriptions 54 $query = 'SELECT * FROM `'. $this->table .'` ORDER BY registration_date;'; 55 $subscriptions = query2array($query, 'id'); 56 57 // upgrade the table 58 pwg_query('TRUNCATE TABLE `'. $this->table .'`;'); 59 pwg_query('ALTER TABLE `'. $this->table .'` DROP `image_id`, DROP `category_id`;'); 60 pwg_query('ALTER TABLE `'. $this->table .'` AUTO_INCREMENT = 1;'); 61 62 $query = ' 63 ALTER TABLE `'. $this->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 `'. $this->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($this->table, $dbfields, $inserts); 102 } 103 } 104 105 $this->installed = true; 106 } 107 108 function activate($plugin_version, &$errors=array()) 109 { 110 if (!$this->installed) 111 { 112 $this->install($plugin_version, $errors); 113 } 114 } 115 116 function deactivate() 117 { 118 } 119 120 function uninstall() 121 { 122 conf_delete_param('Subscribe_to_Comments'); 123 124 pwg_query('DROP TABLE `'. $this->table .'`;'); 19 125 } 20 126 } 21 22 function plugin_uninstall()23 {24 global $prefixeTable;25 26 pwg_query('DROP TABLE `'. $prefixeTable . 'subscribe_to_comments`;');27 pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "Subscribe_to_Comments" LIMIT 1;');28 }29 ?>
Note: See TracChangeset
for help on using the changeset viewer.