function _processLyftenBloggie($migrateComment) { $db = EasyBlogHelper::db(); $jSession = JFactory::getSession(); $ejax = new EJax(); $migrator = EB::migrator()->getAdapter('k2'); $migrateStat = $jSession->get('EBLOG_MIGRATOR_JOOMLA_STAT', '', 'EASYBLOG'); if (empty($migrateStat)) { $migrateStat = new stdClass(); $migrateStat->blog = 0; $migrateStat->category = 0; $migrateStat->comments = 0; $migrateStat->images = 0; $migrateStat->user = array(); } $query = 'SELECT * FROM `#__bloggies_entries` AS a'; $query .= ' WHERE NOT EXISTS ('; $query .= ' SELECT content_id FROM `#__easyblog_migrate_content` AS b WHERE b.`content_id` = a.`id` and `component` = ' . $db->Quote('com_lyftenbloggie'); $query .= ' )'; $query .= ' ORDER BY a.`id` LIMIT 1'; $db->setQuery($query); $row = $db->loadObject(); if (is_null($row)) { // now we migrate the remaining categories $this->_migrateLyftenCategories(); //at here, we check whether there are any records processed. if yes, //show the statistic. $ejax->append('progress-status3', JText::_('COM_EASYBLOG_MIGRATOR_FINISHED')); $ejax->script("divSrolltoBottomLyften();"); //update statistic $stat = '========================================== <br />'; $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_BLOGS') . ': ' . $migrateStat->blog . '<br />'; $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_COMMENTS') . ': ' . $migrateStat->comments . '<br />'; //$stat .= 'Total images migrated : ' . $migrateStat->images . '<br />'; $statUser = $migrateStat->user; if (!empty($statUser)) { $stat .= '<br />'; $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_USERS_CONTRIBUTIONS') . ': ' . count($statUser) . '<br />'; foreach ($statUser as $eachUser) { $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_BLOG_USER') . ' \'' . $eachUser->name . '\': ' . $eachUser->blogcount . '<br />'; } } $stat .= '<br />=========================================='; $ejax->assign('stat-status3', $stat); $ejax->script("\$( '#migrator-submit3' ).html('" . JText::_('COM_EASYBLOG_MIGRATOR_MIGRATION_COMPLETED') . "');"); $ejax->script("\$( '#migrator-submit3' ).attr('disabled' , '');"); $ejax->script("\$( '#icon-wait3' ).css( 'display' , 'none' );"); } else { // here we should process the migration // step 1 : create user if not exists in eblog_users - create user through profile jtable load method. // step 2: create categories / tags if needed. // step 3: migrate comments if needed. $date = EB::date(); $blogObj = new stdClass(); //default $blogObj->category_id = 1; //assume 1 is the uncategorized id. if (!empty($row->catid)) { $joomlaCat = $this->_getLyftenCategory($row->catid); $eCat = $this->_isEblogCategoryExists($joomlaCat); if ($eCat === false) { $eCat = $this->_createEblogCategory($joomlaCat); } $blogObj->category_id = $eCat; } //load user profile $profile = EB::user($row->created_by); $blog = EB::table('Blog'); //assigning blog data $blogObj->created_by = $profile->id; $blogObj->created = !empty($row->created) ? $row->created : $date->toMySQL(); $blogObj->modified = !empty($row->modified) ? $row->modified : $date->toMySQL(); $blogObj->title = $row->title; $blogObj->permalink = EasyBlogHelper::getPermalink($row->title); if (empty($row->fulltext)) { $blogObj->intro = ''; $blogObj->content = $row->introtext; } else { $blogObj->intro = $row->introtext; $blogObj->content = $row->fulltext; } $blogObj->published = $row->state == '1' ? '1' : '0'; // set to unpublish for now. $blogObj->publish_up = !empty($row->created) ? $row->created : $date->toMySQL(); $blogObj->publish_down = '0000-00-00 00:00:00'; $blogObj->hits = $row->hits; $blogObj->frontpage = 1; $blogObj->allowcomment = 1; $blogObj->subscription = 1; $blog->bind($blogObj); $blog->store(); //add meta description $migrator->migrateContentMeta($row->metakey, $row->metadesc, $blog->id); //step 2: tags $query = 'insert into `#__easyblog_post_tag` (`tag_id`, `post_id`, `created`)'; $query .= ' select a.`id`, ' . $db->Quote($blog->id) . ', ' . $db->Quote($date->toMySQL()); $query .= ' from `#__easyblog_tag` as a inner join `#__bloggies_tags` as b'; $query .= ' on a.`title` = b.`name`'; $query .= ' inner join `#__bloggies_relations` as c on b.`id` = c.`tag`'; $query .= ' where c.`entry` = ' . $db->Quote($row->id); $db->setQuery($query); $db->query(); // migrate Jcomments from lyftenbloggie into EasyBlog // $this->_migrateJCommentIntoEasyBlog($row->id, $blog->id, 'com_lyftenbloggie'); // step 3 if ($migrateComment) { //required frontend model file. require_once JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'comment.php'; $model = new EasyBlogModelComment(); $queryComment = 'SELECT * FROM `#__bloggies_comments` WHERE `entry_id` = ' . $db->Quote($row->id); $queryComment .= ' ORDER BY `id`'; $db->setQuery($queryComment); $resultComment = $db->loadObjectList(); if (count($resultComment) > 0) { $lft = 1; $rgt = 2; foreach ($resultComment as $itemComment) { $now = EB::date(); $commt = EB::table('Comment'); $commt->post_id = $blog->id; $commt->comment = $itemComment->content; $commt->title = ''; $commt->name = $itemComment->author; $commt->email = $itemComment->author_email; $commt->url = $itemComment->author_url; $commt->created_by = $itemComment->user_id; $commt->created = $itemComment->date; $commt->published = $itemComment->state == '1' ? '1' : '0'; $commt->lft = $lft; $commt->rgt = $rgt; $commt->store(); //update state $migrateStat->comments++; // next set of siblings $lft = $rgt + 1; $rgt = $lft + 1; } //end foreach } //end if count(comment) } //update session value $migrateStat->blog++; $statUser = $migrateStat->user; $statUserObj = null; if (!isset($statUser[$profile->id])) { $statUserObj = new stdClass(); $statUserObj->name = $profile->nickname; $statUserObj->blogcount = 0; } else { $statUserObj = $statUser[$profile->id]; } $statUserObj->blogcount++; $statUser[$profile->id] = $statUserObj; $migrateStat->user = $statUser; $jSession->set('EBLOG_MIGRATOR_JOOMLA_STAT', $migrateStat, 'EASYBLOG'); //log the entry into migrate table. $migrator = EB::table('Migrate'); $migrator->content_id = $row->id; $migrator->post_id = $blog->id; $migrator->session_id = $jSession->getToken(); $migrator->component = 'com_lyftenbloggie'; $migrator->store(); $ejax->append('progress-status3', JText::_('COM_EASYBLOG_MIGRATOR_MIGRATED_LYFTEN') . ':' . $row->id . JText::_('COM_EASYBLOG_MIGRATOR_EASYBLOG') . ': ' . $blog->id . '<br />'); $ejax->script("ejax.load('migrators','_processLyftenBloggie', '{$migrateComment}');"); } //end if else isnull $ejax->send(); }
function _process($authorId, $stateId, $catId, $sectionId, $myblogSection, $jomcomment = false) { $db = EasyBlogHelper::db(); $jSession = JFactory::getSession(); $ejax = new EJax(); $migrateStat = $jSession->get('EBLOG_MIGRATOR_JOOMLA_STAT', '', 'EASYBLOG'); if (empty($migrateStat)) { $migrateStat = new stdClass(); $migrateStat->blog = 0; $migrateStat->category = 0; $migrateStat->user = array(); } $query = 'SELECT * FROM `#__content` AS a'; $query .= ' WHERE NOT EXISTS ('; $query .= ' SELECT content_id FROM `#__easyblog_migrate_content` AS b WHERE b.`content_id` = a.`id` and `component` = ' . $db->Quote('com_content'); $query .= ' )'; if ($authorId != '0') { $query .= ' AND a.`created_by` = ' . $db->Quote($authorId); } if ($stateId != '*') { switch ($stateId) { case 'P': $query .= ' AND a.`state` = ' . $db->Quote('1'); break; case 'U': $query .= ' AND a.`state` = ' . $db->Quote('0'); break; case 'A': $query .= ' AND a.`state` = ' . $db->Quote('-1'); break; // joomla 1.6 compatibility // joomla 1.6 compatibility case '1': // publish $query .= ' AND a.`state` = ' . $db->Quote('1'); break; case '0': //unpublish $query .= ' AND a.`state` = ' . $db->Quote('0'); break; case '2': // archive $query .= ' AND a.`state` = ' . $db->Quote('2'); break; case '-2': // trash $query .= ' AND a.`state` = ' . $db->Quote('-2'); break; default: break; } } if ($sectionId != '-1') { $query .= ' AND a.`sectionid` = ' . $db->Quote($sectionId); } // we do not want the myblog post process here. if ($myblogSection != '') { $query .= ' AND a.`sectionid` != ' . $db->Quote($myblogSection); } if ($catId != '0') { $query .= ' AND a.`catid` = ' . $db->Quote($catId); } $query .= ' ORDER BY a.`id` LIMIT 1'; $db->setQuery($query); $row = $db->loadObject(); if (is_null($row)) { //at here, we check whether there are any records processed. if yes, //show the statistic. $ejax->append('progress-status', JText::_('COM_EASYBLOG_MIGRATOR_FINISHED')); $ejax->script("divSrolltoBottom();"); //update statistic $stat = '========================================== <br />'; $stat .= JText::_('COM_EASYBLOG_MIGRATOR_JOOMLA_TOTAL_ARTICLE') . ' : ' . $migrateStat->blog . '<br />'; $stat .= JText::_('COM_EASYBLOG_MIGRATOR_JOOMLA_TOTAL_CATEGORY') . ' : ' . $migrateStat->category . '<br />'; $statUser = $migrateStat->user; if (!empty($statUser)) { $stat .= '<br />'; $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_USER_CONTRIBUTIONS') . ' : ' . count($statUser) . '<br />'; foreach ($statUser as $eachUser) { $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_ARTICLES_USER') . ' \'' . $eachUser->name . '\': ' . $eachUser->blogcount . '<br />'; } } $stat .= '<br />=========================================='; $ejax->assign('stat-status', $stat); $ejax->script("\$( '#migrator-submit' ).html('" . JText::_('COM_EASYBLOG_MIGRATOR_MIGRATION_COMPLETED') . "');"); $ejax->script("\$( '#migrator-submit' ).attr('disabled' , '');"); $ejax->script("\$( '#icon-wait' ).css( 'display' , 'none' );"); } else { // here we should process the migration // step 1 : create categery if not exist in eblog_categories // step 2 : create user if not exists in eblog_users - create user through profile jtable load method. $date = EB::date(); $blogObj = new stdClass(); //default $blogObj->category_id = 1; //assume 1 is the uncategorized id. if (!empty($row->catid)) { $joomlaCat = $this->_getJoomlaCategory($row->catid); $eCat = $this->_isEblogCategoryExists($joomlaCat); if ($eCat === false) { $eCat = $this->_createEblogCategory($joomlaCat); } $blogObj->category_id = $eCat; } //load user profile $profile = EB::user($row->created_by); $blog = EB::table('Blog'); //assigning blog data $blogObj->created_by = $profile->id; $blogObj->created = !empty($row->created) ? $row->created : $date->toMySQL(); $blogObj->modified = $date->toMySQL(); $blogObj->title = $row->title; $blogObj->permalink = $row->alias; // Need to remap the access. $access = 0; if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { switch ($row->access) { case 1: $access = 0; break; default: $access = 1; break; } } else { $access = $row->access == 2 ? 1 : $row->access; } $blogObj->access = $access; if (empty($row->fulltext)) { $blogObj->intro = ''; $blogObj->content = $row->introtext; } else { $blogObj->intro = $row->introtext; $blogObj->content = $row->fulltext; } // joomla 3.0 intro imag properties. if (isset($row->images) && !empty($row->images)) { $joomlaImages = json_decode($row->images); if (isset($joomlaImages->image_intro) and !empty($joomlaImages->image_intro)) { $imgTag = '<img'; if ($joomlaImages->image_intro_caption) { $imgTag .= ' class="caption" title="' . htmlspecialchars($joomlaImages->image_intro_caption) . '"'; } $imgTag .= ' src="' . htmlspecialchars($joomlaImages->image_intro) . '" alt="' . htmlspecialchars($joomlaImages->image_intro_alt) . '"/>'; $blogObj->intro = $imgTag . $blogObj->intro; } if (isset($joomlaImages->image_fulltext) and !empty($joomlaImages->image_fulltext)) { $imgTag = '<img'; if ($joomlaImages->image_fulltext_caption) { $imgTag .= ' class="caption" title="' . htmlspecialchars($joomlaImages->image_fulltext_caption) . '"'; } $imgTag .= ' src="' . htmlspecialchars($joomlaImages->image_fulltext) . '" alt="' . htmlspecialchars($joomlaImages->image_fulltext_alt) . '"/>'; $blogObj->content = $imgTag . $blogObj->content; } } //translating the article state into easyblog publish status. $blogState = ''; if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { $blogState = $row->state == 2 || $row->state == -2 ? 0 : $row->state; } else { $blogState = $row->state == -1 ? 0 : $row->state; } $blogObj->published = $blogState; $blogObj->publish_up = !empty($row->publish_up) ? $row->publish_up : $date->toMySQL(); $blogObj->publish_down = !empty($row->publish_down) ? $row->publish_down : $date->toMySQL(); $blogObj->ordering = $row->ordering; $blogObj->hits = $row->hits; $blogObj->frontpage = 1; $blog->bind($blogObj); $blog->store(); // Run jomcomment migration here. if ($jomcomment) { $this->migrateJomcomment($row->id, $blog->id, 'com_content'); } //migrate meta description $this->_migrateContentMeta($row->metakey, $row->metadesc, $blog->id); if ($row->featured) { // just call the model file will do as we do not want to create stream on featured action at this migration. $modelF = EB::model('Featured'); $modelF->makeFeatured('post', $blog->id); } //update session value $migrateStat->blog++; $statUser = $migrateStat->user; $statUserObj = null; if (!isset($statUser[$profile->id])) { $statUserObj = new stdClass(); $statUserObj->name = $profile->nickname; $statUserObj->blogcount = 0; } else { $statUserObj = $statUser[$profile->id]; } $statUserObj->blogcount++; $statUser[$profile->id] = $statUserObj; $migrateStat->user = $statUser; $jSession->set('EBLOG_MIGRATOR_JOOMLA_STAT', $migrateStat, 'EASYBLOG'); //log the entry into migrate table. $migrator = EB::table('Migrate'); $migrator->content_id = $row->id; $migrator->post_id = $blog->id; $migrator->session_id = $jSession->getToken(); $migrator->component = 'com_content'; $migrator->store(); $ejax->append('progress-status', JText::_('COM_EASYBLOG_MIGRATOR_MIGRATED_JOOMLA_ARTICLE') . ': ' . $row->id . JText::_('COM_EASYBLOG_MIGRATOR_EASYBLOG') . ': ' . $blog->id . '<br />'); $ejax->script("ejax.load('migrators','_process','{$authorId}', '{$stateId}', '{$catId}', '{$sectionId}', '{$myblogSection}','{$jomcomment}');"); } $ejax->send(); }