[16591] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
[25678] | 4 | class UserCollections_maintain extends PluginMaintain |
---|
[16591] | 5 | { |
---|
[25678] | 6 | private $installed = false; |
---|
[16591] | 7 | |
---|
[25678] | 8 | function install($plugin_version, &$errors=array()) |
---|
[16658] | 9 | { |
---|
[25678] | 10 | global $conf, $prefixeTable; |
---|
| 11 | |
---|
| 12 | if (empty($conf['user_collections'])) |
---|
| 13 | { |
---|
| 14 | $conf['user_collections'] = serialize(array( |
---|
| 15 | 'allow_mails' => true, |
---|
| 16 | 'allow_public' => true, |
---|
| 17 | )); |
---|
| 18 | |
---|
| 19 | conf_update_param('user_collections', $conf['user_collections']); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | // create tables |
---|
| 23 | $query = ' |
---|
| 24 | CREATE TABLE IF NOT EXISTS `'.$prefixeTable.'collections` ( |
---|
| 25 | `id` mediumint(8) NOT NULL AUTO_INCREMENT, |
---|
| 26 | `user_id` smallint(5) DEFAULT NULL, |
---|
| 27 | `name` varchar(255) NOT NULL, |
---|
| 28 | `date_creation` datetime NOT NULL, |
---|
| 29 | `comment` text NULL, |
---|
| 30 | `nb_images` mediumint(8) NOT NULL DEFAULT 0, |
---|
| 31 | PRIMARY KEY (`id`) |
---|
| 32 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 |
---|
| 33 | ;'; |
---|
| 34 | pwg_query($query); |
---|
| 35 | |
---|
| 36 | $query = ' |
---|
| 37 | CREATE TABLE IF NOT EXISTS `'.$prefixeTable.'collection_images` ( |
---|
| 38 | `col_id` mediumint(8) NOT NULL, |
---|
| 39 | `image_id` mediumint(8) NOT NULL, |
---|
| 40 | `add_date` datetime NULL, |
---|
| 41 | UNIQUE KEY `UNIQUE` (`col_id`,`image_id`) |
---|
| 42 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
---|
| 43 | ;'; |
---|
| 44 | pwg_query($query); |
---|
| 45 | |
---|
| 46 | $query = ' |
---|
| 47 | CREATE TABLE IF NOT EXISTS `'.$prefixeTable.'collection_shares` ( |
---|
| 48 | `id` mediumint(8) NOT NULL AUTO_INCREMENT, |
---|
| 49 | `col_id` mediumint(8) NOT NULL, |
---|
| 50 | `share_key` varchar(64) NOT NULL, |
---|
| 51 | `params` text NULL, |
---|
| 52 | `add_date` datetime NOT NULL, |
---|
| 53 | PRIMARY KEY (`id`), |
---|
| 54 | UNIQUE KEY `share_key` (`share_key`) |
---|
| 55 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 |
---|
| 56 | ;'; |
---|
| 57 | pwg_query($query); |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | // version 2.0.0 |
---|
| 61 | $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'collection_images` LIKE "add_date";'); |
---|
| 62 | if (!pwg_db_num_rows($result)) |
---|
| 63 | { |
---|
| 64 | pwg_query('ALTER TABLE `'.$prefixeTable.'collection_images` ADD `add_date` datetime NULL;'); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'collections` LIKE "comment";'); |
---|
| 68 | if (!pwg_db_num_rows($result)) |
---|
| 69 | { |
---|
| 70 | pwg_query('ALTER TABLE `'.$prefixeTable.'collections` ADD `comment` text NULL;'); |
---|
| 71 | pwg_query('ALTER TABLE `'.$prefixeTable.'collections` DROP `active`;'); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | // version 2.1.0 |
---|
| 75 | $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'collections` LIKE "public";'); |
---|
| 76 | if (pwg_db_num_rows($result)) |
---|
| 77 | { |
---|
| 78 | $now = date('Y-m-d H:i:s'); |
---|
| 79 | |
---|
| 80 | $query = ' |
---|
| 81 | SELECT id, public_id |
---|
| 82 | FROM `'.$prefixeTable.'collections` |
---|
| 83 | WHERE public = 1 |
---|
| 84 | ;'; |
---|
| 85 | $result = pwg_query($query); |
---|
| 86 | |
---|
| 87 | $inserts = array(); |
---|
| 88 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 89 | { |
---|
| 90 | $inserts[] = array( |
---|
| 91 | 'col_id' => $row['id'], |
---|
| 92 | 'share_key' => $row['public_id'], |
---|
| 93 | 'params' => serialize(array('password'=>'','deadline'=>'')), |
---|
| 94 | 'add_date' => $now, |
---|
| 95 | ); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | mass_inserts($prefixeTable.'collection_shares', |
---|
| 99 | array('col_id','share_key','params','add_date'), |
---|
| 100 | $inserts |
---|
| 101 | ); |
---|
| 102 | |
---|
| 103 | pwg_query('ALTER TABLE `'.$prefixeTable.'collections` DROP `public`, DROP `public_id`;'); |
---|
| 104 | } |
---|
[26055] | 105 | |
---|
| 106 | $this->installed = true; |
---|
[16658] | 107 | } |
---|
[16591] | 108 | |
---|
[25678] | 109 | function activate($plugin_version, &$errors=array()) |
---|
| 110 | { |
---|
| 111 | if (!$this->installed) |
---|
| 112 | { |
---|
| 113 | $this->install($plugin_version, $errors); |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | function deactivate(){} |
---|
| 118 | |
---|
| 119 | function uninstall() |
---|
| 120 | { |
---|
| 121 | global $prefixeTable; |
---|
| 122 | |
---|
| 123 | conf_delete_param('user_collections'); |
---|
| 124 | |
---|
| 125 | pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'collections`;'); |
---|
| 126 | pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'collection_images`;'); |
---|
| 127 | pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'collection_shares`;'); |
---|
| 128 | } |
---|
[16591] | 129 | } |
---|