-
Notifications
You must be signed in to change notification settings - Fork 1
/
maintain.class.php
145 lines (119 loc) · 3.75 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
<?php
defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
#[AllowDynamicProperties]
class piwigo_pem_maintain extends PluginMaintain
{
private $installed = false;
function __construct($plugin_id)
{
parent::__construct($plugin_id);
}
/**
* plugin installation
*/
function install($plugin_version, &$errors=array())
{
include(PHPWG_ROOT_PATH.'admin/include/functions_install.inc.php');
global $prefixeTable, $conf;
$this->table = $prefixeTable.'pem_'.'categories';
//add remind every and last-reminder to user_infos to be able to convert existing pem users into piwigo users
$this->table = $prefixeTable.'user_infos';
$result = pwg_query('SHOW COLUMNS FROM `'.$this->table.'` LIKE "pem_remind_every";');
if (!pwg_db_num_rows($result))
{
pwg_query('ALTER TABLE `' . $this->table . '` ADD `pem_remind_every` ENUM ("day","week","month") default "week";');
}
$result = pwg_query('SHOW COLUMNS FROM `'.$this->table.'` LIKE "pem_last_reminder";');
if (!pwg_db_num_rows($result))
{
pwg_query('ALTER TABLE `' . $this->table . '` ADD `pem_last_reminder` DATETIME;');
}
// Convert pem users to piwigo user, only to be called on first install of PEM plugin with and exisiting database
if(isset($_GET['convert_users']) and $conf['start_converting_users'] == $_GET['convert_users'])
{
include( PHPWG_ROOT_PATH.'plugins/piwigo_pem/include/convert_users.inc.php');
}
//Add two files to Piwigo, due to download.php and extension_view.php no longer being in the same place,
// this allows Piwigos to still communicate with PEM without changing the code
$c = <<<EOF
<?php
define('PHPWG_ROOT_PATH','./');
include(PHPWG_ROOT_PATH.'plugins/piwigo_pem/download.php');
?>
EOF;
if (!file_put_contents(PHPWG_ROOT_PATH.'download.php', $c)) {
error_reporting($_error_reporting);
throw new SmartyException("unable to write file {$PHPWG_ROOT_PATH}download.php");
}
$c = <<<EOF
<?php
include('plugins/piwigo_pem/extension_view.php');
?>
EOF;
if (!file_put_contents(PHPWG_ROOT_PATH.'extension_view.php', $c)) {
error_reporting($_error_reporting);
throw new SmartyException("unable to write file {$PHPWG_ROOT_PATH}extension_view.php");
}
}
/**
* 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()
{
include(PHPWG_ROOT_PATH.'admin/include/functions_install.inc.php');
global $prefixeTable, $logger;
$tables_to_drop = array(
'authors',
'categories',
'categories_translations',
'download_log',
'extensions',
'extensions_categories',
'extensions_tags',
'extensions_translations',
'hosting_details',
'languages',
'links',
'rates',
'reviews',
'revisions',
'revisions_compatibilities',
'revisions_languages',
'revisions_translations',
'tags',
'tags_translations',
'user_infos',
'users',
'versions',
);
foreach ($tables_to_drop as $table)
{
$query = 'DROP TABLE '.$prefixeTable.'pem_'.$table.';';
pwg_query($query);
}
$this->table = $prefixeTable.'user_infos';
pwg_query('ALTER TABLE `' . $this->table . '` DROP `pem_remind_every`;');
pwg_query('ALTER TABLE `' . $this->table . '` DROP `pem_last_reminder`;');
@unlink(PHPWG_ROOT_PATH.'download.php');
@unlink(PHPWG_ROOT_PATH.'extension_view.php');
}
}