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