-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmnn_show_import.module
72 lines (53 loc) · 1.92 KB
/
mnn_show_import.module
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @file
* Code for the MNN Show Import feature.
*/
include_once('mnn_show_import.features.inc');
/**
* Implements hook_menu()
*/
function mnn_show_import_menu() {
$items['admin/show/resave-all'] = array(
'title' => 'Resave All Shows',
'description' => 'Enable Active Projects',
'page callback' => 'mnn_show_import_resave_batch_init',
'access arguments' => array('administer group'),
'type' => MENU_CALLBACK
);
return $items;
}
function mnn_show_import_resave_batch_init() {
$batch = array(
'title' => t('Resaving Show Nodes...'),
'operations' => array(),
'init_message' => t('Starting Resave'),
'progress_message' => t('Processed @current out of @total.'),
'error_message' => t('An error occurred during processing'),
'finished' => 'mnn_show_import_resave_batch_finished',
'progressive' => FALSE
);
//query all show nodes
//SELECT nid, ogm.id FROM node n LEFT JOIN og_membership ogm ON etid = nid WHERE n.type = 'cm_show' and ogm.id IS NULL
$result = db_query('SELECT nid FROM {node} n LEFT JOIN {og_membership} ogm ON etid = nid WHERE n.type = :type AND ogm.id IS NULL', array(':type' => 'cm_show'));
//query show nodes without OG2 reference
//etid
$count = 0;
foreach ($result as $record) {
if ($count < 10000) {
$batch['operations'][] = array('mnn_show_import_resave_batch_worker', array($record->nid));
$count++;
}
}
batch_set($batch);
batch_process('admin/content');
}
function mnn_show_import_resave_batch_worker($nid, &$context) {
$node = node_load($nid);
if (isset($node->field_temp_project_id['und'][0]['value']) && $node->field_temp_project_id['und'][0]['value']) {
$node->og_node2['und'][0]['target_id'] = $node->field_temp_project_id['und'][0]['value'];
}
node_save($node);
$context['results']['processed']++;
$context['message'] = 'Successfully resaved Show #' . $array[0];
}