Skip to content
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

[BUGFIX] Output process error output to stderr #196

Merged
merged 1 commit into from
Jun 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 27 additions & 16 deletions Classes/Command/DatabaseCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public function updateSchemaCommand(array $schemaUpdateTypes)
* <b>Example (select):</b> <code>echo 'SELECT username from be_users WHERE admin=1;' | ./typo3cms database:import</code>
* <b>Example (interactive):</b> <code>./typo3cms database:import --interactive</code>
*
* <warning>This command passes the plain text database password to the command line process.</warning>
* This means, that users that have the permission to observe running processes,
* will be able to read your password.
* If this imposes a security risk for you, then refrain from using this command!
*
* @param bool $interactive Open an interactive mysql shell using the TYPO3 connection settings.
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
*/
Expand All @@ -110,15 +115,7 @@ public function importCommand($interactive = false)
$exitCode = $mysqlCommand->mysql(
array('--skip-column-names'),
STDIN,
function ($type, $output) {
if (Process::OUT === $type) {
// Explicitly just echo out for now (avoid Symfony console formatting)
// Todo: use output with OUTPUT_RAW once available in the API
echo $output;
} else {
$this->output('<error>' . $output . '</error>');
}
},
$this->buildOutputClosure(),
$interactive
);
$this->quit($exitCode);
Expand All @@ -130,6 +127,11 @@ function ($type, $output) {
* Export the database (all tables) directly to stdout.
* The mysqldump binary must be available in the path for this command to work.
* This obviously only works when MySQL ist used as DBMS.
*
* <warning>This command passes the plain text database password to the command line process.</warning>
* This means, that users that have the permission to observe running processes,
* will be able to read your password.
* If this imposes a security risk for you, then refrain from using this command!
*/
public function exportCommand()
{
Expand All @@ -139,14 +141,23 @@ public function exportCommand()
);
$exitCode = $mysqlCommand->mysqldump(
array(),
function ($type, $output) {
if (Process::OUT === $type) {
echo $output;
} else {
$this->output('<error>' . $output . '</error>');
}
}
$this->buildOutputClosure()
);
$this->quit($exitCode);
}

/**
* @return \Closure
*/
protected function buildOutputClosure()
{
return function ($type, $data) {
$output = $this->output->getSymfonyConsoleOutput();
if (Process::OUT === $type) {
$output->write($data, $output::OUTPUT_RAW);
} elseif (Process::ERR === $type) {
$output->getErrorOutput()->write($data);
}
};
}
}
3 changes: 2 additions & 1 deletion Classes/Command/DocumentationCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public function generateXsdCommand($phpNamespace, $xsdNamespace = null, $targetF
$this->sendAndExit(1);
}
if ($targetFile === null) {
echo $xsdSchema;
$output = $this->output->getSymfonyConsoleOutput();
$output->write($xsdSchema, $output::OUTPUT_RAW);
} else {
file_put_contents($targetFile, $xsdSchema);
}
Expand Down