Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15505 from mauriciofauth/scripts-console
Add a console tool
- Loading branch information
Showing
5 changed files
with
133 additions
and
78 deletions.
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
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,112 @@ | ||
<?php | ||
/** | ||
* Translates advisory rules to Gettext format | ||
* | ||
* @package PhpMyAdmin\Command | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Command; | ||
|
||
use PhpMyAdmin\Advisor; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Translates advisory rules to Gettext format | ||
* | ||
* @package PhpMyAdmin\Command | ||
*/ | ||
class AdvisoryRulesCommand extends Command | ||
{ | ||
/** @var string */ | ||
protected static $defaultName = 'po:advisory-rules'; | ||
|
||
/** @var array */ | ||
private $messages = []; | ||
|
||
/** @var array */ | ||
private $locations = []; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function configure(): void | ||
{ | ||
$this->setDescription('Translates advisory rules to Gettext format'); | ||
$this->setHelp( | ||
'This command parses advisory rules and output them' | ||
. ' as Gettext POT formatted strings for translation.' | ||
); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input input | ||
* @param OutputInterface $output output | ||
* | ||
* @return void | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): void | ||
{ | ||
$ruleFiles = []; | ||
$ruleFiles[Advisor::GENERIC_RULES_FILE] = Advisor::parseRulesFile( | ||
Advisor::GENERIC_RULES_FILE | ||
); | ||
$ruleFiles[Advisor::BEFORE_MYSQL80003_RULES_FILE] = Advisor::parseRulesFile( | ||
Advisor::BEFORE_MYSQL80003_RULES_FILE | ||
); | ||
|
||
foreach ($ruleFiles as $file => $rules) { | ||
foreach ($rules['rules'] as $idx => $rule) { | ||
$this->addMessage($file, $rules, $idx, 'name'); | ||
$this->addMessage($file, $rules, $idx, 'issue'); | ||
$this->addMessage($file, $rules, $idx, 'recommendation'); | ||
$this->addMessage($file, $rules, $idx, 'justification'); | ||
} | ||
} | ||
|
||
foreach ($this->messages as $index => $message) { | ||
$output->writeln(''); | ||
$output->write('#: '); | ||
$output->writeln(implode(' ', $this->locations[$index])); | ||
if (strstr($this->messages[$index], '%') !== false) { | ||
$output->writeln('#, php-format'); | ||
} | ||
$output->write('msgid "'); | ||
$output->write(addcslashes( | ||
Advisor::escapePercent($this->messages[$index]), | ||
'"\\' | ||
)); | ||
$output->writeln('"'); | ||
$output->writeln('msgstr ""'); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $file file name | ||
* @param array $rules rules array | ||
* @param int $index rule index | ||
* @param string $type rule type | ||
* | ||
* @return void | ||
*/ | ||
private function addMessage(string $file, array $rules, int $index, string $type): void | ||
{ | ||
if ($type == 'justification') { | ||
$messages = Advisor::splitJustification($rules['rules'][$index]); | ||
$message = $messages[0]; | ||
} else { | ||
$message = $rules['rules'][$index][$type]; | ||
} | ||
$line = $file . ':' . $rules['lines'][$index][$type]; | ||
|
||
$pos = array_search($message, $this->messages); | ||
if ($pos === false) { | ||
$this->messages[] = $message; | ||
$this->locations[] = [$line]; | ||
} else { | ||
$this->locations[$pos][] = $line; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use PhpMyAdmin\Command\AdvisoryRulesCommand; | ||
use Symfony\Component\Console\Application; | ||
|
||
if (! defined('ROOT_PATH')) { | ||
define('ROOT_PATH', dirname(__DIR__) . DIRECTORY_SEPARATOR); | ||
} | ||
|
||
define('PHPMYADMIN', true); | ||
require_once ROOT_PATH . 'libraries/vendor_config.php'; | ||
require_once AUTOLOAD_FILE; | ||
|
||
$application = new Application('phpMyAdmin Console Tool'); | ||
|
||
$application->add(new AdvisoryRulesCommand()); | ||
|
||
$application->run(); |
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