[12447] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
[27697] | 4 | class AddUsersNotes_maintain extends PluginMaintain |
---|
[12447] | 5 | { |
---|
[27697] | 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 | { |
---|
[12447] | 15 | global $prefixeTable; |
---|
[27697] | 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 | } |
---|
[12447] | 23 | |
---|
[27697] | 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); |
---|
[12447] | 37 | |
---|
[27697] | 38 | pwg_query('DROP TABLE '.$prefixeTable.'user_notes;'); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | $this->installed = true; |
---|
| 42 | } |
---|
[12447] | 43 | |
---|
[27697] | 44 | function activate($plugin_version, &$errors=array()) |
---|
| 45 | { |
---|
| 46 | if (!$this->installed) |
---|
| 47 | { |
---|
| 48 | $this->install($plugin_version, $errors); |
---|
| 49 | } |
---|
| 50 | } |
---|
[12447] | 51 | |
---|
[29854] | 52 | function update($old_version, $new_version, &$errors=array()) |
---|
| 53 | { |
---|
| 54 | $this->install($new_version, $errors); |
---|
| 55 | } |
---|
| 56 | |
---|
[27697] | 57 | function deactivate() |
---|
| 58 | { |
---|
| 59 | } |
---|
[12447] | 60 | |
---|
[27697] | 61 | function uninstall() |
---|
| 62 | { |
---|
| 63 | pwg_query('ALTER TABLE `'. USER_INFOS_TABLE .'` DROP `usernotes`;'); |
---|
| 64 | } |
---|
| 65 | } |
---|
[12447] | 66 | ?> |
---|