This repository was archived by the owner on May 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathclass.ext_update.php
More file actions
executable file
·163 lines (140 loc) · 5.45 KB
/
class.ext_update.php
File metadata and controls
executable file
·163 lines (140 loc) · 5.45 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
<?php
/***************************************************************
* Copyright notice
*
* (c) 2007 Mittwald CM Service
* 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.
*
* 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!
***************************************************************/
/**
* This class handles the update process between different mm_forum
* versions. For example, there was a change of table and field
* names between versions 0.0.3 and 0.0.4. This script guarantees
* backwards compatibility.
*
* @author Martin Helmich <m.helmich@mittwald.de>
* @version 2007-04-25
* @package mm_forum
* @subpackage ExtCore
*/
class ext_update {
/**
* Obsolete table names and their new names
*/
var $obsTableNames = array(
'tx_mmpm_inbox' => 'tx_mmforum_pminbox',
'tx_mmforumsearch_results' => 'tx_mmforum_searchresults',
'tx_mmforumsearch_wordlist' => 'tx_mmforum_wordlist',
'tx_mmforumsearch_wordmatch' => 'tx_mmforum_wordmatch'
);
/**
* Obsolete field names in the fe_user table and their new names
*/
var $obsFieldNames_feuser = array(
'tx_mmfeuserreg_interests' => 'tx_mmforum_interests',
'tx_mmfeuserreg_occ' => 'tx_mmforum_occ',
'tx_mmfeuserreg_reg_hash' => 'tx_mmforum_reg_hash'
);
var $action = array();
/**
* The main function. Executes all updates.
* @return string The update process output.
*/
function main() {
if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('do_update') == 'htaccess') {
$this->removeHtaccessFromUploadFolder();
}
$content = '';
foreach($this->action as $action) {
if ($action == 'rename_tables') $content .= $this->renameTables();
}
if ($this->hasHtaccessFile()) {
$content .= '<a href="' . \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('do_update' => 'htaccess')) . '">Remove .htaccess file in upload dir<img style="vertical-align:bottom;" ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/refresh_n.gif', 'width="18" height="16"') . '></a><br>';
}
if ($content == '')
$content = 'Nothing to update!';
return $content;
}
/**
* Renames tables and field names to make them 0.0.4-conform.
* @return string The update process output.
*/
function renameTables() {
$sql = $this->renameTables_getQuery();
$content = 'Executing the following MySQL queries:<br /><br />'.implode('<br />',$sql);
$content .= '<br /><br />';
foreach($sql as $singleQuery) {
$GLOBALS['TYPO3_DB']->sql_query($singleQuery);
}
return $content;
}
/**
* Generates the MySQL-queries for renaming all obsolete table and field names.
* @return array An array containing the MySQL-queries
*/
function renameTables_getQuery() {
$sql = array();
foreach($this->obsTableNames as $oldTable => $newTable) {
$sql[] = "DROP TABLE IF EXISTS $newTable";
$sql[] = "ALTER TABLE ".$oldTable." RENAME ".$newTable;
}
foreach($this->obsFieldNames_feuser as $oldField => $newField) {
$sql[] = "ALTER TABLE fe_users DROP $newField";
$sql[] = "ALTER TABLE fe_users CHANGE $oldField $newField tinytext NOT NULL";
}
return $sql;
}
/**
* Determines if an update is required and if so, what has to be done.
* This function determines if an update to a newer version is necessary.
* If the function notices, that an update is necessary, it will tell the
* main function what to do.
* @return boolean TRUE, if an update is required, otherwise FALSE.
*/
function access() {
// Check for deprecated table names
// Update check from 0.0.3 to 0.0.4
$res = $GLOBALS['TYPO3_DB']->sql_query('SHOW TABLES');
$tbl = array_keys($this->obsTableNames);
while($arr = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
if (in_array($arr[0],$tbl)) {
$this->action[] = 'rename_tables';
return true;
}
}
if ($this->hasHtaccessFile())
return true;
return false;
}
function hasHtaccessFile() {
if (file_exists(PATH_site.'uploads/tx_mmforum/.htaccess')) {
if (file_get_contents(PATH_site.'uploads/tx_mmforum/.htaccess') == 'deny from all')
return true;
}
return false;
}
function removeHtaccessFromUploadFolder() {
if (file_exists(PATH_site.'uploads/tx_mmforum/.htaccess')) {
if (file_get_contents(PATH_site.'uploads/tx_mmforum/.htaccess') == 'deny from all')
unlink(PATH_site.'uploads/tx_mmforum/.htaccess');
}
}
}
if (defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/mm_forum/class.ext_update.php']) {
include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/mm_forum/class.ext_update.php']);
}