-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewsroom_connector.install
55 lines (46 loc) · 1.69 KB
/
newsroom_connector.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* @file
* Update hooks.
*/
use Drupal\Core\Config\ExtensionInstallStorage;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Database\Database;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Clean up empty mappings.
*/
function newsroom_connector_update_9001(&$sandbox) {
$plugins = \Drupal::service('newsroom_connector.plugin.manager.newsroom_processor')->getDefinitions();
/** @var \Drupal\newsroom_connector\MigrationManager $migration_manager */
$migration_manager = \Drupal::service('newsroom_connector.migration_manager');
/** @var \Drupal\Core\Database\Connection $database */
$database = \Drupal::service('database');
foreach ($plugins as $plugin) {
$migrations = $plugin['migrations'] ?? [];
foreach ($migrations as $migration_id) {
$tables = [];
// Get mapping table for given migration.
$migration = $migration_manager->getMigration($migration_id);
if (empty($migration)) {
continue;
}
$tables[] = $migration->getIdMap()->mapTableName();
// Get mapping tables also for translation migration.
$translation_migration_ids = $migration_manager->getTranslationMigrationIds($migration_id);
foreach ($translation_migration_ids as $translation_migration_id) {
$translation_migration = $migration_manager->getMigration($translation_migration_id);
if (empty($translation_migration)) {
continue;
}
$tables[] = $translation_migration->getIdMap()->mapTableName();
}
foreach ($tables as $table) {
$database->delete($table)
->condition('destid1', NULL, 'IS NULL')
->execute();
}
}
}
}