-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclass.ext_update.php
124 lines (110 loc) · 3.66 KB
/
class.ext_update.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
<?php
/***************************************************************
* Copyright notice
*
* (c) 2011 Tymoteusz Motylewski
* 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!
***************************************************************/
/**
* Update class for extmgr,
* inspired by news extension
*/
class ext_update
{
public const STATUS_WARNING = -1;
public const STATUS_ERROR = 0;
public const STATUS_OK = 1;
protected $messageArray = [];
protected function changeGender()
{
$status = self::STATUS_OK;
$title = 'Changing gender type form varchar to int';
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'count(*)',
'fe_users',
"gender like '%male%'",
'',
'',
''
);
$entry = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
$message = '';
if ($entry['count(*)'] <= 0) {
$message = 'Everything is up to date';
} else {
$updateArray = ['gender' => 0];
$res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', "gender = 'male'", $updateArray);
if ($res === false) {
$message .= "\n" . ' Could not change gender "male"';
$status = self::STATUS_ERROR;
}
$updateArray['gender'] = 1;
$res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', "gender = 'female'", $updateArray);
if ($res === false) {
$message .= "\n" . ' Could not change gender "female"';
$status = self::STATUS_ERROR;
}
$sql = "ALTER TABLE fe_users CHANGE gender gender int(11) unsigned default '0'";
if ($GLOBALS['TYPO3_DB']->admin_query($sql) === false) {
$message .= ' SQL ERROR: ' . $GLOBALS['TYPO3_DB']->sql_error();
$status = self::STATUS_ERROR;
} else {
$message .= 'OK!';
$status = self::STATUS_OK;
}
}
$this->messageArray[] = [$status, $title, $message];
}
/**
* Main update function called by the extension manager.
*
* @return string
*/
public function main()
{
$this->changeGender();
return $this->generateOutput();
}
/**
* Generates more or less readable output.
*
* @todo: beautify output :)
* @return string
*/
protected function generateOutput()
{
$output = '';
foreach ($this->messageArray as $messageItem) {
$output .= '<strong>' . $messageItem[1] . '</strong><br />' .
' ->' . $messageItem[2] . '<br /><br />';
}
return $output;
}
/**
* Called by the extension manager to determine if the update menu entry
* should by showed.
*
* @return bool
* @todo find a better way to determine if update is needed or not.
*/
public function access()
{
return true;
}
}