-
Notifications
You must be signed in to change notification settings - Fork 3
/
maintain.class.php
152 lines (125 loc) · 3.72 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
144
145
146
147
148
149
150
151
152
<?php
defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
#[AllowDynamicProperties]
class expiry_date_maintain extends PluginMaintain
{
private $default_conf = array(
'expd_action' => 'nothing',
'expd_archive_album' => null,
'expd_notify' => false,
'expd_notify_before_option' => 'none',
'expd_notify_admin' => false,
'expd_notify_admin_before_option' => 'none',
);
private $installed = false;
function __construct($plugin_id)
{
parent::__construct($plugin_id);
}
/**
* plugin installation
*/
function install($plugin_version, &$errors=array())
{
global $conf, $prefixeTable;
$result = pwg_query('SHOW COLUMNS FROM `'.IMAGES_TABLE.'` LIKE "expiry_date" ');
if (!pwg_db_num_rows($result))
{
pwg_query('ALTER TABLE `'.IMAGES_TABLE.'` ADD `expiry_date` DATETIME;');
}
$result = pwg_query('SHOW COLUMNS FROM `'.IMAGES_TABLE.'` LIKE "expd_action_applied_on" ');
if (!pwg_db_num_rows($result))
{
pwg_query('ALTER TABLE `'.IMAGES_TABLE.'` ADD `expd_action_applied_on` DATETIME;');
}
$result = pwg_query('SHOW COLUMNS FROM `'.IMAGES_TABLE.'` LIKE "expd_expired_on" ');
if (!pwg_db_num_rows($result))
{
pwg_query('ALTER TABLE `'.IMAGES_TABLE.'` ADD `expd_expired_on` DATETIME;');
}
$this->table = $prefixeTable . 'expd_notifications';
pwg_query('
CREATE TABLE IF NOT EXISTS `'. $this->table .'` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`type` varchar(64) NOT NULL,
`user_id` int(11) NOT NULL,
`image_id` int(11) NOT NULL,
`send_date` DATETIME,
`email_used` varchar(64),
`email_uuid` varchar(10),
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
;');
// add a new column to existing table
$result = pwg_query('SHOW COLUMNS FROM `'.$this->table.'` LIKE "email_uuid";');
if (!pwg_db_num_rows($result))
{
pwg_query('ALTER TABLE `' . $this->table . '` ADD `email_uuid` varchar(10);');
}
if (!isset($conf['expiry_date']))
{
conf_update_param('expiry_date', $this->default_conf, true);
}
else
{
$old_conf = safe_unserialize($conf['expiry_date']);
$additional_conf_fields = array(
'expd_notify_before_option',
'expd_notify_admin',
'expd_notify_admin_before_option',
);
foreach ($additional_conf_fields as $fieldname)
{
if (empty($old_conf[$fieldname]))
{ // use case: this parameter was added in a new version
$old_conf[$fieldname] = $this->default_conf[$fieldname];
}
}
conf_update_param('expiry_date', $old_conf, true);
}
if (!isset($conf['expd_email_content']))
{
conf_update_param('expd_email_content', null, true);
}
if (!isset($conf['expd_admin_email_content']))
{
conf_update_param('expd_admin_email_content', null, true);
}
}
/**
* Plugin activation
*/
function activate($plugin_version, &$errors=array())
{
}
/**
* Plugin deactivation
*/
function deactivate()
{
}
/**
* Plugin (auto)update
*/
function update($old_version, $new_version, &$errors=array())
{
$this->install($new_version, $errors);
}
/**
* Plugin uninstallation
*/
function uninstall()
{
global $prefixeTable;
//delete table
$query = 'DROP TABLE '.$prefixeTable.'expd_notifications;';
pwg_query($query);
// delete field
pwg_query('ALTER TABLE `'. IMAGES_TABLE .'` DROP `expiry_date`, DROP `expd_action_applied_on`, DROP `expd_expired_on`;');
conf_delete_param('expiry_date');
conf_delete_param('expd_last_check');
conf_delete_param('expd_email_content');
conf_delete_param('expd_admin_email_content');
}
}
?>