-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Create status command #49
Open
alias-mac
wants to merge
1
commit into
insulin:master
Choose a base branch
from
alias-mac:ticket-49
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Insulin CLI | ||
* | ||
* Copyright (c) 2008-2013 Filipe Guerra, João Morais | ||
* http://cli.sugarmeetsinsulin.com | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Insulin\Console\Command; | ||
|
||
use Insulin\Sugar\SugarInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Helper\TableHelper; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* This command provides information about the current status of Insulin and | ||
* SugarCRM version on existing or provided path. | ||
* | ||
* The information provided depends on the maximum boot level reached. | ||
* | ||
* @fixme Insulin commands need to extend from InsulinCommand so it requires an Insulin Application | ||
* | ||
* @api | ||
*/ | ||
class StatusCommand extends Command | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('status') | ||
->setAliases(array('st')) | ||
->setDefinition(array( | ||
new InputOption('show-passwords', null, InputOption::VALUE_NONE, 'Show database password.'), | ||
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output status in other formats.', 'table'), | ||
)) | ||
->setDescription('Provides a birds-eye view of the current SugarCRM installation, if any.') | ||
->setHelp( | ||
<<<EOF | ||
The <info>%command.name%</info> command shows the current SugarCRM status: | ||
|
||
<info>%command.full_name%</info> | ||
|
||
You can also output the status in other formats by using the <comment>--format</comment> option: | ||
|
||
<info>%command.full_name% --format=json</info> | ||
|
||
Output formats available: <comment>table</comment>, <comment>json</comment>. | ||
EOF | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* Uses table helper for output. | ||
* @see http://symfony.com/doc/master/components/console/helpers/tablehelper.html | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$data = | ||
$this->getInsulinInfo() + | ||
$this->getSugarBasicInfo() + | ||
$this->getSugarConfigurationInfo() + | ||
$this->getSugarMoreInfo(); | ||
|
||
if (!$input->hasOption('show-passwords')) { | ||
unset($data['Database password']); | ||
unset($data['License download key']); | ||
} | ||
|
||
// TODO sorting by translated labels for table format | ||
ksort($data); | ||
|
||
switch ($input->getOption('format')) { | ||
case 'table': | ||
|
||
/* @var $table TableHelper */ | ||
$table = $this->getApplication()->getHelperSet()->get('table'); | ||
$table->setLayout(TableHelper::LAYOUT_COMPACT); | ||
|
||
// prepare data for TableHelper | ||
// TODO move this to a class so we can reuse this type of output (e.g: for vardefs) | ||
foreach ($data as $key => $value) { | ||
|
||
// do some fixes based on keys | ||
if ($key === 'Database') { | ||
$value = $value ? 'Connected' : 'Not connected'; | ||
} elseif (is_bool($value)) { | ||
$value = $value ? 'Enabled' : 'Disabled'; | ||
} | ||
|
||
$table->addRow(array($key, $value)); | ||
} | ||
|
||
$table->render($output); | ||
|
||
break; | ||
case 'json': | ||
$output->writeln(json_encode($data)); | ||
break; | ||
default: | ||
throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $input->getOption('format'))); | ||
} | ||
} | ||
|
||
protected function getInsulinInfo() | ||
{ | ||
/* @var $kernel \Insulin\Console\KernelInterface */ | ||
$kernel = $this->getApplication()->getKernel(); | ||
|
||
if ($kernel->getBootedLevel() < $kernel::BOOT_INSULIN) { | ||
return array(); | ||
} | ||
|
||
return array( | ||
// not the same but probably we shouldn't give too much support for 5.3 now that 5.5 is out | ||
'PHP executable' => defined('PHP_BINARY') ? PHP_BINARY : PHP_BINDIR, | ||
'PHP configuration' => php_ini_loaded_file(), | ||
'PHP OS' => PHP_OS, | ||
'Insulin version' => $kernel->getVersion(), | ||
); | ||
|
||
} | ||
|
||
protected function getSugarBasicInfo() | ||
{ | ||
/* @var $kernel \Insulin\Console\KernelInterface */ | ||
$kernel = $this->getApplication()->getKernel(); | ||
|
||
if ($kernel->getBootedLevel() < $kernel::BOOT_SUGAR_ROOT) { | ||
return array(); | ||
} | ||
|
||
/* @var $sugar SugarInterface */ | ||
$sugar = $kernel->get('sugar'); | ||
|
||
$flavor = $sugar->getInfo('flavor'); | ||
$version = $sugar->getInfo('version'); | ||
$build = $sugar->getInfo('build'); | ||
|
||
return array( | ||
'SugarCRM version' => sprintf('%s %s build %s', $flavor, $version, $build), | ||
'SugarCRM root' => $sugar->getPath(), | ||
); | ||
} | ||
|
||
protected function getSugarConfigurationInfo() | ||
{ | ||
/* @var $kernel \Insulin\Console\KernelInterface */ | ||
$kernel = $this->getApplication()->getKernel(); | ||
|
||
if ($kernel->getBootedLevel() < $kernel::BOOT_SUGAR_CONFIGURATION) { | ||
return array(); | ||
} | ||
|
||
/* @var $sugar SugarInterface */ | ||
$sugar = $kernel->get('sugar'); | ||
|
||
// FIXME we need a getConfig as API from SugarInterface | ||
$config = $sugar->bootConfig(); | ||
|
||
$dbType = $config['dbconfig']['db_type']; | ||
$dbHostname = $config['dbconfig']['db_host_name']; | ||
$dbPort = $config['dbconfig']['db_port']; | ||
$dbUsername = $config['dbconfig']['db_user_name']; | ||
$dbPassword = $config['dbconfig']['db_password']; | ||
$dbName = $config['dbconfig']['db_name']; | ||
|
||
$data = array( | ||
'Database driver' => $dbType, | ||
'Database hostname' => $dbHostname, | ||
'Database port' => $dbPort, | ||
'Database username' => $dbUsername, | ||
'Database password' => $dbPassword, | ||
'Database name' => $dbName, | ||
); | ||
|
||
$isConnected = ($kernel->getBootedLevel() >= $kernel::BOOT_SUGAR_DATABASE); | ||
$data += array( | ||
'Database' => $isConnected, | ||
); | ||
|
||
$data += array( | ||
'Cache directory path' => $config['cache_dir'], | ||
'Site URI' => $config['site_url'], | ||
'Upload directory path' => $config['upload_dir'], | ||
'Developer mode' => !empty($config['developerMode']), | ||
'Logger level' => $config['logger']['level'], | ||
// FIXME support SugarCRM logger file with dates | ||
// see sugarcrm/include/SugarLogger/SugarLogger.php on _doInitialization | ||
'Logger file' => $config['logger']['file']['name'] . $config['logger']['file']['ext'], | ||
); | ||
|
||
if (!empty($config['full_text_engine'])) { | ||
// TODO this is weird but I'm pretty sure that Sugar only supports 1 FTS at a time | ||
// but configuration gets this as an array? | ||
$ftsEngine = reset($config['full_text_engine']); | ||
$data += array( | ||
'Full text engine' => key($config['full_text_engine']), | ||
'Full text engine host' => $ftsEngine['host'], | ||
'Full text engine port' => $ftsEngine['port'], | ||
); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
protected function getSugarMoreInfo() | ||
{ | ||
/* @var $kernel \Insulin\Console\KernelInterface */ | ||
$kernel = $this->getApplication()->getKernel(); | ||
|
||
if ($kernel->getBootedLevel() < $kernel::BOOT_SUGAR_FULL) { | ||
return array(); | ||
} | ||
|
||
/* @var $sugar SugarInterface */ | ||
$sugar = $kernel->get('sugar'); | ||
$settings = $sugar->getSystemSettings('info'); | ||
|
||
$data = array( | ||
'Database expected version' => $settings['info_sugar_version'], | ||
); | ||
|
||
if ($sugar->getInfo('flavor') !== 'COM') { | ||
$data += array( | ||
'License number of users' => $settings['license_users'], | ||
'License number of offline clients' => $settings['license_num_lic_oc'], | ||
'License expire date' => $settings['license_expire_date'], | ||
'License download key' => $settings['license_key'], | ||
); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,5 +115,20 @@ public function bootApplication(); | |
* @throws \RuntimeException | ||
* If login fails. | ||
*/ | ||
public function localLogin(); | ||
public function localLogin($username); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably this one should be in a separate PR since it was a typo currently on master. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. |
||
|
||
/** | ||
* Gets the system settings from the Administration module. | ||
* | ||
* @param string $category | ||
* The category to get a slimmer payload. | ||
* @param bool $reload | ||
* Reload data by skipping cache. | ||
* @return array | ||
* All the settings cached due to bug on SugarCRM. | ||
* | ||
* TODO we should only get the category(ies) that we asked for. | ||
* Currently we send information just like SugarCRM has it. | ||
*/ | ||
public function getSystemSettings($category, $reload = false); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this extra line?