public static function import() { // include required modules if (!CModule::IncludeModule('forum')) { return false; } $moduleId = 'prmedia.treelikecomments'; // retrieve or init session storage $sessionStorage = $_SESSION['tlc_import']; if ($_REQUEST['start'] == 'Y') { // get total count of comments $rsMessage = CForumMessage::GetList(); $rsMessage->NavStart(); $totalCount = $rsMessage->NavRecordCount; $sessionStorage = array( 'processing_time' => time(), 'current_count' => 0, 'actual_count' => 0, 'total_count' => $totalCount, 'comment_id' => 1, 'allow_smiles' => COption::GetOptionString($moduleId, 'smiles_enable') == 1 ? true : false, 'allow_bb' => COption::GetOptionString($moduleId, 'bb_code_enable') == 1 ? true : false ); } // import comments... $obComment = new CTreelikeComments; $is_finish = true; $currentTime = time(); $arOrder = array( 'ID' => 'ASC' ); $arFilter = array( '>ID' => $sessionStorage['comment_id'] ); $rsMessage = CForumMessage::GetList($arOrder, $arFilter); while ($arMessage = $rsMessage->Fetch()) { $is_finish = false; $sessionStorage['current_count']++; $sessionStorage['comment_id'] = $arMessage['ID']; $comment = $arMessage['POST_MESSAGE']; if ($sessionStorage['allow_smiles']) { $comment = CTreelikeForumImporter::setSmiles($comment); } if ($sessionStorage['allow_bb']) { $comment = CTreelikeForumImporter::setBB($comment); } $arFields = array( 'REMOTE_ADDR' => $arMessage['AUTHOR_REAL_IP'], 'AUTHOR_NAME' => $arMessage['AUTHOR_NAME'], 'USER_ID' => $arMessage['AUTHOR_ID'], 'OBJECT_ID' => $arMessage['PARAM2'], 'COMMENT' => $comment, 'DATE' => CDatabase::FormatDate($arMessage['POST_DATE'], "DD.MM.YYYY HH:MI:SS", "YYYY-MM-DD HH:MI:SS"), 'ACTIVATED' => $arMessage['APPROVED'] == 'Y' ? 1 : 0 ); // counter if (!empty($arFields['USER_ID'])) { $elementId = $obComment->Add($arFields); if (!empty($elementId)) { if (empty($sessionStorage['first_element'])) { $sessionStorage['first_element'] = $elementId; } $sessionStorage['actual_count']++; CTreelikeForumImporter::addImportedComment($elementId); } } // one step is one second if ($currentTime != time()) { break; } } if ($is_finish) { // go to finish step echo '<script>document.getElementsByClassName("wizard-next-button")[0].click();</script>'; CTreelikeForumImporter::clearCache(); return; } // progress message $text = GetMessage('PRMEDIA_WIZARDS_IMPORT_FORUM_PROGRESS_MESSAGE'); $arReplace = array( "#IMPORTED#" => $sessionStorage['current_count'], "#COUNT#" => $sessionStorage['total_count'], "#TIME#" => gmdate("i:s", time() - $sessionStorage['processing_time']) ); $progressMessage = str_replace(array_keys($arReplace), $arReplace, $text); CAdminMessage::ShowMessage(array( "TYPE" => "PROGRESS", "MESSAGE" => GetMessage('PRMEDIA_SS_DIST_PROGRESS_TITLE'), "DETAILS" => $progressMessage, "HTML" => true, "PROGRESS_VALUE" => $sessionStorage['current_count'], "PROGRESS_TOTAL" => $sessionStorage['total_count'] )); echo "<script>jsPrmediaCommentImporter.update();</script>"; $_SESSION['tlc_import'] = $sessionStorage; }
} } } if($ex = $APPLICATION->GetException()) { $arResult['ERRORS'][] = $ex->GetString(); } else { $arResult['ERRORS'][] = GetMessage('UNKNOWN_ERROR'); } } else { if ($NEW_ID = $comment->Add($arComment)) { $NEW_ID = intval($NEW_ID); $_SESSION['COMMENTS']['ADD'] = 'Y'; if ($arParams['CACHE_TYPE'] == "N") { SetCookie("saveName", $arPreparedFields['AUTHOR_NAME'], time() + 15552000, "/"); $_COOKIE['saveName'] = $arPreparedFields['AUTHOR_NAME']; } // Set default values of emails $to_Mail_answer = "N"; $to_Mail_like = "N"; $to_Mail_admin = "N";