-
Notifications
You must be signed in to change notification settings - Fork 2
/
maintain.class.php
99 lines (84 loc) · 2.24 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
<?php
defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
class ColorPalette_maintain extends PluginMaintain
{
private $default_conf = array(
'colors' => 8,
'sample_size' => 150,
'coverage' => 100,
'generate_on_image_page' => true
);
private $table;
function __construct($plugin_id)
{
parent::__construct($plugin_id);
global $prefixeTable;
$this->table = $prefixeTable . 'color_palette';
}
function install($plugin_version, &$errors=array())
{
global $conf;
if (empty($conf['ColorPalette']))
{
conf_update_param('ColorPalette', $this->default_conf, true);
}
else
{
$old_conf = safe_unserialize($conf['ColorPalette']);
// Add missing parameters to conf
foreach ($this->default_conf as $key => $value)
{
if (!array_key_exists($key, $old_conf))
{
$old_conf[$key] = $value;
}
}
conf_update_param('ColorPalette', $old_conf, true);
}
$query = '
CREATE TABLE IF NOT EXISTS `' . $this->table . '` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`color_r` tinyint(3) unsigned NOT NULL,
`color_g` tinyint(3) unsigned NOT NULL,
`color_b` tinyint(3) unsigned NOT NULL,
`image_id` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `image_id` (`image_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
;';
pwg_query($query);
$rgbid = 'colpal_rgbid';
if (!$this->has_index($rgbid))
{
$query = '
CREATE INDEX `' . $rgbid . '` ON `' . $this->table . '` (
color_r, color_g, color_b, image_id
);';
pwg_query($query);
}
}
function update($old_version, $new_version, &$errors=array())
{
$this->install($new_version, $errors);
}
function uninstall()
{
conf_delete_param('ColorPalette');
pwg_query('DROP TABLE `' . $this->table . '`;');
$rgbid = 'colpal_rgbid';
if ($this->has_index($rgbid))
{
pwg_query('DROP INDEX `' . $rgbid . '` ON `' . $this->table . '`;');
}
}
function has_index($name)
{
$query = '
SELECT COUNT(1) AS `has_index`
FROM INFORMATION_SCHEMA.STATISTICS
WHERE `table_name` = "' . $this->table . '" AND `index_name` = "' . $name. '"
;';
list($has_index) = query2array($query, null, 'has_index');
return $has_index;
}
}