Changeset 27697 for extensions/AddUsersNotes/maintain.inc.php
- Timestamp:
- Mar 11, 2014, 11:25:49 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/AddUsersNotes/maintain.inc.php
r12447 r27697 1 1 <?php 2 3 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 4 3 5 function plugin_install() 4 class AddUsersNotes_maintain extends PluginMaintain 6 5 { 6 private $installed = false; 7 8 function __construct($plugin_id) 9 { 10 parent::__construct($plugin_id); 11 } 12 13 function install($plugin_version, &$errors=array()) 14 { 7 15 global $prefixeTable; 16 17 // add a new column to existing table 18 $result = pwg_query('SHOW COLUMNS FROM `'.USER_INFOS_TABLE.'` LIKE "usernotes";'); 19 if (!pwg_db_num_rows($result)) 20 { 21 pwg_query('ALTER TABLE `' . USER_INFOS_TABLE . '` ADD `usernotes` VARCHAR(255) DEFAULT NULL;'); 22 } 8 23 9 if (!defined('USERNOTES_TABLE')) define('USERNOTES_TABLE', $prefixeTable.'user_notes'); 10 $query = "CREATE TABLE IF NOT EXISTS ". USERNOTES_TABLE ." ( 11 user_id SMALLINT( 5 ) UNSIGNED NOT NULL , 12 note VARCHAR( 255 ) NOT NULL , 13 PRIMARY KEY (user_id))DEFAULT CHARSET=utf8;"; 14 $result = pwg_query($query); 15 24 // if we find the old table, we copy notes 25 $result = pwg_query('SHOW TABLES LIKE "'.$prefixeTable.'user_notes";'); 26 if (pwg_db_num_rows($result)) 27 { 28 $query = ' 29 UPDATE 30 '.USER_INFOS_TABLE.' AS ui, 31 '.$prefixeTable.'user_notes AS un 32 SET ui.usernotes = un.note 33 WHERE ui.user_id = un.user_id 34 AND LENGTH(note) > 0 35 ;'; 36 pwg_query($query); 37 38 pwg_query('DROP TABLE '.$prefixeTable.'user_notes;'); 39 } 40 41 $this->installed = true; 42 } 43 44 function activate($plugin_version, &$errors=array()) 45 { 46 if (!$this->installed) 47 { 48 $this->install($plugin_version, $errors); 49 } 50 } 51 52 function deactivate() 53 { 54 } 55 56 function uninstall() 57 { 58 pwg_query('ALTER TABLE `'. USER_INFOS_TABLE .'` DROP `usernotes`;'); 59 } 16 60 } 17 18 function plugin_uninstall()19 {20 global $prefixeTable;21 22 $q = 'DROP TABLE ' . $prefixeTable . 'user_notes;';23 pwg_query($q);24 }25 26 27 61 ?>
Note: See TracChangeset
for help on using the changeset viewer.