-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmetatag_setup.php
199 lines (163 loc) · 3.66 KB
/
metatag_setup.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
/**
* @file
* Installation hooks and callbacks of metatag plugin.
*/
if(!defined('e107_INIT'))
{
exit;
}
/**
* Class metatag_setup.
*/
class metatag_setup
{
/**
* This function is called before plugin table has been created
* by the metatag_sql.php file.
*
* @param array $var
*/
function install_pre($var)
{
}
/**
* This function is called after plugin table has been created
* by the metatag_sql.php file.
*
* @param array $var
*/
function install_post($var)
{
e107_require_once(e_PLUGIN . 'metatag/includes/metatag.class.php');
$meta = new metatag();
$meta->updateAddonList();
$meta->setCronJob();
}
function uninstall_options()
{
}
function uninstall_post($var)
{
}
/**
* Call During Upgrade Check. May be used to check for existence of tables
* etc... and if not found return TRUE to call for an upgrade.
*
* @param array $var
*
* @return bool
* True to trigger an upgrade alert, and false to not.
*/
function upgrade_required($var)
{
$xml = e107::getXml();
$sql = e107::getDb();
// Current version.
$version = $sql->retrieve('plugin', 'plugin_version', 'plugin_path = "metatag"');
if(empty($version))
{
return false;
}
$plugInfo = $xml->loadXMLfile(e_PLUGIN . 'metatag/plugin.xml', 'advanced');
$version_new = $plugInfo['@attributes']['version'] ?? NULL;
if(empty($version_new))
{
return false;
}
if(version_compare($version, $version_new, '<'))
{
return true;
}
return false;
}
/**
* Before Automatic Upgrade Routine has completed... run this.
*
* @param $var
*/
function upgrade_pre($var)
{
$sql = e107::getDb();
$version = $sql->retrieve('plugin', 'plugin_version', 'plugin_path = "metatag"');
if(!empty($version) && version_compare($version, '1.6', '<'))
{
$this->upgrade_n_to_16();
}
if(!empty($version) && version_compare($version, '1.7', '<'))
{
$this->upgrade_n_to_17();
}
}
/**
* After Automatic Upgrade Routine has completed... run this.
*
* @param $var
*/
function upgrade_post($var)
{
$sql = e107::getDb();
// Clear the cache.
$sql->truncate('metatag_cache');
}
/**
* Upgrades Metatag plugin from version N to 1.6.
*/
function upgrade_n_to_16()
{
e107_require_once(e_PLUGIN . 'metatag/includes/metatag.class.php');
$meta = new metatag();
$sql1 = e107::getDb('select');
$sql2 = e107::getDb('update');
// Update metatag_default table data.
$sql1->select('metatag_default', '*', '', true);
while($row = $sql1->fetch())
{
if(empty($row['data']) || base64_encode(base64_decode($row['data'])) != $row['data'])
{
continue;
}
$data = unserialize(base64_decode($row['data']));
$sql2->update('metatag_default', [
'data' => [
'data' => $meta->serialize($data),
],
'WHERE' => 'id = "' . $row['id'] . '"',
]);
}
// Update metatag table data.
$sql1->select('metatag', '*', '', true);
while($row = $sql1->fetch())
{
if(empty($row['data']) || base64_encode(base64_decode($row['data'])) != $row['data'])
{
continue;
}
$data = unserialize(base64_decode($row['data']));
$sql2->update('metatag', [
'data' => [
'data' => $meta->serialize($data),
],
'WHERE' => 'entity_id = "' . $row['entity_id'] . '" AND entity_type = "' . $row['entity_type'] . '"',
]);
}
}
/**
* Upgrades Metatag plugin from version N to 1.7.
*/
function upgrade_n_to_17()
{
e107::getPlugConfig('metatag')
->setPref('override', 1)
->setPref('groups', array(
'basic' => 1,
'advanced' => 1,
'opengraph' => 1,
'facebook' => 1,
'twitter' => 1,
'dublin' => 1,
'google' => 1,
))
->save(false, true);
}
}