public function MigratePollEntityHandler::complete in Migrate 7.2
File
- plugins/
destinations/ poll.inc, line 84 - Support for poll nodes.
Class
- MigratePollEntityHandler
- @file Support for poll nodes.
Code
public function complete($entity, stdClass $row) {
if ($entity->type == 'poll') {
// Update settings overridden by !user_access('administer nodes') check in
// poll_insert().
db_update('poll')
->fields(array(
'active' => $entity->active,
))
->condition('nid', $entity->nid)
->execute();
// Update vote summary count, again overridden by
// !user_access('administer nodes') check in poll_insert().
foreach ($row->choice as $choice) {
// Have no mapping tracking for chid, so assume choice text is unique.
db_update('poll_choice')
->fields(array(
'chvotes' => $choice['chvotes'],
'weight' => $choice['weight'],
))
->condition('nid', $entity->nid)
->condition('chtext', $choice['chtext'])
->execute();
}
// Insert actual votes.
foreach ($row->votes as $vote) {
if (!isset($vote['chid'])) {
$result = db_select('poll_choice', 'pc')
->fields('pc', array(
'chid',
))
->condition('pc.nid', $entity->nid)
->condition('pc.chtext', $vote['chtext'])
->execute();
$chid = $result
->fetchField();
}
else {
$chid = $vote['chid'];
}
db_insert('poll_vote')
->fields(array(
'chid' => $chid,
'nid' => $entity->nid,
'uid' => $vote['uid'],
'hostname' => $vote['hostname'],
'timestamp' => $vote['timestamp'],
))
->execute();
}
}
}