/** * Import a single comment. */ static function import_comment(&$queue) { $messages = array(); if (count($queue) == 0) { //this case happens if more than one comment is found on one or more items $messages[] = t('Empty comments queue'); return $messages; } $element = array_shift($queue); list($item, $comments) = each($element); g1_import::debug(t('Now importing %$comments comment(s) for item %$item', array('album' => $item, 'comments' => count($comments)))); // Item names come in as FolderX/ItemX $pos = strrpos($item, '/'); if ($pos === false) { $messages[] = t('Invalid item %item', array('item' => $item)); return $messages; } // Get ItemX into g1_item $g1_item = substr($item, $pos + 1); // Get FolderX into g1_item $g1_album = substr($item, 0, $pos); if (self::map($g1_album, $g1_item, 'comment')) { return $messages; } $item_id = self::map($g1_album, $g1_item, 'item'); if (empty($item_id)) { $messages[] = t('Could not find item %item', array('item' => $item)); return; } foreach ($comments as $g1comment) { // Just import the fields we know about. Do this outside of the comment API for now so that // we don't trigger spam filtering events $comment = ORM::factory('comment'); $comment->author_id = identity::guest()->id; $comment->guest_name = utf8_encode(self::_decode_html_special_chars(trim($g1comment['name']))); $comment->guest_name or $comment->guest_name = (string) t('Anonymous coward'); $comment->guest_email = '*****@*****.**'; $comment->item_id = $item_id; $comment->text = utf8_encode(self::_decode_html_special_chars(trim($g1comment['commentText']))); $comment->state = 'published'; $comment->server_http_host = utf8_encode(self::_decode_html_special_chars(trim($g1comment['IPNumber']))); try { $comment->save(); } catch (Exception $e) { $messages[] = (string) new G1_Import_Exception(t('Failed to import comment for item: %item.', array('item' => $item)), $e); return $messages; } // Backdate the creation date. We can't do this at creation time because // Comment_Model::save() will override it. db::update('comments')->set('created', utf8_encode(self::_decode_html_special_chars(trim($g1comment['datePosted']))))->set('updated', utf8_encode(self::_decode_html_special_chars(trim($g1comment['datePosted']))))->where('id', '=', $comment->id)->execute(); } self::set_map($item_id, $g1_album, $g1_item, 'comment'); return $messages; }