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