View source
<?php
$plugin = array(
'name' => t('Group'),
'access callback' => 'og_migrate_7000_access',
'migrate callback' => 'og_migrate_og_migrate_upgrade_group',
);
function og_migrate_og_migrate_upgrade_group(&$context) {
if (empty($context['sandbox'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['last'] = 0;
$query = db_select('node_revision', 'nr');
$query
->innerJoin('node', 'n', 'n.vid = nr.vid');
$query
->innerJoin('d6_og', 'og', 'n.nid = og.nid');
$context['sandbox']['max'] = $query
->countQuery()
->execute()
->fetchField();
if (!$context['sandbox']['max']) {
$context['finished'] = 1;
return;
}
og_migrate_create_fields();
}
$batch_size = variable_get('og_batch_size', 200);
$query = db_select('node_revision', 'nr');
$query
->innerJoin('node', 'n', 'n.vid = nr.vid');
$query
->innerJoin('d6_og', 'og', 'n.nid = og.nid');
$query
->fields('nr', array(
'nid',
'vid',
))
->fields('n', array(
'type',
'created',
))
->fields('og', array(
'upgrade_id',
))
->condition('og.upgrade_id', $context['sandbox']['last'], '>')
->orderBy('og.upgrade_id', 'ASC')
->range(0, $batch_size);
$revisions = $query
->execute();
$nids = array();
foreach ($revisions as $revision) {
if (!og_get_group('node', $revision->nid)) {
$node = (object) array(
'nid' => $revision->nid,
'vid' => $revision->vid,
'type' => $revision->type,
);
if (empty($nids[$revision->nid]) || $nids[$revision->nid] > $revision->created) {
$nids[$revision->nid] = $revision->created;
}
$node->{OG_GROUP_FIELD}[LANGUAGE_NONE][0]['value'] = TRUE;
field_attach_update('node', $node);
}
$context['sandbox']['last'] = $revision->upgrade_id;
$context['sandbox']['progress']++;
}
if ($nids) {
foreach ($nids as $nid => $created) {
if (($group = og_get_group('node', $nid, TRUE)) && $group->created != $created) {
$group->created = $created;
$group
->save();
}
}
}
if ($context['sandbox']['progress'] < $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}