Skip to content

Commit 6f72f2c

Browse files
committed
Script for fixing nodes publish status
1 parent 71ce459 commit 6f72f2c

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
use Drupal\Core\Database\Database;
3+
use Drupal\node\Entity\Node;
4+
5+
$database = \Drupal::database();
6+
$migrateDatabase = Database::getConnection('default', 'migrate');
7+
8+
// Getting all migrate NIDS.
9+
$node_migrate_tables = [
10+
'migrate_map_ballerup_d7_node_gallery_slide',
11+
'migrate_map_ballerup_d7_node_indholdside',
12+
'migrate_map_ballerup_d7_node_institution_page',
13+
'migrate_map_ballerup_d7_node_news',
14+
];
15+
16+
$migrate_nids = [];
17+
foreach ($node_migrate_tables as $table) {
18+
$table_nids = $database->select($table)->fields($table, [
19+
'destid1',
20+
'sourceid1',
21+
])
22+
->isNotNull('destid1')
23+
->execute()
24+
->fetchAllKeyed();
25+
26+
$migrate_nids += $table_nids;
27+
}
28+
29+
// Getting node status.
30+
$migrateNodeStatus = $migrateDatabase->select('node')->fields('node', [
31+
'nid',
32+
'status',
33+
])->execute()->fetchAllKeyed();
34+
35+
$nids = \Drupal::entityQuery('node')
36+
->condition('status', 0)
37+
->condition('type', ['os2web_page', 'os2web_news'], 'IN')
38+
->execute();
39+
40+
$i = 0;
41+
$totalPublished = 0;
42+
foreach ($nids as $nid) {
43+
// Find corresponding migrate_nid
44+
if (isset($migrate_nids[$nid])) {
45+
$migrateNid = $migrate_nids[$nid];
46+
print_r("Inspecting $nid : $migrateNid");
47+
print_r(PHP_EOL);
48+
49+
// Find migrate node status
50+
$status = $migrateNodeStatus[$migrateNid];
51+
print_r("Status is $status");
52+
print_r(PHP_EOL);
53+
54+
// If published.
55+
if ($status) {
56+
print_r("Setting $nid published");
57+
print_r(PHP_EOL);
58+
59+
$node = Node::load($nid);
60+
$node->setPublished(TRUE);
61+
$node->set('moderation_state', "published");
62+
$node->save();
63+
$totalPublished++;
64+
}
65+
}
66+
}
67+
68+
print_r("Total published: $totalPublished");
69+
print_r(PHP_EOL);
70+
71+
72+

0 commit comments

Comments
 (0)