-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.ext_update.php
140 lines (124 loc) · 3.98 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Extension manager update script
* @see https://docs.typo3.org/typo3cms/CoreApiReference/singlehtml/
* [Example-2]
*
* @package EHAERER\EhBootstrap
*/
class ext_update
{
/**
* @var \TYPO3\CMS\Core\Messaging\FlashMessageQueue
* @inject
*/
protected $flashMessageQueue;
/**
* @var string
*/
protected $extensionKey = 'eh_bootstrap';
/**
* Check if upgrade script is needed (this function is called from the extension manager)
*
* @return boolean
*/
public function access()
{
return $this->getBackendUserAuthentication()->isAdmin();
}
/**
* Run upgrade scripts (this function is called from the extension manager)
*
* @return string
*/
public function main()
{
$updateScriptLink = BackendUtility::getModuleUrl('tools_ExtensionmanagerExtensionmanager', [
'tx_extensionmanager_tools_extensionmanagerextensionmanager' => [
'extensionKey' => $this->extensionKey,
'action' => 'show',
'controller' => 'UpdateScript',
],
]);
$view = $this->getView();
$viewValues = ['formAction' => $updateScriptLink];
if ((int) GeneralUtility::_GP('doSomething') === 1) {
$contentElements = $this->doSomething();
$viewValues['contentElements'] = $contentElements;
}
$view->assignMultiple($viewValues);
return $view->render();
}
/**
* Get tt_content data
*
* @return array
*/
protected function doSomething()
{
$table = 'tt_content';
$res = $this->getDatabaseConnection()->exec_SELECTgetRows(
'uid, pid, tstamp, crdate, CType, header', $table, '', '', '', 1000
);
/* @var $message \TYPO3\CMS\Core\Messaging\FlashMessage */
if (count($res) > 0) {
$message = $this->getObjectManager()->get(
\TYPO3\CMS\Core\Messaging\FlashMessage::class, 'A total of ' . count($res) . ' content elements found.', 'Content elements found', FlashMessage::OK
);
} else {
$message = $this->getObjectManager()->get(
\TYPO3\CMS\Core\Messaging\FlashMessage::class, 'No content elements found.', 'Nothing to do', FlashMessage::ERROR
);
}
$this->getFlashMessageQueue()->enqueue($message);
return $res;
}
/**
* @return \TYPO3\CMS\Extbase\Object\ObjectManager
*/
protected function getObjectManager()
{
return GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
}
/**
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
*/
protected function getDatabaseConnection()
{
return $GLOBALS['TYPO3_DB'];
}
/**
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
*/
protected function getBackendUserAuthentication()
{
return $GLOBALS['BE_USER'];
}
/**
* @return \TYPO3\CMS\Fluid\View\StandaloneView
*/
protected function getView()
{
/* @var $view \TYPO3\CMS\Fluid\View\StandaloneView */
$view = $this->getObjectManager()->get(\TYPO3\CMS\Fluid\View\StandaloneView::class);
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:' . $this->extensionKey . '/Resources/Private/Templates/UpdateScript/Index.html'));
$view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:' . $this->extensionKey . '/Resources/Private/Layouts')]);
$view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:' . $this->extensionKey . '/Resources/Private/Partials')]);
return $view;
}
/**
* @return \TYPO3\CMS\Core\Messaging\FlashMessageQueue
*/
protected function getFlashMessageQueue()
{
if (!isset($this->flashMessageQueue)) {
/* @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
$flashMessageService = $this->getObjectManager()->get(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
$this->flashMessageQueue = $flashMessageService->getMessageQueueByIdentifier('reintcontentelements.errors');
}
return $this->flashMessageQueue;
}
}