SiteApiCommandController::createSysNewsCommand()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 3
Metric Value
c 4
b 0
f 3
dl 0
loc 17
rs 9.4285
cc 3
eloc 12
nc 4
nop 2
1
<?php
2
namespace Etobi\CoreAPI\Command;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2012 Georg Ringer <[email protected]>
8
 *  (c) 2014 Stefano Kowalke <[email protected]>
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 2 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
29
30
/**
31
 * Site API Command Controller
32
 *
33
 * @author Georg Ringer <[email protected]>
34
 * @author Stefano Kowalke <[email protected]>
35
 * @package Etobi\CoreAPI\Service\SiteApiService
36
 */
37
class SiteApiCommandController extends CommandController {
38
39
  const MAXIMUM_LINE_LENGTH = 79;
40
41
	/**
42
	 * @var \TYPO3\CMS\Core\Log\LogManager $logManager
43
	 */
44
	protected $logManager;
45
46
	/**
47
	 * @var \TYPO3\CMS\Core\Log\Logger $logger
48
	 */
49
	protected $logger;
50
51
	/**
52
	 * @param \TYPO3\CMS\Core\Log\LogManager $logManager
53
	 *
54
	 * @return void
55
	 */
56
	public function injectLogManager(\TYPO3\CMS\Core\Log\LogManager $logManager) {
57
		$this->logManager = $logManager;
58
	}
59
60
	/**
61
	 * Initialize the object
62
	 */
63
	public function initializeObject() {
64
		$this->logger = $this->objectManager->get('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
65
	}
66
67
	/**
68
	 * @var \Etobi\CoreAPI\Service\SiteApiService
69
	 */
70
	protected $siteApiService;
71
72
	/**
73
	 * Inject the SiteApiService
74
	 *
75
	 * @param \Etobi\CoreAPI\Service\SiteApiService $siteApiService
76
	 *
77
	 * @return void
78
	 */
79
	public function injectSiteApiService(\Etobi\CoreAPI\Service\SiteApiService $siteApiService) {
80
		$this->siteApiService = $siteApiService;
81
	}
82
83
	/**
84
	 * Basic information about the system.
85
	 *
86
	 * @return void
87
	 */
88
	public function infoCommand() {
89
		$data = $this->siteApiService->getSiteInfo();
90
91
		foreach ($data as $key => $value) {
92
			$line = wordwrap($value, $this->output->getMaximumLineLength() - 43, PHP_EOL . str_repeat(' ', 43), TRUE);
93
			$this->outputLine('%-2s%-40s %s', array(' ', $key, $line));
94
		}
95
96
		$this->logger->info('siteApi:info executes successfully.');
97
	}
98
99
	/**
100
	 * Sys news record is displayed at the login page.
101
	 *
102
	 * @param string $header Header text
103
	 * @param string $text   Basic text
104
	 *
105
	 * @return void
106
	 */
107
	public function createSysNewsCommand($header, $text = '') {
108
		$result = FALSE;
109
110
		try {
111
			$result = $this->siteApiService->createSysNews($header, $text);
112
		} catch (\Exception $e) {
113
			$this->outputLine($e->getMessage());
114
			$this->quit(1);
115
		}
116
117
		if ($result) {
118
			$this->outputLine('News entry successfully created.');
119
		} else {
120
			$this->outputLine('News entry NOT created.');
121
			$this->quit(1);
122
		}
123
	}
124
}
125