You are here

class StructureSyncCommands in Structure Sync 8

Same name and namespace in other branches
  1. 2.x src/Commands/StructureSyncCommands.php \Drupal\structure_sync\Commands\StructureSyncCommands

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:

Hierarchy

Expanded class hierarchy of StructureSyncCommands

1 string reference to 'StructureSyncCommands'
drush.services.yml in ./drush.services.yml
drush.services.yml
1 service uses StructureSyncCommands
structure_sync.commands in ./drush.services.yml
\Drupal\structure_sync\Commands\StructureSyncCommands

File

src/Commands/StructureSyncCommands.php, line 19

Namespace

Drupal\structure_sync\Commands
View source
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();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StructureSyncCommands::exportAll public function Export menu links, Taxonomy and Blocks
StructureSyncCommands::exportBlocks public function Export blocks
StructureSyncCommands::exportMenus public function Export menu links
StructureSyncCommands::exportTaxonomies public function Export the taxonomies
StructureSyncCommands::importAll public function Import menu links, Taxonomy and Blocks
StructureSyncCommands::importBlocks public function Import blocks
StructureSyncCommands::importMenus public function Import menu links
StructureSyncCommands::importTaxonomies public function Import the taxonomies