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

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Kowalke committed Oct 28, 2014
2 parents acbe842 + 0540e47 commit 3acee21
Show file tree
Hide file tree
Showing 16 changed files with 846 additions and 281 deletions.
110 changes: 110 additions & 0 deletions Classes/Command/BackendApiCommandController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
namespace Etobi\CoreAPI\Command;

/***************************************************************
* Copyright notice
*
* (c) 2014 Helmut Hummel <helmut.hummel@typo3.org>
* 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.
* A copy is found in the text file GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;

/**
* API Command Controller
*/
class BackendApiCommandController extends CommandController {

/**
* @var \TYPO3\CMS\Core\Log\LogManager $logManager
*/
protected $logManager;

/**
* @var \TYPO3\CMS\Core\Log\Logger $logger
*/
protected $logger;

/**
* @param \TYPO3\CMS\Core\Log\LogManager $logManager
*
* @return void
*/
public function injectLogManager(\TYPO3\CMS\Core\Log\LogManager $logManager) {
$this->logManager = $logManager;
}

/**
* Initialize the object
*/
public function initializeObject() {
$this->logger = $this->objectManager->get('\TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
}

/**
* Locks backend access for all users by writing a lock file that is checked when the backend is accessed.
*
* @param string $redirectUrl URL to redirect to when the backend is accessed
*/
public function lockCommand($redirectUrl = NULL) {
if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
$message = 'A lockfile already exists. Overwriting it...';
$this->outputLine($message);
$this->logger->info($message);
}

\TYPO3\CMS\Core\Utility\GeneralUtility::writeFile(PATH_typo3conf . 'LOCK_BACKEND', (string)$redirectUrl);

if ($redirectUrl === NULL) {
$message = 'Wrote lock file to \'typo3conf/LOCK_BACKEND\'';
$this->outputLine($message);
$this->logger->info($message);
} else {
$message = 'Wrote lock file to \'typo3conf/LOCK_BACKEND\' with instruction to redirect to: \'' . $redirectUrl . '\'';
$this->outputLine($message);
$this->logger->info($message);
}
}

/**
* Unlocks the backend access by deleting the lock file
*/
public function unlockCommand() {
if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
unlink(PATH_typo3conf . 'LOCK_BACKEND');
if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
$message = 'ERROR: Could not remove lock file \'typo3conf/LOCK_BACKEND\'!';
$this->outputLine($message);
$this->logger->error($message);
$this->quit(1);
} else {
$message = 'Removed lock file \'typo3conf/LOCK_BACKEND\'';
$this->outputLine($message);
$this->logger->info($message);
}
} else {
$message = 'No lock file \'typo3conf/LOCK_BACKEND\' was found, hence no lock could be removed.';
$this->outputLine($message);
$this->logger->info($message);
$this->quit(1);
}
}
}
83 changes: 76 additions & 7 deletions Classes/Command/CacheApiCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@
* @package Etobi\CoreAPI\Service\SiteApiService
*/
class CacheApiCommandController extends CommandController {
/**
* @var \TYPO3\CMS\Core\Log\LogManager $logManager
*/
protected $logManager;

/**
* @var \TYPO3\CMS\Core\Log\Logger $logger
*/
protected $logger;

/**
* @param \TYPO3\CMS\Core\Log\LogManager $logManager
*
* @return void
*/
public function injectLogManager(\TYPO3\CMS\Core\Log\LogManager $logManager) {
$this->logManager = $logManager;
}

/**
* Initialize the object
*/
public function initializeObject() {
$this->logger = $this->objectManager->get('\TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
}

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

/**
* Clear all caches.
* If hard, cache will be cleared in a more straightforward approach and the according backend hooks are not executed.
*
* @param boolean $hard
* @return void
*/
public function clearAllCachesCommand() {
$this->cacheApiService->clearAllCaches();
$this->outputLine('All caches have been cleared.');
public function clearAllCachesCommand($hard = false) {
$this->cacheApiService->clearAllCaches($hard);
$message = 'All caches have been cleared%s.';
$this->logger->info($message);
$this->outputLine($message, $hard ? array(' hard') : array(''));
}

/**
* Clear system cache.
*
* @return void
*/
public function clearSystemCacheCommand() {
$this->cacheApiService->clearSystemCache();
$message = 'System cache has been cleared';
$this->logger->info($message);
$this->outputLine($message);
}

/**
* Clears the opcode cache.
*
* @param string|NULL $fileAbsPath The file as absolute path to be cleared
* or NULL to clear completely.
*
* @return void
*/
public function clearAllActiveOpcodeCacheCommand($fileAbsPath = NULL) {
$this->cacheApiService->clearAllActiveOpcodeCache($fileAbsPath);

if ($fileAbsPath !== NULL) {
$message = sprintf('The opcode cache for the file %s has been cleared', $fileAbsPath);
$this->outputLine($message);
$this->logger->info($message);
} else {
$message = 'The complete opcode cache has been cleared';
$this->outputLine($message);
$this->logger->info($message);
}
}

/**
Expand All @@ -66,7 +129,9 @@ public function clearAllCachesCommand() {
*/
public function clearConfigurationCacheCommand() {
$this->cacheApiService->clearConfigurationCache();
$this->outputLine('Configuration cache has been cleared.');
$message = 'Configuration cache has been cleared.';
$this->logger->info($message);
$this->outputLine($message);
}

/**
Expand All @@ -76,7 +141,9 @@ public function clearConfigurationCacheCommand() {
*/
public function clearPageCacheCommand() {
$this->cacheApiService->clearPageCache();
$this->outputLine('Page cache has been cleared.');
$message = 'Page cache has been cleared.';
$this->logger->info($message);
$this->outputLine($message);
}

/**
Expand All @@ -87,6 +154,8 @@ public function clearPageCacheCommand() {
*/
public function clearAllExceptPageCacheCommand() {
$clearedCaches = $this->cacheApiService->clearAllExceptPageCache();
$this->outputLine('Cleared caches: ' . implode(', ', $clearedCaches));
$message = 'Cleared caches: ' . implode(', ', $clearedCaches);
$this->logger->info($message);
$this->outputLine($message);
}
}
}
89 changes: 71 additions & 18 deletions Classes/Command/DatabaseApiCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,91 @@
*/
class DatabaseApiCommandController extends CommandController {

/**
* @var \TYPO3\CMS\Core\Log\LogManager $logManager
*/
protected $logManager;

/**
* @var \TYPO3\CMS\Core\Log\Logger $logger
*/
protected $logger;

/**
* @param \TYPO3\CMS\Core\Log\LogManager $logManager
*
* @return void
*/
public function injectLogManager(\TYPO3\CMS\Core\Log\LogManager $logManager) {
$this->logManager = $logManager;
}

/**
* Initialize the object
*/
public function initializeObject() {
$this->logger = $this->objectManager->get('\TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
}

/**
* @var \Etobi\CoreAPI\Service\DatabaseApiService $databaseApiService
*/
protected $databaseApiService;

/**
* Injects the DatabaseApiService object
*
* @param \Etobi\CoreAPI\Service\DatabaseApiService $databaseApiService
*
* @return void
*/
public function injectDatabaseApiService(\Etobi\CoreAPI\Service\DatabaseApiService $databaseApiService) {
$this->databaseApiService = $databaseApiService;
}

/**
* Database compare.
* Leave the argument 'actions' empty or use "help" to see the available ones
*
* @param string $actions List of actions which will be executed
* @param bool $dry
*/
public function databaseCompareCommand($actions = '') {
$service = $this->getService();

public function databaseCompareCommand($actions = '', $dry = FALSE) {
if ($actions === 'help' || strlen($actions) === 0) {
$actions = $service->databaseCompareAvailableActions();
$actions = $this->databaseApiService->databaseCompareAvailableActions();
foreach ($actions as $number => $action) {
$this->outputLine(' - ' . $action . ' => ' . $number);
}
$this->quit();
}

$result = $service->databaseCompare($actions);
if (empty($result)) {
$this->outputLine('DB has been compared');
$result = $this->databaseApiService->databaseCompare($actions, $dry);

if ($dry) {
$this->outputLine('DB compare would execute the following queries:');
foreach($result as $key => $set) {
$this->outputLine(sprintf('### Action: %s ###', $key));
$this->outputLine('===================================');
$this->logger->info(sprintf('### Action: %s ###', $key));
$this->logger->info('===================================');
foreach($set as $line) {
$this->outputLine($line);
$this->logger->info($line);
}
$this->outputLine(LF);
}
$this->logger->info('DB compare executed in dry mode');
} else {
$this->outputLine('DB could not be compared, Error(s): %s', array(LF . implode(LF, $result)));
$this->quit();
if (empty($result)) {
$message = 'DB has been compared';
$this->outputLine($message);
$this->logger->info($message);
} else {
$message = sprintf('DB could not be compared, Error(s): %s', array(LF . implode(LF, $result)));
$this->outputLine($message);
$this->logger->error($message);
$this->quit(1);
}
}
}

/**
* Returns the service object.
*
* @return \Etobi\CoreAPI\Service\DatabaseApiService object
*/
private function getService() {
return $this->objectManager->get('Etobi\\CoreAPI\\Service\\DatabaseApiService');
}
}
Loading

0 comments on commit 3acee21

Please sign in to comment.