View source
<?php
namespace Drupal\structure_sync\Commands;
use Drush\Commands\DrushCommands;
use Drupal\structure_sync\StructureSyncHelper;
class StructureSyncCommands extends DrushCommands {
public function exportTaxonomies() {
$this
->output()
->writeln('Exporting taxonomies...');
StructureSyncHelper::exportTaxonomies([
'drush' => TRUE,
]);
$this
->logger()
->info('Successfully exported 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');
}
}
public function exportBlocks() {
$this
->output()
->writeln('Exporting blocks...');
StructureSyncHelper::exportCustomBlocks([
'drush' => TRUE,
]);
$this
->logger()
->info('Successfully exported 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');
}
}
public function exportMenus() {
$this
->output()
->writeln('Exporting menu links...');
StructureSyncHelper::exportMenuLinks([
'drush' => TRUE,
]);
$this
->logger()
->info('Successfully exported menu links');
}
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');
}
}
public function importAll($options = [
'choice' => NULL,
]) {
$this
->importTaxonomies($options);
$this
->importBlocks($options);
$this
->importMenus($options);
}
public function exportAll() {
$this
->exportTaxonomies();
$this
->exportBlocks();
$this
->exportMenus();
}
}