forked from Ecodev/speciality
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.ext_update.php
116 lines (95 loc) · 3.64 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
<?php
namespace Abteilung\Speciality;
/*
* This file is part of the Abteilung\Speciality project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
/**
* Class ext_update
*/
class ext_update
{
/**
* @return boolean
*/
public function access()
{
return false;
}
/**
* @return string
*/
public function main()
{
$lines[] = $this->updatePagesTemplate();
$lines[] = $this->updateContentTemplatefile();
return implode('<br/>', $lines);
}
/**
* @return string
* @throws \InvalidArgumentException
*/
private function updatePagesTemplate()
{
// Fetch records that needs to be updated
$records = $this->getDatabaseConnection()->exec_SELECTgetRows(
'uid, tx_fed_page_controller_action, tx_fed_page_controller_action_sub',
'pages',
'tx_fed_page_controller_action != "" OR tx_fed_page_controller_action_sub != "" AND deleted = 0'
);
$counter = 0;
foreach ($records as $record) {
$values = [];
if (preg_match('/speciality->/', $record['tx_fed_page_controller_action'])) {
$parts = explode('->', $record['tx_fed_page_controller_action']);
$values['tx_fed_page_controller_action'] = ucfirst($parts[0]) . '->' . lcfirst($parts[1]);
}
if (preg_match('/speciality->/', $record['tx_fed_page_controller_action_sub'])) {
$parts = explode('->', $record['tx_fed_page_controller_action_sub']);
$values['tx_fed_page_controller_action_sub'] = ucfirst($parts[0]) . '->' . lcfirst($parts[1]);
}
if (count($values) > 0) {
$counter++;
$this->getDatabaseConnection()->exec_UPDATEquery('pages', 'uid = ' . $record['uid'], $values);
}
}
if ($counter > 0) {
$result = sprintf('- %s page(s) have been updated fields "tx_fed_page_controller_action" and "tx_fed_page_controller_action_sub".', count($records));
} else {
$result = '- After checking no update was necessary in pages.';
}
return $result;
}
/**
* @return string
* @throws \InvalidArgumentException
*/
private function updateContentTemplatefile()
{
$result = '- Extension "fluidbootstraptheme" is still enabled. I will not do anything!';
if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('fluidbootstraptheme')) {
$records = $this->getDatabaseConnection()->exec_SELECTgetRows('uid, tx_fed_fcefile', 'tt_content', 'tx_fed_fcefile LIKE "FluidBT.Fluidbootstraptheme%"');
foreach ($records as $record) {
$values['tx_fed_fcefile'] = str_replace('FluidBT.Fluidbootstraptheme', 'speciality', $record['tx_fed_fcefile']);
$this->getDatabaseConnection()->exec_UPDATEquery('tt_content', 'uid = ' . $record['uid'], $values);
}
if (count($records) > 0) {
$result = sprintf('- %s record(s) have been updated with value "FluidBT.Fluidbootstraptheme" by "speciality" in field "tx_fed_fcefile".', count($records));
} else {
$result = '- After checking no update was necessary in tt_content.';
}
}
return $result;
}
/**
* Returns a pointer to the database.
*
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
*/
protected function getDatabaseConnection()
{
return $GLOBALS['TYPO3_DB'];
}
}