/
mnn_project_import.module
149 lines (116 loc) · 14.5 KB
/
mnn_project_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* @file
* Code for the MNN Project Import feature.
*/
include_once('mnn_project_import.features.inc');
/**
* Implements hook_menu()
*/
function mnn_project_import_menu() {
// This provides a place for Field API to hang its own
// interface and has to be the same as what was defined
// in airing_entity_info() above.
$items['admin/projects/disable-all'] = array(
'title' => 'Disable All Projects',
'description' => 'Disable All Projects',
'page callback' => 'mnn_project_import_disable_all_projects',
'access arguments' => array('administer group'),
'type' => MENU_CALLBACK
);
$items['admin/projects/enable-active'] = array(
'title' => 'Enable Acive Projects',
'description' => 'Enable Active Projects',
'page callback' => 'mnn_project_import_enable_active_projects',
'access arguments' => array('administer group'),
'type' => MENU_CALLBACK
);
$items['admin/projects/enable-all'] = array(
'title' => 'Enable Acive Projects',
'description' => 'Enable Active Projects',
'page callback' => 'mnn_project_import_enable_all_projects',
'access arguments' => array('administer group'),
'type' => MENU_CALLBACK
);
$items['admin/projects/resave-all'] = array(
'title' => 'Resave All Projects',
'description' => 'Enable Active Projects',
'page callback' => 'mnn_project_import_resave_batch_init',
'access arguments' => array('administer group'),
'type' => MENU_CALLBACK
);
return $items;
}
// 1 -
function mnn_project_import_disable_all_projects() {
$num_updated = db_update('og')
->fields(array(
'state' => 2,
))
->execute();
return $num_updated . ' projects disabled';
}
function mnn_project_import_enable_all_projects() {
$num_updated = db_update('og')
->fields(array(
'state' => 1,
))
->execute();
return $num_updated . ' projects enabled';
}
function mnn_project_import_enable_active_projects() {
// on 2-1-2012 there were 1,566 active, but this will change
// SELECT project_id FROM `ac_report_project_cache` WHERE `project_status` LIKE 'Active'
// project_id is now nid
// should have imported Active status into a field we could process from Drupal
$active_projets_array = array(1, 6, 15, 17, 21, 31, 40, 44, 58, 60, 64, 67, 68, 92, 114, 128, 132, 143, 147, 172, 185, 186, 216, 217, 264, 271, 275, 280, 303, 307, 308, 312, 313, 314, 330, 346, 361, 367, 374, 388, 392, 405, 408, 419, 426, 450, 454, 461, 488, 507, 514, 540, 565, 576, 584, 591, 597, 601, 714, 743, 765, 769, 846, 872, 886, 951, 1051, 1064, 1065, 1069, 1325, 1453, 1546, 1596, 1607, 1629, 1731, 1732, 1787, 1792, 1834, 1889, 1897, 2094, 2149, 2157, 2159, 2180, 2231, 2403, 2419, 2500, 2583, 2667, 2679, 2680, 2707, 2713, 2716, 2753, 2815, 2843, 3039, 3052, 3063, 3083, 3121, 3124, 3134, 3229, 3360, 3370, 3375, 3380, 3408, 3435, 3447, 3528, 3734, 3745, 3753, 3771, 3772, 3776, 3779, 3976, 3987, 4014, 4038, 4055, 4068, 4111, 4240, 4276, 4304, 4336, 4345, 4378, 4386, 4646, 4655, 4656, 4657, 4689, 4690, 4725, 4738, 4744, 4795, 4797, 4802, 4828, 4831, 4845, 5077, 5085, 5111, 5116, 5120, 5136, 5167, 5314, 5323, 5482, 5490, 5493, 5504, 5509, 5524, 5534, 5562, 5624, 5862, 5864, 5904, 5922, 5978, 6001, 6070, 6222, 6275, 6329, 6376, 6378, 6529, 6532, 6636, 6685, 6734, 6764, 6810, 6812, 6813, 6821, 7003, 7041, 7043, 7140, 7308, 7342, 7375, 7381, 7384, 7403, 7407, 7602, 7604, 7649, 7651, 7654, 7656, 7736, 7751, 7758, 7775, 7855, 8038, 8055, 8061, 8085, 8133, 8229, 8420, 8422, 8439, 8453, 8454, 8491, 8518, 8572, 8687, 8743, 8783, 8813, 8814, 8846, 8851, 9537, 9572, 9595, 9722, 9901, 9903, 9910, 9959, 10051, 10052, 10073, 10092, 10106, 10399, 10446, 10510, 10691, 10723, 10736, 10999, 11006, 11016, 11026, 11030, 11032, 11118, 11288, 11299, 11678, 11685, 11686, 11691, 11697, 11698, 11699, 11703, 11734, 11799, 11858, 11935, 11943, 11954, 11955, 11964, 11973, 11974, 11975, 12054, 12268, 12276, 12277, 12329, 12512, 12530, 12536, 12543, 12548, 12592, 12593, 12766, 12868, 12872, 12873, 12874, 12890, 12906, 12930, 13111, 13146, 13165, 13169, 13171, 13196, 13205, 13211, 13502, 13503, 13543, 13559, 13560, 13580, 13581, 13584, 13588, 13589, 13603, 13607, 13609, 13635, 13703, 13785, 13888, 13892, 13904, 13908, 13910, 13915, 13935, 13953, 13955, 13962, 13968, 14055, 14177, 14218, 14239, 14301, 14302, 14307, 14312, 14316, 14325, 14328, 14332, 14333, 14341, 14351, 14367, 14369, 14389, 14410, 14446, 14518, 14638, 14639, 14641, 14648, 14650, 14651, 14661, 14665, 14668, 14669, 14673, 14686, 14724, 14808, 14810, 14815, 14958, 14969, 14970, 14981, 14997, 15008, 15044, 15239, 15241, 15254, 15257, 15260, 15264, 15266, 15272, 15298, 15329, 15589, 15603, 15605, 15607, 15611, 15617, 15623, 15628, 15630, 15641, 15644, 15655, 15666, 15670, 15689, 15769, 15944, 15949, 15953, 15955, 15956, 15959, 15983, 15988, 16032, 16310, 16319, 16322, 16332, 16337, 16343, 16345, 16367, 16555, 16563, 16576, 16595, 16603, 16606, 16612, 16615, 16640, 16650, 16669, 16817, 16819, 16820, 16821, 16824, 16836, 16841, 16843, 16852, 16866, 16877, 16881, 16882, 16910, 17022, 17023, 17024, 17039, 17049, 17068, 17070, 17073, 17074, 17076, 17084, 17300, 17301, 17308, 17313, 17323, 17326, 17331, 17336, 17337, 17340, 17346, 17569, 17573, 17584, 17595, 17598, 17604, 17605, 17627, 17629, 17633, 17638, 17640, 17870, 17871, 17877, 17880, 17882, 17885, 17892, 17902, 17904, 17916, 17926, 17930, 17958, 17961, 17966, 17969, 17971, 17977, 17983, 18008, 18084, 18114, 18115, 18116, 18120, 18122, 18155, 18159, 18160, 18170, 18198, 18239, 18366, 18372, 18384, 18393, 18413, 18433, 18441, 18608, 18660, 18662, 18667, 18668, 18670, 18673, 18682, 18685, 18686, 18689, 18690, 18692, 18768, 18801, 21967, 18805, 18848, 18861, 18885, 18901, 18902, 18903, 18905, 18915, 18919, 18922, 18923, 18926, 18927, 18944, 18947, 18948, 18956, 18984, 19189, 19223, 19225, 19226, 19227, 19229, 19230, 19232, 19233, 19241, 19254, 19258, 19260, 19261, 19421, 19429, 19438, 19439, 19443, 19447, 19450, 19459, 19463, 19466, 19472, 19473, 19480, 19482, 19540, 19662, 19672, 19674, 19681, 19682, 19683, 19691, 19696, 19701, 19708, 19729, 19742, 19743, 19753, 19754, 19755, 19756, 19757, 19759, 19763, 19764, 19765, 19767, 19769, 19773, 19774, 19775, 19776, 19777, 19778, 19781, 19793, 19794, 19797, 19800, 19801, 19815, 19816, 19818, 19819, 19820, 19821, 19823, 19824, 19825, 19826, 19827, 19828, 19829, 19830, 19831, 19835, 19836, 19842, 19843, 19853, 19854, 19857, 19859, 19860, 19861, 19862, 19863, 19864, 19865, 19877, 19879, 19881, 19884, 19885, 19886, 19888, 19889, 19890, 19891, 19892, 19896, 19897, 19898, 19908, 19909, 19910, 19912, 19913, 19914, 19927, 19928, 19933, 19934, 19935, 19936, 19937, 19941, 19946, 19947, 19952, 19957, 19958, 19959, 19963, 19965, 19966, 19967, 19968, 19969, 19971, 19974, 19976, 19989, 19991, 20007, 20008, 20012, 20013, 20014, 20016, 20023, 20028, 20036, 20043, 20045, 20050, 20051, 20052, 20054, 20186, 20196, 20203, 20225, 20230, 20236, 20237, 20240, 20264, 20279, 20339, 20341, 20342, 20358, 20366, 20370, 20372, 20373, 20380, 20382, 21886, 21883, 20415, 20422, 21872, 22046, 22045, 22019, 20613, 20619, 20636, 20640, 20644, 20648, 20655, 20677, 20678, 20679, 20680, 20688, 20691, 20725, 22040, 22038, 22029, 22110, 22111, 22109, 22106, 20923, 20931, 24214, 22090, 22091, 22094, 22095, 21019, 21020, 21072, 21073, 21076, 21080, 21095, 21099, 21102, 21104, 21105, 21110, 21125, 21134, 21198, 21190, 22086, 21210, 21238, 21248, 21249, 21250, 21314, 21334, 21337, 21363, 21368, 21373, 21673, 21374, 21385, 21386, 21397, 21403, 21407, 21416, 21419, 21424, 21426, 21445, 21447, 21457, 21468, 21476, 21478, 21505, 21510, 21531, 21674, 21544, 21545, 21546, 21547, 21548, 21549, 21550, 21551, 21552, 21553, 21554, 21555, 21556, 21557, 21558, 21559, 21560, 21561, 21562, 21564, 21565, 21566, 21567, 21568, 21569, 21570, 21573, 21574, 21575, 21576, 21577, 21578, 21579, 21580, 21581, 21582, 21583, 21584, 21585, 21586, 21587, 21588, 21589, 21590, 21591, 21592, 21593, 21594, 21595, 21596, 21597, 21598, 21599, 21600, 21601, 21602, 21603, 21604, 21605, 21606, 21607, 21608, 21609, 21610, 21611, 21612, 21613, 21615, 21619, 21620, 21621, 21622, 21623, 21624, 21625, 21626, 21627, 21628, 21629, 21630, 21631, 21632, 21633, 21634, 21635, 21636, 21637, 21638, 21639, 21640, 21641, 21642, 21643, 21644, 21645, 21646, 21647, 21648, 21649, 21650, 21651, 21652, 21653, 21654, 21655, 21656, 21657, 21660, 21661, 21662, 21663, 21664, 21665, 21666, 21667, 21668, 21669, 21670, 21671, 21676, 21677, 21688, 21690, 21692, 21693, 21694, 21695, 21696, 21697, 21698, 21699, 21700, 21701, 21703, 21704, 21707, 21714, 21718, 21719, 21720, 21721, 21722, 21730, 21733, 21737, 21739, 21740, 21743, 21746, 21748, 21755, 21757, 21761, 21804, 21767, 21818, 21766, 21768, 21769, 21770, 21772, 21774, 21775, 21783, 21784, 21785, 21786, 21787, 21788, 21789, 21790, 21792, 21796, 21798, 21815, 21819, 21825, 21836, 21837, 21845, 21954, 21855, 21891, 21895, 21904, 21918, 21925, 21926, 21928, 21947, 21951, 21959, 21960, 21971, 21972, 21997, 21999, 22002, 22014, 22048, 22049, 22050, 22051, 22054, 22056, 22058, 22061, 22067, 22068, 22076, 22081, 22133, 22146, 22163, 22166, 22169, 22178, 22179, 22389, 22183, 22191, 22194, 22227, 22230, 22233, 22259, 22260, 22264, 22265, 22266, 22271, 22272, 22274, 22275, 22277, 22282, 22283, 22292, 22296, 22301, 22307, 22317, 22323, 22334, 22335, 22341, 22368, 22364, 22367, 22371, 22375, 22377, 22782, 22401, 22406, 22414, 22415, 22419, 22479, 22480, 22481, 22497, 22498, 22499, 22515, 22526, 22538, 22539, 22540, 24033, 22563, 22565, 22566, 22567, 22568, 22569, 22570, 22571, 22575, 22577, 22721, 22581, 22585, 22586, 22587, 22591, 22592, 22594, 22595, 22607, 22608, 22624, 22613, 22618, 22620, 22621, 22625, 22629, 22637, 22638, 22639, 22643, 22644, 22664, 22650, 22651, 22662, 22665, 22675, 22706, 22716, 22720, 22722, 22726, 23813, 22740, 22748, 22749, 22750, 22760, 22762, 22765, 22766, 22767, 22771, 22772, 22773, 22774, 22775, 22777, 22778, 22779, 22784, 22785, 22786, 22788, 22789, 22796, 22797, 22800, 22801, 22803, 22824, 22846, 22839, 22836, 22837, 22842, 22848, 23089, 22868, 22876, 22879, 23102, 23047, 22899, 22913, 22914, 22929, 22931, 22940, 22941, 22942, 22950, 22951, 22954, 23340, 22969, 22974, 22978, 22989, 22990, 22993, 23000, 23001, 23003, 23004, 23006, 23007, 23016, 23017, 23020, 23023, 23024, 23025, 23026, 23029, 23031, 23033, 23034, 23036, 23037, 23038, 23040, 23046, 23061, 23244, 23078, 23079, 23091, 23332, 23107, 23109, 23112, 23217, 23115, 23133, 23139, 23144, 23143, 23168, 23175, 23177, 23179, 23180, 23181, 23184, 23185, 23186, 23195, 23196, 23198, 23199, 23200, 23201, 23202, 23204, 23206, 23207, 23210, 23211, 23212, 23213, 23214, 23215, 23221, 23225, 23228, 23234, 23235, 23237, 23238, 23248, 23249, 23256, 23272, 23277, 23280, 23281, 23282, 23317, 23318, 23320, 23326, 23328, 23352, 23354, 23356, 23364, 23368, 23369, 23372, 23376, 23377, 23378, 23379, 23381, 23384, 23388, 23390, 23391, 23392, 23393, 23394, 23399, 23400, 23403, 23404, 23407, 23408, 23410, 23412, 23414, 23415, 23416, 23417, 23418, 23454, 23455, 23460, 23466, 23467, 23469, 23470, 23471, 23473, 23483, 23488, 23498, 23500, 23505, 23510, 23523, 24083, 23527, 23532, 23533, 23534, 23535, 24170, 23537, 23563, 23614, 23622, 23623, 23624, 23625, 23626, 23627, 23633, 23635, 23637, 23638, 23640, 23641, 23653, 23644, 23648, 23651, 23652, 23660, 23661, 23665, 23666, 23670, 23673, 23678, 23685, 23686, 23739, 23742, 23745, 23746, 23753, 23768, 23769, 23788, 24194, 23792, 23795, 24260, 23800, 23807, 23809, 23811, 23815, 23816, 23818, 23819, 23820, 23823, 23824, 23830, 23836, 23837, 23838, 23839, 23840, 24039, 23857, 23845, 23849, 23851, 23854, 23861, 23862, 23863, 23864, 23867, 23966, 23892, 23906, 23907, 23932, 23934, 23936, 23937, 23941, 23948, 23949, 24221, 23955, 23960, 23980, 23982, 23983, 23986, 23987, 23988, 23990, 23992, 23993, 23994, 23996, 23997, 23999, 24002, 24003, 24032, 24021, 24007, 24008, 24009, 24010, 24011, 24012, 24013, 24015, 24016, 24024, 24028, 24034, 24040, 24160, 24046, 24047, 24127, 24050, 24052, 24053, 24054, 24055, 24056, 24057, 24062, 24063, 24071, 24079, 24085, 24086, 24162, 24099, 24113, 24278, 24114, 24119, 24289, 24121, 24122, 24123, 24124, 24125, 24126, 24131, 24141, 24142, 24143, 24145, 24148, 24150, 24151, 24156, 24157, 24158, 24159, 24161, 24163, 24165, 24239, 24166, 24167, 24169, 24349, 24171, 24174, 24175, 24176, 24184, 24195, 24196, 24197, 24220, 24223, 24224, 24225, 24226, 24227, 24232, 24233, 24235, 24236, 24238, 24240, 24241, 24245, 24246, 24251, 24257, 24262, 24263, 24265, 24266, 24267, 24273, 24268, 24274, 24277, 24279, 24280, 24283, 24284, 24285, 24288, 24290, 24292, 24294, 24295, 24296, 24297, 24298, 24299, 24302, 24303, 24315, 24316, 24325, 24327, 24329, 24330, 24332, 24336, 24337, 24339, 24340, 24341, 24342, 24343, 24344, 24345, 24346, 24347, 24355, 24350, 24351, 24352, 24353, 24354, 24357, 24359, 24360, 24361, 24362, 24363, 24364, 24365, 24369, 24370, 24371, 24375, 24372, 24373, 24384, 24376, 24377, 24378, 24379, 24380, 24381, 24382, 24383, 24385, 24386, 24387, 24388, 24389, 24390, 24391, 24392, 24393, 24394, 24398, 24395, 24397, 24404, 24403);
foreach ($active_projets_array as $nid) {
$i++;
$num_updated = db_update('og')
->fields(array(
'state' => 1,
))
->condition('etid', $nid)
->execute();
}
return $i . ' projects enabled';
}
function mnn_project_import_resave_batch_init() {
$batch = array(
'title' => t('Resaving Project 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_project_import_resave_batch_finished',
'progressive' => FALSE
);
//query all project nodes
$result = db_query('SELECT nid FROM {node} WHERE type = :type', array(':type' => 'cm_project'));
//$count = 0;
foreach ($result as $record) {
//if (!$count) {
$batch['operations'][] = array('mnn_project_import_resave_batch_worker', array($record->nid));
//$count++;
//}
}
batch_set($batch);
batch_process('admin/content');
}
function mnn_project_import_resave_batch_worker($nid, &$context) {
$node = node_load($nid);
//set og to legacy project id
//dsm($node);
node_save($node);
$context['results']['processed']++;
$context['message'] = 'Successfully imported Project #' . $array[0];
}
function mnn_project_resave_import_batch_finished($success, $results, $operations) {
if ($success) {
$message = format_plural($results['processed'], 'One Project processed.', '@count Projects processed.');
}
else {
$message = 'some errors';
}
drupal_set_message($message);
}