function oa_sections_node_update in Open Atrium Core 7.2
Implements hook_node_update().
File
- modules/
oa_sections/ oa_sections.module, line 50
Code
function oa_sections_node_update($node) {
// If the Section has been moved to a new Space, then we need to update all
// the content inside the Section to also be in the new Space.
if ($node->type == 'oa_section' && !empty($node->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE][0]['target_id'])) {
$original = $node->original;
$space_nid = $node->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE][0]['target_id'];
if (empty($original->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE][0]['target_id']) || $original->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE][0]['target_id'] != $space_nid) {
$child_nids = oa_core_get_section_content($node->nid);
// For 10 nodes or less, we update them inline (per Mike Potter).
if (count($child_nids) <= 10) {
foreach ($child_nids as $nid) {
_oa_sections_batch_change_space_operation($nid, $space_nid);
}
}
else {
// Create a batch operation to actually update the child nodes.
$batch = array(
'title' => t('Moving content to new Space'),
'operations' => array(),
);
foreach ($child_nids as $nid) {
$batch['operations'][] = array(
'_oa_sections_batch_change_space_operation',
array(
$nid,
$space_nid,
),
);
}
batch_set($batch);
}
}
}
}