• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

My importer shows 0 items after

Kirk

Well-known member
#1
Hi all so I've created an importer to import usernotes. Currently the importer will import items but it shows a 0 items imported after i click the button. I've checked on my local wamp server and it shows the items actually imported even though the import button said 0 items imported.

Here's my importer code

PHP:
<?php

class ElUsernotes_Importer_vBulletin extends XFCP_ElUsernotes_Importer_vBulletin
{


    public function getSteps() {
        $steps = parent::getSteps();

        $steps = array_merge($steps,array(
            'usernotes' => array(
                'title' => 'Import Usernotes',
                'depends' => array('users')
            )
        ));

        return $steps;
    }

    public function stepUsernotes($start, array $options)
    {
        $options = array_merge(array(
            'limit' => 200,
            'max' => false
        ), $options);

        $sDb = $this->_sourceDb;
        $prefix = $this->_prefix;

        /* @var $model XenForo_Model_Import */
        $model = $this->_importModel;

        if ($options['max'] === false)
        {
            $options['max'] = $sDb->fetchOne('
                SELECT MAX(usernoteid)
                FROM ' . $prefix . 'usernote
            ');
        }

        $vms = $sDb->fetchAll($sDb->limit(
            '
                SELECT usernote.*
                FROM ' . $prefix . 'usernote AS usernote
                WHERE usernote.usernoteid > ' . $sDb->quote($start) . '
                ORDER BY usernote.usernoteid
            ', $options['limit']
        ));
        if (!$vms)
        {
            return true;
        }

        $next = 0;
        $total = 0;

        $userIds = array();
        foreach ($vms AS $vm)
        {
            $userIds[] = $vm['userid'];
            $userIds[] = $vm['posterid'];
        }
        $userIdMap = $model->getImportContentMap('user', $userIds);

        XenForo_Db::beginTransaction();

        $formatter = XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_Text');
        $parser = new XenForo_BbCode_Parser($formatter);

        foreach ($vms AS $vm)
        {
            $next = $vm['usernoteid'];

            $profileUserId = $this->_mapLookUp($userIdMap, $vm['userid']);
            if (!$profileUserId)
            {
                continue;
            }

            $postUserId = $this->_mapLookUp($userIdMap, $vm['posterid'], 0);

            $info = array(
                'profile_user_id'   =>  $profileUserId,
                'user_id' =>  $postUserId,
                'message'   =>  $parser->render($this->_convertToUtf8($vm['message'])),
                'post_date' =>  $vm['dateline']
            );



            $vm = $this->_importModel->importUserNote($next, $info);
            if ($vm){
                $total++;
            }
        }

        XenForo_Db::commit();
        $this->_session->incrementStepImportTotal($total);
        return array($next, $options, $this->_getProgressOutput($next, $options['max']));
    }

    public function importUserNote($oldId, $info)
    {
        $profilePostId = $this->_importData($oldId, 'ElUsernotes_DataWriter_DiscussionMessage_Usernote', 'userNote', 'note_id', $info);
        if ($profilePostId) {
            return $profilePostId;
        }
    }
}