Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.

Commit 3acee21

Browse files
author
Stefano Kowalke
committed
Merge branch 'release/1.1.0'
2 parents acbe842 + 0540e47 commit 3acee21

16 files changed

+846
-281
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
namespace Etobi\CoreAPI\Command;
3+
4+
/***************************************************************
5+
* Copyright notice
6+
*
7+
* (c) 2014 Helmut Hummel <[email protected]>
8+
* All rights reserved
9+
*
10+
* This script is part of the TYPO3 project. The TYPO3 project is
11+
* free software; you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation; either version 2 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* The GNU General Public License can be found at
17+
* http://www.gnu.org/copyleft/gpl.html.
18+
* A copy is found in the text file GPL.txt and important notices to the license
19+
* from the author is found in LICENSE.txt distributed with these scripts.
20+
*
21+
*
22+
* This script is distributed in the hope that it will be useful,
23+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+
* GNU General Public License for more details.
26+
*
27+
* This copyright notice MUST APPEAR in all copies of the script!
28+
***************************************************************/
29+
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
30+
31+
/**
32+
* API Command Controller
33+
*/
34+
class BackendApiCommandController extends CommandController {
35+
36+
/**
37+
* @var \TYPO3\CMS\Core\Log\LogManager $logManager
38+
*/
39+
protected $logManager;
40+
41+
/**
42+
* @var \TYPO3\CMS\Core\Log\Logger $logger
43+
*/
44+
protected $logger;
45+
46+
/**
47+
* @param \TYPO3\CMS\Core\Log\LogManager $logManager
48+
*
49+
* @return void
50+
*/
51+
public function injectLogManager(\TYPO3\CMS\Core\Log\LogManager $logManager) {
52+
$this->logManager = $logManager;
53+
}
54+
55+
/**
56+
* Initialize the object
57+
*/
58+
public function initializeObject() {
59+
$this->logger = $this->objectManager->get('\TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
60+
}
61+
62+
/**
63+
* Locks backend access for all users by writing a lock file that is checked when the backend is accessed.
64+
*
65+
* @param string $redirectUrl URL to redirect to when the backend is accessed
66+
*/
67+
public function lockCommand($redirectUrl = NULL) {
68+
if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
69+
$message = 'A lockfile already exists. Overwriting it...';
70+
$this->outputLine($message);
71+
$this->logger->info($message);
72+
}
73+
74+
\TYPO3\CMS\Core\Utility\GeneralUtility::writeFile(PATH_typo3conf . 'LOCK_BACKEND', (string)$redirectUrl);
75+
76+
if ($redirectUrl === NULL) {
77+
$message = 'Wrote lock file to \'typo3conf/LOCK_BACKEND\'';
78+
$this->outputLine($message);
79+
$this->logger->info($message);
80+
} else {
81+
$message = 'Wrote lock file to \'typo3conf/LOCK_BACKEND\' with instruction to redirect to: \'' . $redirectUrl . '\'';
82+
$this->outputLine($message);
83+
$this->logger->info($message);
84+
}
85+
}
86+
87+
/**
88+
* Unlocks the backend access by deleting the lock file
89+
*/
90+
public function unlockCommand() {
91+
if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
92+
unlink(PATH_typo3conf . 'LOCK_BACKEND');
93+
if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
94+
$message = 'ERROR: Could not remove lock file \'typo3conf/LOCK_BACKEND\'!';
95+
$this->outputLine($message);
96+
$this->logger->error($message);
97+
$this->quit(1);
98+
} else {
99+
$message = 'Removed lock file \'typo3conf/LOCK_BACKEND\'';
100+
$this->outputLine($message);
101+
$this->logger->info($message);
102+
}
103+
} else {
104+
$message = 'No lock file \'typo3conf/LOCK_BACKEND\' was found, hence no lock could be removed.';
105+
$this->outputLine($message);
106+
$this->logger->info($message);
107+
$this->quit(1);
108+
}
109+
}
110+
}

Classes/Command/CacheApiCommandController.php

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@
3434
* @package Etobi\CoreAPI\Service\SiteApiService
3535
*/
3636
class CacheApiCommandController extends CommandController {
37+
/**
38+
* @var \TYPO3\CMS\Core\Log\LogManager $logManager
39+
*/
40+
protected $logManager;
41+
42+
/**
43+
* @var \TYPO3\CMS\Core\Log\Logger $logger
44+
*/
45+
protected $logger;
46+
47+
/**
48+
* @param \TYPO3\CMS\Core\Log\LogManager $logManager
49+
*
50+
* @return void
51+
*/
52+
public function injectLogManager(\TYPO3\CMS\Core\Log\LogManager $logManager) {
53+
$this->logManager = $logManager;
54+
}
55+
56+
/**
57+
* Initialize the object
58+
*/
59+
public function initializeObject() {
60+
$this->logger = $this->objectManager->get('\TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
61+
}
3762

3863
/**
3964
* @var \Etobi\CoreAPI\Service\CacheApiService
@@ -51,12 +76,50 @@ public function injectCacheApiService(\Etobi\CoreAPI\Service\CacheApiService $ca
5176

5277
/**
5378
* Clear all caches.
79+
* If hard, cache will be cleared in a more straightforward approach and the according backend hooks are not executed.
5480
*
81+
* @param boolean $hard
5582
* @return void
5683
*/
57-
public function clearAllCachesCommand() {
58-
$this->cacheApiService->clearAllCaches();
59-
$this->outputLine('All caches have been cleared.');
84+
public function clearAllCachesCommand($hard = false) {
85+
$this->cacheApiService->clearAllCaches($hard);
86+
$message = 'All caches have been cleared%s.';
87+
$this->logger->info($message);
88+
$this->outputLine($message, $hard ? array(' hard') : array(''));
89+
}
90+
91+
/**
92+
* Clear system cache.
93+
*
94+
* @return void
95+
*/
96+
public function clearSystemCacheCommand() {
97+
$this->cacheApiService->clearSystemCache();
98+
$message = 'System cache has been cleared';
99+
$this->logger->info($message);
100+
$this->outputLine($message);
101+
}
102+
103+
/**
104+
* Clears the opcode cache.
105+
*
106+
* @param string|NULL $fileAbsPath The file as absolute path to be cleared
107+
* or NULL to clear completely.
108+
*
109+
* @return void
110+
*/
111+
public function clearAllActiveOpcodeCacheCommand($fileAbsPath = NULL) {
112+
$this->cacheApiService->clearAllActiveOpcodeCache($fileAbsPath);
113+
114+
if ($fileAbsPath !== NULL) {
115+
$message = sprintf('The opcode cache for the file %s has been cleared', $fileAbsPath);
116+
$this->outputLine($message);
117+
$this->logger->info($message);
118+
} else {
119+
$message = 'The complete opcode cache has been cleared';
120+
$this->outputLine($message);
121+
$this->logger->info($message);
122+
}
60123
}
61124

62125
/**
@@ -66,7 +129,9 @@ public function clearAllCachesCommand() {
66129
*/
67130
public function clearConfigurationCacheCommand() {
68131
$this->cacheApiService->clearConfigurationCache();
69-
$this->outputLine('Configuration cache has been cleared.');
132+
$message = 'Configuration cache has been cleared.';
133+
$this->logger->info($message);
134+
$this->outputLine($message);
70135
}
71136

72137
/**
@@ -76,7 +141,9 @@ public function clearConfigurationCacheCommand() {
76141
*/
77142
public function clearPageCacheCommand() {
78143
$this->cacheApiService->clearPageCache();
79-
$this->outputLine('Page cache has been cleared.');
144+
$message = 'Page cache has been cleared.';
145+
$this->logger->info($message);
146+
$this->outputLine($message);
80147
}
81148

82149
/**
@@ -87,6 +154,8 @@ public function clearPageCacheCommand() {
87154
*/
88155
public function clearAllExceptPageCacheCommand() {
89156
$clearedCaches = $this->cacheApiService->clearAllExceptPageCache();
90-
$this->outputLine('Cleared caches: ' . implode(', ', $clearedCaches));
157+
$message = 'Cleared caches: ' . implode(', ', $clearedCaches);
158+
$this->logger->info($message);
159+
$this->outputLine($message);
91160
}
92-
}
161+
}

Classes/Command/DatabaseApiCommandController.php

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,91 @@
3535
*/
3636
class DatabaseApiCommandController extends CommandController {
3737

38+
/**
39+
* @var \TYPO3\CMS\Core\Log\LogManager $logManager
40+
*/
41+
protected $logManager;
42+
43+
/**
44+
* @var \TYPO3\CMS\Core\Log\Logger $logger
45+
*/
46+
protected $logger;
47+
48+
/**
49+
* @param \TYPO3\CMS\Core\Log\LogManager $logManager
50+
*
51+
* @return void
52+
*/
53+
public function injectLogManager(\TYPO3\CMS\Core\Log\LogManager $logManager) {
54+
$this->logManager = $logManager;
55+
}
56+
57+
/**
58+
* Initialize the object
59+
*/
60+
public function initializeObject() {
61+
$this->logger = $this->objectManager->get('\TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
62+
}
63+
64+
/**
65+
* @var \Etobi\CoreAPI\Service\DatabaseApiService $databaseApiService
66+
*/
67+
protected $databaseApiService;
68+
69+
/**
70+
* Injects the DatabaseApiService object
71+
*
72+
* @param \Etobi\CoreAPI\Service\DatabaseApiService $databaseApiService
73+
*
74+
* @return void
75+
*/
76+
public function injectDatabaseApiService(\Etobi\CoreAPI\Service\DatabaseApiService $databaseApiService) {
77+
$this->databaseApiService = $databaseApiService;
78+
}
79+
3880
/**
3981
* Database compare.
4082
* Leave the argument 'actions' empty or use "help" to see the available ones
4183
*
4284
* @param string $actions List of actions which will be executed
85+
* @param bool $dry
4386
*/
44-
public function databaseCompareCommand($actions = '') {
45-
$service = $this->getService();
46-
87+
public function databaseCompareCommand($actions = '', $dry = FALSE) {
4788
if ($actions === 'help' || strlen($actions) === 0) {
48-
$actions = $service->databaseCompareAvailableActions();
89+
$actions = $this->databaseApiService->databaseCompareAvailableActions();
4990
foreach ($actions as $number => $action) {
5091
$this->outputLine(' - ' . $action . ' => ' . $number);
5192
}
5293
$this->quit();
5394
}
5495

55-
$result = $service->databaseCompare($actions);
56-
if (empty($result)) {
57-
$this->outputLine('DB has been compared');
96+
$result = $this->databaseApiService->databaseCompare($actions, $dry);
97+
98+
if ($dry) {
99+
$this->outputLine('DB compare would execute the following queries:');
100+
foreach($result as $key => $set) {
101+
$this->outputLine(sprintf('### Action: %s ###', $key));
102+
$this->outputLine('===================================');
103+
$this->logger->info(sprintf('### Action: %s ###', $key));
104+
$this->logger->info('===================================');
105+
foreach($set as $line) {
106+
$this->outputLine($line);
107+
$this->logger->info($line);
108+
}
109+
$this->outputLine(LF);
110+
}
111+
$this->logger->info('DB compare executed in dry mode');
58112
} else {
59-
$this->outputLine('DB could not be compared, Error(s): %s', array(LF . implode(LF, $result)));
60-
$this->quit();
113+
if (empty($result)) {
114+
$message = 'DB has been compared';
115+
$this->outputLine($message);
116+
$this->logger->info($message);
117+
} else {
118+
$message = sprintf('DB could not be compared, Error(s): %s', array(LF . implode(LF, $result)));
119+
$this->outputLine($message);
120+
$this->logger->error($message);
121+
$this->quit(1);
122+
}
61123
}
62124
}
63-
64-
/**
65-
* Returns the service object.
66-
*
67-
* @return \Etobi\CoreAPI\Service\DatabaseApiService object
68-
*/
69-
private function getService() {
70-
return $this->objectManager->get('Etobi\\CoreAPI\\Service\\DatabaseApiService');
71-
}
72125
}

0 commit comments

Comments
 (0)