summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgit2018-02-25 13:48:22 (GMT)
committerTim Kruijsen2018-02-25 13:48:22 (GMT)
commitab27251153ccd578ed63abd1d23ce6a896ee0a22 (patch)
treea0add786e41c326fc75ed9992967a2375089bdde
parent9c658938ee62bed24d74aa638841b46eb8a4d681 (diff)
Issue #2942004 by vml-bsummers: Drush include file not used8.x-1.10
-rw-r--r--drush.services.yml5
-rw-r--r--src/Commands/StructureSyncCommands.php215
2 files changed, 220 insertions, 0 deletions
diff --git a/drush.services.yml b/drush.services.yml
new file mode 100644
index 0000000..b707854
--- /dev/null
+++ b/drush.services.yml
@@ -0,0 +1,5 @@
+services:
+ structure_sync.commands:
+ class: \Drupal\structure_sync\Commands\StructureSyncCommands
+ tags:
+ - { name: drush.command }
diff --git a/src/Commands/StructureSyncCommands.php b/src/Commands/StructureSyncCommands.php
new file mode 100644
index 0000000..ef4703e
--- /dev/null
+++ b/src/Commands/StructureSyncCommands.php
@@ -0,0 +1,215 @@
+<?php
+
+namespace Drupal\structure_sync\Commands;
+
+use Drush\Commands\DrushCommands;
+use Drupal\structure_sync\StructureSyncHelper;
+
+/**
+ * A Drush commandfile.
+ *
+ * In addition to this file, you need a drush.services.yml
+ * in root of your module, and a composer.json file that provides the name
+ * of the services file to use.
+ *
+ * See these files for an example of injecting Drupal services:
+ * - http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php
+ * - http://cgit.drupalcode.org/devel/tree/drush.services.yml
+ */
+class StructureSyncCommands extends DrushCommands {
+
+ /**
+ * Export the taxonomies
+ *
+ * @validate-module-enabled structure_sync
+ *
+ * @command export:taxonomies
+ *
+ * @aliases et,export-taxonomies
+ */
+ public function exportTaxonomies() {
+ $this->output()->writeln('Exporting taxonomies...');
+
+ StructureSyncHelper::exportTaxonomies(['drush' => TRUE]);
+
+ $this->logger()->info('Successfully exported taxonomies');
+ }
+
+ /**
+ * Import the taxonomies
+ *
+ * @validate-module-enabled structure_sync
+ *
+ * @command import:taxonomies
+ *
+ * @option choice Import style choice.
+ * @aliases it,import-taxonomies
+ */
+ public function importTaxonomies($options = ['choice' => NULL]) {
+ $this->output()->writeln('Importing taxonomies...');
+
+ $choices = [
+ 'full' => 'Full',
+ 'safe' => 'Safe',
+ 'force' => 'Force',
+ ];
+
+ if (!$options['choice']) {
+ $options['choice'] = $this->io()->choice(dt("What import style would you like?"), $choices);
+ }
+
+ if ($options['choice'] && array_key_exists($options['choice'], $choices)) {
+ $this->output()->writeln('Using "' . $choices[$options['choice']] . '" import style');
+
+ StructureSyncHelper::importTaxonomies([
+ 'style' => $options['choice'],
+ 'drush' => TRUE,
+ ]);
+
+ $this->logger()->info('Successfully imported taxonomies');
+ }
+ else {
+ $this->logger()->warning('No choice made for import style on importing taxonomies');
+ }
+ }
+
+ /**
+ * Export blocks
+ *
+ * @validate-module-enabled structure_sync
+ *
+ * @command export:blocks
+ * @aliases eb,export-blocks
+ */
+ public function exportBlocks() {
+ $this->output()->writeln('Exporting blocks...');
+
+ StructureSyncHelper::exportCustomBlocks(['drush' => TRUE]);
+
+ $this->logger()->info('Successfully exported blocks');
+ }
+
+ /**
+ * Import blocks
+ *
+ * @validate-module-enabled structure_sync
+ *
+ * @command import:blocks
+ *
+ * @option choice Import style choice.
+ * @aliases ib,import-blocks
+ */
+ public function importBlocks($options = ['choice' => NULL]) {
+ $this->output()->writeln('Importing blocks...');
+
+ $choices = [
+ 'full' => 'Full',
+ 'safe' => 'Safe',
+ 'force' => 'Force',
+ ];
+
+ if (!$options['choice']) {
+ $options['choice'] = $this->io()->choice(dt("What import style would you like?"), $choices);
+ }
+
+ if ($options['choice'] && array_key_exists($options['choice'], $choices)) {
+ $this->output()->writeln('Using "' . $choices[$options['choice']] . '" import style');
+
+ StructureSyncHelper::importCustomBlocks([
+ 'style' => $options['choice'],
+ 'drush' => TRUE,
+ ]);
+
+ $this->logger()->info('Successfully imported custom blocks');
+ }
+ else {
+ $this->logger()->warning('No choice made for import style on importing custom blocks');
+ }
+ }
+
+ /**
+ * Export menu links
+ *
+ * @validate-module-enabled structure_sync
+ *
+ * @command export:menus
+ * @aliases em,export-menus
+ */
+ public function exportMenus() {
+ $this->output()->writeln('Exporting menu links...');
+
+ StructureSyncHelper::exportMenuLinks(['drush' => TRUE]);
+
+ $this->logger()->info('Successfully exported menu links');
+ }
+
+ /**
+ * Import menu links
+ *
+ * @validate-module-enabled structure_sync
+ *
+ * @command import:menus
+ *
+ * @option choice Import style choice.
+ * @aliases im,import-menus
+ */
+ public function importMenus($options = ['choice' => NULL]) {
+
+ $this->output()->writeln('Importing menu links...');
+
+ $choices = [
+ 'full' => 'Full',
+ 'safe' => 'Safe',
+ 'force' => 'Force',
+ ];
+
+ if (!$options['choice']) {
+ $options['choice'] = $this->io()->choice(dt("What import style would you like?"), $choices);
+ }
+
+ if ($options['choice'] && array_key_exists($options['choice'], $choices)) {
+ $this->output()->writeln('Using "' . $choices[$options['choice']] . '" import style');
+
+ StructureSyncHelper::importMenuLinks([
+ 'style' => $options['choice'],
+ 'drush' => TRUE,
+ ]);
+
+ $this->logger()->info('Successfully imported menu links');
+ }
+ else {
+ $this->logger()->warning('No choice made for import style on importing menu links');
+ }
+ }
+
+ /**
+ * Import menu links, Taxonomy and Blocks
+ *
+ * @validate-module-enabled structure_sync
+ *
+ * @command import:all
+ *
+ * @option choice Import style choice.
+ * @aliases ia,import-all
+ */
+ public function importAll($options = ['choice' => NULL]) {
+ $this->importTaxonomies($options);
+ $this->importBlocks($options);
+ $this->importMenus($options);
+ }
+
+ /**
+ * Export menu links, Taxonomy and Blocks
+ *
+ * @validate-module-enabled structure_sync
+ *
+ * @command export:all
+ * @aliases ea,export-all
+ */
+ public function exportAll() {
+ $this->exportTaxonomies();
+ $this->exportBlocks();
+ $this->exportMenus();
+ }
+
+}