diff --git a/drush.services.yml b/drush.services.yml new file mode 100644 index 0000000000000000000000000000000000000000..b707854099ecaf9b5a146543caa60b1040a5ad56 --- /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 0000000000000000000000000000000000000000..ef4703e41bcba0aa6e2914ee25d8e99a7cbf914b --- /dev/null +++ b/src/Commands/StructureSyncCommands.php @@ -0,0 +1,215 @@ +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(); + } + +}