View source
<?php
$plugin = array(
'name' => t('Group description'),
'access callback' => 'og_migrate_7000_access',
'migrate callback' => 'og_migrate_og_migrate_upgrade_group_description',
'dependencies' => array(
'upgrade_group',
),
);
function og_migrate_og_migrate_upgrade_group_description(&$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;
}
}
$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',
'og_description',
))
->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) {
$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;
}
if (!empty($revision->og_description)) {
$node->og_description[LANGUAGE_NONE][0]['value'] = $revision->og_description;
}
field_attach_update('node', $node);
$context['sandbox']['last'] = $revision->upgrade_id;
}
if ($nids) {
foreach ($nids as $nid => $created) {
$context['sandbox']['progress']++;
}
}
if ($context['sandbox']['progress'] < $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}