rocketship_core-8.x-2.0-alpha11/modules/rocketship_content/rocketship_content.install
modules/rocketship_content/rocketship_content.install
<?php
/**
* @file
* Install file.
*/
use Drupal\migrate\MigrateExecutable;
/**
* Implements hook_install().
*/
function rocketship_content_install() {
// Import the content.
try {
$migration = \Drupal::service('plugin.manager.migration')
->createInstance('rc_text_main_p');
if ($migration) {
$executable = new MigrateExecutable($migration);
$executable->import();
}
$migration = \Drupal::service('plugin.manager.migration')
->createInstance('rc_simple_header');
if ($migration) {
$executable = new MigrateExecutable($migration);
$executable->import();
}
$migration = \Drupal::service('plugin.manager.migration')
->createInstance('rocketship_pages');
if ($migration) {
$executable = new MigrateExecutable($migration);
$executable->import();
}
\Drupal::messenger()
->addMessage(t('Migrated the Rocketship Content content.'));
}
catch (\Exception $e) {
\Drupal::messenger()
->addError(t('Failed migrating Rocketship Content content.'));
}
}
/**
* Implements hook_uninstall().
*/
function rocketship_content_uninstall() {
try {
// Rollback the content (reverse order)
$migration = \Drupal::service('plugin.manager.migration')
->createInstance('rocketship_pages');
$executable = new MigrateExecutable($migration);
$executable->rollback();
$migration = \Drupal::service('plugin.manager.migration')
->createInstance('rc_text_main_p');
$executable = new MigrateExecutable($migration);
$executable->rollback();
$migration = \Drupal::service('plugin.manager.migration')
->createInstance('rc_simple_header');
$executable = new MigrateExecutable($migration);
$executable->rollback();
\Drupal::messenger()
->addMessage(t('Rolled back the Rocketship Content migration.'));
// Delete our migrates.
\Drupal::configFactory()
->getEditable('migrate_plus.migration.rocketship_pages')
->delete();
\Drupal::configFactory()
->getEditable('migrate_plus.migration.rc_text_main_p')
->delete();
\Drupal::configFactory()
->getEditable('migrate_plus.migration.rc_simple_header')
->delete();
\Drupal::configFactory()
->getEditable('migrate_plus.migration_group.rocketship_content')
->delete();
\Drupal::messenger()
->addMessage(t('Deleted the Rocketship Content migrations.'));
}
catch (\Exception $e) {
\Drupal::messenger()
->addError(t('Failed rolling back the Rocketship Content content.'));
}
}
