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

Commit 37c83ed

Browse files
author
Georg Ringer
committed
[FEATURE] Site info task
1 parent c65a2c0 commit 37c83ed

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

Classes/Command/SiteApiCommandController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ class Tx_Coreapi_Command_SiteApiCommandController extends Tx_Extbase_MVC_Control
3838
* @return void
3939
*/
4040
public function infoCommand() {
41-
// todo
41+
/** @var $service Tx_Coreapi_Service_SiteApiService */
42+
$service = $this->objectManager->get('Tx_Coreapi_Service_SiteApiService');
43+
$data = $service->getSiteInfo();
4244

45+
foreach($data as $key => $value) {
46+
$line = wordwrap($value, self::MAXIMUM_LINE_LENGTH - 43, PHP_EOL . str_repeat(' ', 43), TRUE);
47+
$this->outputLine('%-2s%-40s %s', array(' ', $key, $line));
48+
}
4349
}
4450

4551
/**

Classes/Service/SiteApiService.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,54 @@
3131
class Tx_Coreapi_Service_SiteApiService {
3232

3333
/*
34-
* site:info Provides some basic site status (Version, file size ...)
3534
* site:sysNews Create a sys news, e.g. for new deployment
3635
*/
3736

37+
/**
38+
* Get some basic site information
39+
*
40+
* @return array
41+
*/
42+
public function getSiteInfo() {
43+
$data = array(
44+
'TYPO3 version' => TYPO3_version,
45+
'Site name' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'],
46+
);
47+
48+
$this->getDiskUsage($data);
49+
$this->getDatabaseInformation($data);
50+
51+
return $data;
52+
}
53+
54+
/**
55+
* Get disku usage
56+
*
57+
* @author Claus Due <[email protected]>, Wildside A/S
58+
* @param array $data
59+
* @return void
60+
*/
61+
protected function getDiskUsage(&$data) {
62+
if (TYPO3_OS !== 'WIN') {
63+
$data['Combined disk usage'] = trim(array_shift(explode("\t", shell_exec('du -sh ' . PATH_site))));
64+
}
65+
}
66+
67+
/**
68+
* Get database size
69+
*
70+
* @author Claus Due <[email protected]>, Wildside A/S
71+
* @param array $data
72+
* @return void
73+
*/
74+
protected function getDatabaseInformation(&$data) {
75+
$databaseSizeResult = $GLOBALS['TYPO3_DB']->sql_query("SELECT SUM( data_length + index_length ) / 1024 / 1024 AS size FROM information_schema.TABLES WHERE table_schema = '" . TYPO3_db . "'");
76+
$databaseSizeRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($databaseSizeResult);
77+
$databaseSize = array_pop($databaseSizeRow);
78+
$value = number_format($databaseSize, ($databaseSize > 10 ? 0 : 1)) . 'M';
79+
$data['Database size'] = $value;
80+
}
81+
3882
}
3983

4084
?>

0 commit comments

Comments
 (0)