-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration manager, which will clean up migrations records in orde…
…r to keep everything in clean state.
- Loading branch information
Showing
18 changed files
with
289 additions
and
38 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
modules/newsroom_connector_country/newsroom_connector_country.module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Provides newsroom_connector_country functionality. | ||
*/ | ||
|
||
use Drupal\newsroom_connector_country\Plugin\newsroom\NewsroomCountryNewsroomProcessor; | ||
|
||
/** | ||
* Implements hook_entity_delete(). | ||
*/ | ||
function newsroom_connector_country_taxonomy_term_delete(Drupal\Core\Entity\EntityInterface $entity) { | ||
if ($entity->bundle() == 'newsroom_country') { | ||
// Clean up migrations. | ||
\Drupal::service('newsroom_connector.migration_manager')->cleanUpMigrations(NewsroomCountryNewsroomProcessor::MIGRATION_COUNTRY, $entity); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 16 additions & 1 deletion
17
modules/newsroom_connector_service/newsroom_connector_service.module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
modules/newsroom_connector_team_responsible/newsroom_connector_team_responsible.module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Provides newsroom_connector_team_responsible functionality. | ||
*/ | ||
|
||
use Drupal\newsroom_connector_team_responsible\Plugin\newsroom\NewsroomTeamResponsibleNewsroomProcessor; | ||
|
||
/** | ||
* Implements hook_entity_delete(). | ||
*/ | ||
function newsroom_connector_team_responsible_taxonomy_term_delete(Drupal\Core\Entity\EntityInterface $entity) { | ||
if ($entity->bundle() == 'newsroom_team_responsible') { | ||
// Clean up migrations. | ||
\Drupal::service('newsroom_connector.migration_manager')->cleanUpMigrations(NewsroomTeamResponsibleNewsroomProcessor::MIGRATION_TEAM_RESPONSIBLE, $entity); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
modules/newsroom_connector_topic/newsroom_connector_topic.module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Provides newsroom_connector_topic functionality. | ||
*/ | ||
|
||
use Drupal\newsroom_connector_topic\Plugin\newsroom\NewsroomTopicNewsroomProcessor; | ||
|
||
/** | ||
* Implements hook_entity_delete(). | ||
*/ | ||
function newsroom_connector_topic_taxonomy_term_delete(Drupal\Core\Entity\EntityInterface $entity) { | ||
if ($entity->bundle() == 'newsroom_topic') { | ||
// Clean up migrations. | ||
\Drupal::service('newsroom_connector.migration_manager')->cleanUpMigrations(NewsroomTopicNewsroomProcessor::MIGRATION_TOPIC, $entity); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace Drupal\newsroom_connector; | ||
|
||
use Drupal\Core\Entity\ContentEntityInterface; | ||
use Drupal\Core\Language\LanguageManagerInterface; | ||
use Drupal\migrate\Plugin\MigrationPluginManager; | ||
|
||
class MigrationManager implements MigrationManagerInterface { | ||
|
||
/** | ||
* Migration plugin manager service. | ||
* | ||
* @var \Drupal\migrate\Plugin\MigrationPluginManager | ||
*/ | ||
protected $migrationPluginManager; | ||
|
||
/** | ||
* @var \Drupal\Core\Language\LanguageManagerInterface | ||
*/ | ||
protected $languageManager; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct(MigrationPluginManager $migrationPluginManager, LanguageManagerInterface $languageManager) { | ||
$this->migrationPluginManager = $migrationPluginManager; | ||
$this->languageManager = $languageManager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function cleanUpMigrations($migration_id, ContentEntityInterface $entity) { | ||
$id = $entity->getEntityType()->getKey('id'); | ||
$destination_keys = []; | ||
$destination_keys[$id] = $entity->id(); | ||
$this->deleteDestination($migration_id, $destination_keys); | ||
|
||
// Run cleanup for translations' migrations. | ||
$languages = $this->languageManager->getLanguages(); | ||
foreach ($languages as $language) { | ||
$destination_keys['langcode'] = $language->getId(); | ||
$this->deleteDestination($this->getTranslationMigrationId($migration_id, $language->getId()), $destination_keys); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function normalizeLanguage($language_id) { | ||
// For languages pt-pt, we take the first part only. | ||
if (strpos($language_id, '-') !== FALSE) { | ||
$parts = explode('-', $language_id); | ||
$language_id = $parts[0]; | ||
} | ||
|
||
return $language_id; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTranslationMigrationId($migration_id, $language_id) { | ||
$language_id = $this->normalizeLanguage($language_id); | ||
return "{$migration_id}_translations:{$language_id}"; | ||
} | ||
|
||
/** | ||
* Delete migration records based on keys. | ||
* | ||
* @param string $migration_id | ||
* Migration id. | ||
* @param array $destination_keys | ||
* Destination keys. | ||
*/ | ||
protected function deleteDestination($migration_id, array $destination_keys) { | ||
$migration = $this->migrationPluginManager->createInstance($migration_id); | ||
if (empty($migration)) { | ||
return; | ||
} | ||
/** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map */ | ||
$id_map = $migration->getIdMap(); | ||
$id_map->deleteDestination($destination_keys); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Drupal\newsroom_connector; | ||
|
||
use Drupal\Core\Entity\ContentEntityInterface; | ||
|
||
interface MigrationManagerInterface { | ||
|
||
/** | ||
* Clean migration records for a deleted entity. | ||
* | ||
* @param string $migration_id | ||
* Migration id | ||
* @param \Drupal\Core\Entity\ContentEntityInterface $entity | ||
* Deleted entity. | ||
*/ | ||
public function cleanUpMigrations($migration_id, ContentEntityInterface $entity); | ||
|
||
/** | ||
* Normalize language to newsroom format. | ||
* | ||
* @param string $language_id | ||
* Language id. | ||
* @return string | ||
* Normalized language. | ||
*/ | ||
public function normalizeLanguage($language_id); | ||
|
||
/** | ||
* Get migration id for translations. | ||
* | ||
* @param string $migration_id | ||
* Plugin id | ||
* @param string $language_id | ||
* Language id. | ||
* | ||
* @return string | ||
* Translation migration id. | ||
*/ | ||
public function getTranslationMigrationId($migration_id, $language_id); | ||
|
||
} |
Oops, something went wrong.