-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathclass.ext_update.php
More file actions
executable file
·272 lines (233 loc) · 10.7 KB
/
Copy pathclass.ext_update.php
File metadata and controls
executable file
·272 lines (233 loc) · 10.7 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Kay Strobach (typo3@kay-strobach.de)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* class.ext_update.php.
*
* extmgm update script
*
* $Id: class.ext_update.php 66302 2012-09-24 12:06:02Z kaystrobach $
*
* @author Kay Strobach <typo3@kay-strobach.de>
*/
class ext_update
{
public function access($what = 'all')
{
return true;
}
public function main()
{
global $LANG;
$LANG->includeLLFile('EXT:piwikintegration/Resources/Private/Language/locallang.xlf');
$func = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('func'));
$buffer = '';
if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('do_update')) {
if (method_exists($this, $func)) {
try {
$result = $this->$func();
$flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $result, '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK);
} catch (Exception $e) {
$result = $e->getMessage();
$flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $result, '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
}
$buffer .= $flashMessage->render();
} else {
$buffer .= $LANG->getLL('methodNotFound');
}
}
try {
\KayStrobach\Piwikintegration\Lib\Install::getInstaller()->getConfigObject();
} catch (Exception $e) {
$flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $LANG->getLL('installedPiwikNeeded'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO
);
$buffer .= $flashMessage->render();
}
$buffer .= $this->getHeader($LANG->getLL('header.installation'));
$buffer .= $this->getButton('installPiwik', false);
$buffer .= $this->getButton('updatePiwik');
$buffer .= $this->getButton('removePiwik');
$buffer .= $this->getFooter();
$buffer .= $this->getHeader($LANG->getLL('header.configuration'));
$buffer .= $this->getButton('patchPiwik');
$buffer .= $this->getButton('configurePiwik');
$buffer .= $this->getButton('enableSuggestedPlugins');
$buffer .= $this->getButton('respectGermanDataPrivacyAct');
$buffer .= $this->getButton('showPiwikConfig');
$buffer .= $this->getFooter();
$buffer .= $this->getHeader($LANG->getLL('header.database'));
$buffer .= $this->getButton('renameTables');
$buffer .= $this->getButton('resetUserRights');
$buffer .= $this->getButton('deletePiwikTables');
$buffer .= $this->getButton('createPiwikTables');
$buffer .= $this->getFooter();
return $buffer;
}
public function getHeader($text)
{
$buffer = '';
$buffer .= '<table class="typo3-dblist">';
$buffer .= '<cols><col width="80%"><col width="20%"></cols>';
$buffer .= '<tr class="t3-row-header"><td colspan="2">'.$text.'</td></tr>';
return $buffer;
}
public function getFooter()
{
return '</table>';
}
public function getButton($func, $piwikNeeded = true)
{
global $LANG;
$params = ['do_update' => 1, 'func' => $func];
$onClick = "document.location='".\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript($params)."'; return false;";
$button = '<tr class="db_list_normal">';
$button .= '<td>';
$button .= '<span class="typo3-dimmed" style="float:right;">['.$func.']</span>';
$button .= '<b style="float:left;">'.$LANG->getLL('action.'.$func).'</b><br>';
$button .= '<p>'.$LANG->getLL('desc.'.$func).'</p>';
$button .= '</td><td>';
try {
if ($piwikNeeded) {
\KayStrobach\Piwikintegration\Lib\Install::getInstaller()->getConfigObject();
}
if (method_exists($this, $func)) {
$button .= '<input type="submit" value="'.$LANG->getLL('button.DoIt').'" onclick="'.htmlspecialchars($onClick).'">';
} else {
$button .= '<input type="submit" value="'.$LANG->getLL('button.DoIt').'" onclick="'.htmlspecialchars($onClick).'" disabled="disabled" title="Method not implemented!">';
}
} catch (Exception $e) {
$button .= '<input type="submit" value="'.$LANG->getLL('button.DoIt').'" onclick="'.htmlspecialchars($onClick).'" disabled="disabled" title="Matomo not installed!">';
}
$button .= '</td>';
$button .= '</tr>';
return $button;
}
public function installPiwik()
{
$installer = \KayStrobach\Piwikintegration\Lib\Install::getInstaller();
$installer->installPiwik();
return $GLOBALS['LANG']->getLL('action.installPiwik.success');
}
public function updatePiwik()
{
throw new Exception($GLOBALS['LANG']->getLL('action.updatePiwik.error'));
}
public function removePiwik()
{
$installer = \KayStrobach\Piwikintegration\Lib\Install::getInstaller();
if (!$installer->removePiwik()) {
throw new Exception($GLOBALS['LANG']->getLL('action.removePiwik.error'));
}
return $GLOBALS['LANG']->getLL('action.removePiwik.success');
}
public function patchPiwik()
{
$installer = \KayStrobach\Piwikintegration\Lib\Install::getInstaller();
$exclude = [
'config/config.ini.php',
];
$installer->patchPiwik($exclude);
return $GLOBALS['LANG']->getLL('action.patchPiwik.success');
}
public function configurePiwik()
{
$installer = \KayStrobach\Piwikintegration\Lib\Install::getInstaller();
$installer->getConfigObject()->makePiwikConfigured();
return $GLOBALS['LANG']->getLL('action.configurePiwik.success');
}
public function resetUserRights()
{
$installer = \KayStrobach\Piwikintegration\Lib\Install::getInstaller();
$installer->getConfigObject();
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(\KayStrobach\Piwikintegration\Lib\Div::getDBandTableName('access'));
$connection->truncate(\KayStrobach\Piwikintegration\Lib\Div::getDBandTableName('access'));
return $GLOBALS['LANG']->getLL('action.resetUserRights.success');
}
public function deletePiwikTables()
{
\KayStrobach\Piwikintegration\Lib\Install::getInstaller()->getConfigObject()->initPiwikDatabase();
$tablesInstalled = \Piwik\DbHelper::getTablesInstalled();
$buffer = $GLOBALS['LANG']->getLL('action.deletePiwikTables.success');
foreach ($tablesInstalled as $table) {
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
$connection->prepare('DROP TABLE `'.$table.'`')
->execute();
$buffer .= $table.', ';
}
return $buffer;
}
public function createPiwikTables()
{
$this->deletePiwikTables();
\KayStrobach\Piwikintegration\Lib\Install::getInstaller()->getConfigObject()->installDatabase();
return $GLOBALS['LANG']->getLL('action.createPiwikTables.success');
}
public function showPiwikConfig()
{
$path = \KayStrobach\Piwikintegration\Lib\Install::getInstaller()->getAbsInstallPath().'piwik/config/config.ini.php';
$button = $path;
$button .= '</b><pre style="width:80%;height:300px;overflow-y:scroll;border:1px solid silver;padding:10px;">';
$button .= file_get_contents($path);
$button .= '</pre><b>';
return $button;
}
public function enableSuggestedPlugins()
{
$config = \KayStrobach\Piwikintegration\Lib\Install::getInstaller()->getConfigObject();
$suggestedPlugins = $config->enableSuggestedPlugins();
$config->disablePlugin('Login');
return 'Installed: '.$suggestedPlugins.'<br />Removed: Login';
}
public function respectGermanDataPrivacyAct()
{
$config = \KayStrobach\Piwikintegration\Lib\Install::getInstaller()->getConfigObject();
\KayStrobach\Piwikintegration\Lib\Install::getInstaller()->getConfigObject()->enablePlugin('AnonymizeIP');
$config->setOption('Tracker', 'ip_address_mask_length', 2);
$config->setOption('Tracker', 'cookie_expire', 604800);
return 'Installed: AnonymizeIP<br />Set: Tracker.ip_address_mask_length=2<br />Set: Tracker.cookie_expire=604800';
}
public function renameTables()
{
$buffer = 'Renamed all tables prepended with tx_piwikintegration to user_piwikintegration:';
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('be_users')->getSchemaManager();
$tablesInstalled = $connection->listTableNames();
foreach ($tablesInstalled as $table) {
if (substr($table, 0, 20) === 'tx_piwikintegration_') {
$newTableName = str_replace('tx_piwikintegration_', 'user_piwikintegration_', $table);
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
$connection->prepare('RENAME TABLE `'.$table.'` to `'.$newTableName.'`')
->execute();
$buffer .= $table.', ';
}
}
\KayStrobach\Piwikintegration\Lib\Install::getInstaller()->getConfigObject()->setOption('database', 'tables_prefix', 'user_piwikintegration_');
return $buffer;
}
}