From e03c085ef2c83d52a869a5e49f57f298f0fbe4e5 Mon Sep 17 00:00:00 2001 From: enzo - Eduardo Garcia Date: Tue, 11 Jun 2019 10:33:19 +1000 Subject: [PATCH 1/4] Update version to 1.9.0 (#4085) * Removed generate commands and generators * Revert "Removed generate commands and generators (#3417)" This reverts commit 1dea474267555f569ca7f1d8d61396918be99bfb. * Update version to 1.9.0 --- composer.json | 2 +- src/Application.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e14616a3c..356a1dd7a 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "composer/installers": "~1.0", "doctrine/annotations": "^1.2", "doctrine/collections": "^1.3", - "drupal/console-core": "1.8.0", + "drupal/console-core": "1.9.0", "drupal/console-extend-plugin": "~0", "psy/psysh": "0.6.* || ~0.8", "symfony/css-selector": "~2.8|~3.0", diff --git a/src/Application.php b/src/Application.php index ff247181f..3804126fd 100644 --- a/src/Application.php +++ b/src/Application.php @@ -25,7 +25,7 @@ class Application extends BaseApplication /** * @var string */ - const VERSION = '1.8.0'; + const VERSION = '1.9.0'; public function __construct(ContainerInterface $container) { From e076e833414cd21800439e692325880d4da76bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harold=20Ju=C3=A1rez?= Date: Mon, 17 Jun 2019 13:05:06 -0600 Subject: [PATCH 2/4] [create:nodes] Added the revision option (#4091) --- src/Command/Create/NodesCommand.php | 17 +++++++++++++++++ src/Utils/Create/NodeData.php | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/Command/Create/NodesCommand.php b/src/Command/Create/NodesCommand.php index 54c6bfee9..af9608bf7 100644 --- a/src/Command/Create/NodesCommand.php +++ b/src/Command/Create/NodesCommand.php @@ -87,6 +87,12 @@ protected function configure() InputOption::VALUE_OPTIONAL, $this->trans('commands.create.nodes.options.time-range') ) + ->addOption( + 'revision', + null, + InputOption::VALUE_NONE, + $this->trans('commands.create.nodes.options.revision') + ) ->addOption( 'language', null, @@ -151,6 +157,15 @@ function ($contentType) use ($bundles) { $input->setOption('time-range', array_search($timeRange, $timeRanges)); } + $revision = is_null($input->getOption('revision')); + if (!$revision) { + $revision = $this->getIo()->confirm( + $this->trans('commands.create.nodes.questions.revision') + ); + + $input->setOption('revision', $revision); + } + // Language module is enabled or not. $languageModuleEnabled = \Drupal::moduleHandler() ->moduleExists('language'); @@ -193,6 +208,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $limit = $input->getOption('limit')?:25; $titleWords = $input->getOption('title-words')?:5; $timeRange = $input->getOption('time-range')?:31536000; + $revision = $input->getOption('revision'); $available_types = array_keys($this->drupalApi->getBundles()); $language = $input->getOption('language')?:'und'; @@ -211,6 +227,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $limit, $titleWords, $timeRange, + $revision, $language ); diff --git a/src/Utils/Create/NodeData.php b/src/Utils/Create/NodeData.php index f4d1f41fe..4d1e98dcc 100644 --- a/src/Utils/Create/NodeData.php +++ b/src/Utils/Create/NodeData.php @@ -24,6 +24,7 @@ class NodeData extends Base * @param $limit * @param $titleWords * @param $timeRange + * @param $revision * * @return array */ @@ -32,6 +33,7 @@ public function create( $limit, $titleWords, $timeRange, + $revision, $language = LanguageInterface::LANGCODE_NOT_SPECIFIED ) { $nodes = []; @@ -55,6 +57,13 @@ public function create( $this->generateFieldSampleData($node); $node->save(); + + if($revision) { + for ($a = 0; $a < 3; $a++) { + $this->addRevision($node, $a); + } + } + $nodes['success'][] = [ 'nid' => $node->id(), 'node_type' => $bundles[$contentType], @@ -72,4 +81,16 @@ public function create( return $nodes; } + + /** + * @param $node + * @param $count + */ + private function addRevision($node, $count) { + $node->setTitle($this->getRandom()->sentences(mt_rand(1, 5), true)); + $node->setNewRevision(TRUE); + $node->revision_log = "Revision number $count was created"; + $node->setRevisionCreationTime(REQUEST_TIME); + $node->save(); + } } From 14dead1c6e1e7ef1327c19ad75ad9494a634890e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harold=20Ju=C3=A1rez?= Date: Mon, 17 Jun 2019 15:36:06 -0600 Subject: [PATCH 3/4] [database:dump | database:restore] Implement the symfony process and remove escapeshellcmd (#4092) * [update:execute] Fixed update table * Revert "Merge remote-tracking branch 'upstream/master'" This reverts commit ddf77395b32e35f259e9b1503eedb71b71c52604, reversing changes made to a95b7e60be2b2cd53d5371f2cc2c0d976e1c1c19. * [database:dump] Implemented symfony process and remove escapeshellcmd --- src/Command/Database/DumpCommand.php | 176 +++++++++++++----------- src/Command/Database/RestoreCommand.php | 15 +- src/Command/Shared/ConnectTrait.php | 2 +- 3 files changed, 101 insertions(+), 92 deletions(-) diff --git a/src/Command/Database/DumpCommand.php b/src/Command/Database/DumpCommand.php index a67f4fe0a..4650838db 100644 --- a/src/Command/Database/DumpCommand.php +++ b/src/Command/Database/DumpCommand.php @@ -15,6 +15,7 @@ use Drupal\Console\Command\Shared\ConnectTrait; use Drupal\Console\Core\Utils\ShellProcess; use Drupal\Core\Database\Connection; +use Symfony\Component\Process\Process; class DumpCommand extends Command { @@ -82,10 +83,10 @@ protected function configure() $this->trans('commands.database.dump.options.gz') ) ->addOption( - 'exclude-cache', - null, - InputOption::VALUE_NONE, - $this->trans('commands.database.dump.options.exclude.cache') + 'exclude-cache', + null, + InputOption::VALUE_NONE, + $this->trans('commands.database.dump.options.exclude.cache') ) ->setHelp($this->trans('commands.database.dump.help')) ->setAliases(['dbdu']); @@ -140,97 +141,106 @@ protected function execute(InputInterface $input, OutputInterface $output) $command = null; - if ($databaseConnection['driver'] == 'mysql') { - $command = sprintf( - 'mysqldump --user="%s" --password="%s" --host="%s" --port="%s" "%s" > "%s"', - $databaseConnection['username'], - $databaseConnection['password'], - $databaseConnection['host'], - $databaseConnection['port'], - $databaseConnection['database'], - $file - ); - - if ($excludeCache) { - $ignoreTable = ''; - foreach ($excludeTables as $table) { - $ignoreTable .= "--ignore-table=\"{$table}\" "; - } - - $command = sprintf( - 'mysqldump --user="%s" --password="%s" --host="%s" --port="%s" %s "%s"> "%s"', - $databaseConnection['username'], - $databaseConnection['password'], - $databaseConnection['host'], - $databaseConnection['port'], - $ignoreTable, - $databaseConnection['database'], - $file - ); - - } + if ($databaseConnection['driver'] == 'mysql') { + $command = sprintf( + "mysqldump --user='%s' --password='%s' --host='%s' --port='%s' '%s' > '%s'", + $databaseConnection['username'], + $databaseConnection['password'], + $databaseConnection['host'], + $databaseConnection['port'], + $databaseConnection['database'], + $file + ); + + if ($excludeCache) { + $ignoreTable = ''; + foreach ($excludeTables as $table) { + $ignoreTable .= "--ignore-table=\"{$table}\" "; + } + + $command = sprintf( + "mysqldump --user='%s' --password='%s' --host='%s' --port='%s' %s '%s'> '%s'", + $databaseConnection['username'], + $databaseConnection['password'], + $databaseConnection['host'], + $databaseConnection['port'], + $ignoreTable, + $databaseConnection['database'], + $file + ); + + } } elseif ($databaseConnection['driver'] == 'pgsql') { - $command = sprintf( - 'PGPASSWORD="%s" pg_dumpall -w -U "%s" -h "%s" -p "%s" -l "%s" -f "%s"', - $databaseConnection['password'], - $databaseConnection['username'], - $databaseConnection['host'], - $databaseConnection['port'], - $databaseConnection['database'], - $file - ); - - if ($excludeCache) { - $ignoreTable = ''; - foreach ($excludeTables as $table) { - $ignoreTable .= "-T \"{$table}\" "; - } - - $command = sprintf( - 'PGPASSWORD="%s" pg_dump -w -U "%s" -h "%s" -p "%s" -f "%s" %s-d "%s"', - $databaseConnection['password'], - $databaseConnection['username'], - $databaseConnection['host'], - $databaseConnection['port'], - $file, - $ignoreTable, - $databaseConnection['database'] - ); - } + $command = sprintf( + "PGPASSWORD='%s' pg_dumpall -w -U '%s' -h '%s' -p '%s' -l '%s' -f '%s'", + $databaseConnection['password'], + $databaseConnection['username'], + $databaseConnection['host'], + $databaseConnection['port'], + $databaseConnection['database'], + $file + ); + + if ($excludeCache) { + $ignoreTable = ''; + foreach ($excludeTables as $table) { + $ignoreTable .= "-T \"{$table}\" "; + } + + $command = sprintf( + "PGPASSWORD='%s' pg_dump -w -U '%s' -h '%s' -p '%s' -f '%s' %s-d '%s'", + $databaseConnection['password'], + $databaseConnection['username'], + $databaseConnection['host'], + $databaseConnection['port'], + $file, + $ignoreTable, + $databaseConnection['database'] + ); + } } if ($learning) { $this->getIo()->commentBlock($command); } - if ($this->shellProcess->exec($command, $this->appRoot)) { - $resultFile = $file; - if ($gz) { - if (substr($file, -3) != '.gz') { - $resultFile = $file . '.gz'; - } - file_put_contents( - $resultFile, - gzencode( - file_get_contents( - $file + try { + $process = new Process($command); + $process->setTimeout(null); + $process->setWorkingDirectory($this->appRoot); + $process->run(); + + if($process->isSuccessful()) { + $resultFile = $file; + if ($gz) { + if (substr($file, -3) != '.gz') { + $resultFile = $file . '.gz'; + } + file_put_contents( + $resultFile, + gzencode( + file_get_contents( + $file + ) ) + ); + if ($resultFile != $file) { + unlink($file); + } + } + + $this->getIo()->success( + sprintf( + '%s %s', + $this->trans('commands.database.dump.messages.success'), + $resultFile ) ); - if ($resultFile != $file) { - unlink($file); - } } - $this->getIo()->success( - sprintf( - '%s %s', - $this->trans('commands.database.dump.messages.success'), - $resultFile - ) - ); + return 0; + } catch (\Exception $e) { + return 1; } - - return 0; } } diff --git a/src/Command/Database/RestoreCommand.php b/src/Command/Database/RestoreCommand.php index 7ee368d20..ad5be0074 100644 --- a/src/Command/Database/RestoreCommand.php +++ b/src/Command/Database/RestoreCommand.php @@ -11,7 +11,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; use Drupal\Console\Core\Command\Command; use Drupal\Console\Command\Shared\ConnectTrait; @@ -94,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($databaseConnection['driver'] == 'mysql') { // Drop database first. $commands[] = sprintf( - 'mysql --user=%s --password=%s --host=%s --port=%s -e"DROP DATABASE IF EXISTS %s"', + "mysql --user='%s' --password='%s' --host='%s' --port='%s' -e'DROP DATABASE IF EXISTS %s'", $databaseConnection['username'], $databaseConnection['password'], $databaseConnection['host'], @@ -104,7 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // Recreate database. $commands[] = sprintf( - 'mysql --user=%s --password=%s --host=%s --port=%s -e"CREATE DATABASE %s"', + "mysql --user='%s' --password='%s' --host='%s' --port='%s' -e'CREATE DATABASE %s'", $databaseConnection['username'], $databaseConnection['password'], $databaseConnection['host'], @@ -114,7 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // Import dump. $commands[] = sprintf( - $catCommand . 'mysql --user=%s --password=%s --host=%s --port=%s %s', + $catCommand . "mysql --user='%s' --password='%s' --host='%s' --port='%s' %s", $file, $databaseConnection['username'], $databaseConnection['password'], @@ -124,7 +124,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ); } elseif ($databaseConnection['driver'] == 'pgsql') { $commands[] = sprintf( - 'PGPASSWORD="%s" ' . $catCommand . 'psql -w -U %s -h %s -p %s -d %s', + "PGPASSWORD='%s' " . $catCommand . "psql -w -U '%s' -h '%s' -p '%s' -d '%s'", $file, $databaseConnection['password'], $databaseConnection['username'], @@ -139,11 +139,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->getIo()->commentBlock($command); } - $processBuilder = new ProcessBuilder(['-v']); - $process = $processBuilder->getProcess(); + $process = new Process($command); + $process->setTimeout(null); $process->setWorkingDirectory($this->appRoot); $process->setTty($input->isInteractive()); - $process->setCommandLine($command); $process->run(); if (!$process->isSuccessful()) { diff --git a/src/Command/Shared/ConnectTrait.php b/src/Command/Shared/ConnectTrait.php index 24ddd8b40..1b2e93f47 100644 --- a/src/Command/Shared/ConnectTrait.php +++ b/src/Command/Shared/ConnectTrait.php @@ -75,7 +75,7 @@ public function escapeConnection($databaseConnection) { ]; foreach ($settings as $setting) { - $databaseConnection[$setting] = escapeshellcmd($databaseConnection[$setting]); + $databaseConnection[$setting] = $databaseConnection[$setting]; } return $databaseConnection; From 541cd2ecda5e1e071239507932d928a5fec735a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harold=20Ju=C3=A1rez?= Date: Mon, 17 Jun 2019 16:40:44 -0600 Subject: [PATCH 4/4] [generate:form] Input missing was fixed (#4093) * [update:execute] Fixed update table * Revert "Merge remote-tracking branch 'upstream/master'" This reverts commit ddf77395b32e35f259e9b1503eedb71b71c52604, reversing changes made to a95b7e60be2b2cd53d5371f2cc2c0d976e1c1c19. * [generate:form] Input missing was fixed --- templates/module/src/Form/form.php.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/module/src/Form/form.php.twig b/templates/module/src/Form/form.php.twig index 4300e16f3..fd8f06fca 100644 --- a/templates/module/src/Form/form.php.twig +++ b/templates/module/src/Form/form.php.twig @@ -115,7 +115,7 @@ class {{ class_name }} extends FormBase {% endblock %} public function submitForm(array &$form, FormStateInterface $form_state) { // Display result. foreach ($form_state->getValues() as $key => $value) { - \Drupal::messenger()->addMessage($key . ': ' . $value{% if input.type == 'text_format' %}['value']{% endif %}); + \Drupal::messenger()->addMessage($key . ': ' . ($key === 'text_format'?$value['value']:$value)); } } {% endblock %}