global $USER;
if( !$USER->IsAdmin() ) die('Недостаточно прав для запуска');
$userID = $USER->GetID();
$forumId = isset($_POST['FORUM_ID']) ? $_POST['FORUM_ID'] : false;
$blogId = isset($_POST['BLOG_ID']) ? $_POST['BLOG_ID'] : false;
$bOnlyIPComments = isset($_POST['ONLY_IP']);
$userIP = \Bitrix\Main\Service\GeoIp\Manager::getRealIp();
?>
Для форума '.$forumId.' и блога '.$blogId.' отзывы уже перенесены ('.$converted['count'].').
';
die();
}
}
}
if(!CModule::IncludeModule('forum')) {
echo 'Не установлен модуль Форум!';
die();
}
if(!CModule::IncludeModule('blog')) {
echo 'Не установлен модуль Блог!';
die();
}
if(!CModule::IncludeModule('iblock')) {
echo 'Не установлен модуль Информационные блоки!';
die();
}
?>
// Кол-во комментариев без IP адреса
$iCommentsWithoutIP = $iCommentsWithoutIPAdded = 0;
$resForumTopics = CForumTopic::GetList(array("ID"=>"ASC"), array('FORUM_ID' => $forumId));
while( $forumTopic = $resForumTopics->Fetch() ) {
$productId = explode('_', $forumTopic['XML_ID'])[1];
$userStartID = CUser::GetByID($forumTopic['USER_START_ID'])->SelectedRowsCount() > 0 ? $forumTopic['USER_START_ID'] : $userID;
$arForumTopics[$forumTopic['ID']] = array(
'ID' => $forumTopic['ID'],
'TITLE' => $forumTopic['TITLE'],
'PRODUCT_ID' => $productId,
'USER_START_ID' => $userStartID,
'START_DATE' => $forumTopic['START_DATE'],
);
$arProductsIds[] = $productId;
}
if($arForumTopics) {
$resForums = CForumMessage::GetList(array("ID"=>"ASC"), array('FORUM_ID' => $forumId));
$bForumExist = false;
while( $forum = $resForums->Fetch() ) {
// Проверка на IP
if( !$bOnlyIPComments && !$forum['AUTHOR_IP'] ){
$forum['AUTHOR_IP'] = $userIP;
$iCommentsWithoutIP++;
$iCommentsWithoutIPAdded++;
}
if( !$bOnlyIPComments && !$forum['AUTHOR_REAL_IP'] ){
$forum['AUTHOR_REAL_IP'] = $userIP;
}
if( isset($arForumTopics[$forum['TOPIC_ID']]) && $forum['AUTHOR_IP'] ) {
$authorID = CUser::GetByID($forum['AUTHOR_ID'])->SelectedRowsCount() > 0 ? $forum['AUTHOR_ID'] : $userID;
$arForumTopics[$forum['TOPIC_ID']]['ITEMS'][$forum['ID']] = array(
'ID' => $forum['ID'],
'AUTHOR_ID' => $authorID,
'AUTHOR_NAME' => $forum['AUTHOR_NAME'],
'AUTHOR_EMAIL' => $forum['AUTHOR_EMAIL'],
'AUTHOR_IP' => $forum['AUTHOR_IP'],
'AUTHOR_IP1' => $forum['AUTHOR_REAL_IP'],
'DATE_CREATE' => $forum['POST_DATE'],
'POST_TEXT' => $forum['POST_MESSAGE'],
);
$bForumExist = true;
}else{
if( !$forum['AUTHOR_IP'] ) $iCommentsWithoutIP++;
}
}
if(!$bForumExist) {
echo 'Нет сообщений форума для переноса. Либо ни в одном не указан автор.';
die();
}
} else {
echo 'Нет доступных тем на форуме.';
die();
}
if($arProductsIds) {
$resProducts = CIBlockElement::GetList(array(), array('ID' => $arProductsIds), false, false, array('DETAIL_PAGE_URL', 'PREVIEW_TEXT'));
while( $product = $resProducts->GetNext() ) {
$arProducts[$product['ID']] = $product;
}
if(!$arProducts) {
echo 'Нет товаров, связанных с темами форума.';
die();
}
}
$blogUrl = CBlog::GetByID($blogId)['URL'];
foreach($arForumTopics as $topicId => $topic) {
$detailText = '[URL='.$_SERVER['HTTP_ORIGIN'].$arProducts[$topic['PRODUCT_ID']]['DETAIL_PAGE_URL'].']'.$topic['TITLE'].'[/URL]'.PHP_EOL.$arProducts[$topic['PRODUCT_ID']]['PREVIEW_TEXT'].PHP_EOL;
$fields = array(
'TITLE' => $topic['TITLE'],
'BLOG_ID' => $blogId,
'AUTHOR_ID' => $topic['USER_START_ID'],
'DETAIL_TEXT' => $detailText,
'DATE_CREATE' => $topic['START_DATE'],
'DATE_PUBLISH' => $topic['START_DATE'],
'PUBLISH_STATUS' => 'P',
);
$postId = CBlogPost::Add($fields);
if($postId) {
CIBlockElement::SetPropertyValuesEx( $topic['PRODUCT_ID'], $arProducts[$topic['PRODUCT_ID']]['IBLOCK_ID'], array('BLOG_POST_ID' => $postId) );
$arForumTopics[$topicId]['POST_ID'] = $postId;
if($topic['ITEMS']) {
foreach($arForumTopics[$topicId]['ITEMS'] as $commentId => $comment) {
$fields = array(
'BLOG_ID' => $blogId,
'POST_ID' => $postId,
'AUTHOR_IP' => $comment['AUTHOR_IP'],
'AUTHOR_IP1' => $comment['AUTHOR_IP1'],
'DATE_CREATE' => $comment['DATE_CREATE'],
'POST_TEXT' => ''.$comment['POST_TEXT'].'',
'PATH' => $_SERVER['HTTP_ORIGIN'].$arProducts[$topic['PRODUCT_ID']]['DETAIL_PAGE_URL'].'?commentId=#comment_id###comment_id#',
'URL' => $blogUrl,
);
if($comment['AUTHOR_ID'] && $comment['AUTHOR_ID'] !== $userID && CUser::GetByID($comment['AUTHOR_ID'])->SelectedRowsCount() > 0 ) {
$fields['AUTHOR_ID'] = $comment['AUTHOR_ID'];
} else {
if($comment['AUTHOR_NAME']) {
$fields['AUTHOR_NAME'] = $comment['AUTHOR_NAME'];
}
if($comment['AUTHOR_EMAIL']) {
$fields['AUTHOR_EMAIL'] = $comment['AUTHOR_EMAIL'];
}
}
$newCommentFields[] = $fields;
$newCommentId[] = CBlogComment::Add($fields);
if ($ex = $GLOBALS['APPLICATION']->GetException())
echo 'Сообщение блога '.$topic['TITLE'].' : '.$comment['POST_TEXT'].' не было добавлено, '.$ex->GetString().'
';
}
}
} else {
if ($ex = $GLOBALS['APPLICATION']->GetException())
echo 'Тема блога '.$topic['TITLE'].' не была добавлена, '.$ex->GetString().'
';
}
}
$_SESSION['NEW_REVIEWS_CONVERTED'][$forumId.'_'.$blogId] = array(
'forum' => $forumId,
'blog' => $blogId,
'count' => count($newCommentId),
);
if($newCommentId):?>
0 ): ?>
Отзывов без IP адреса оставлено: = $iCommentsWithoutIP; ?>
0 ): ?>
Отзывов без IP адреса перенесено: = $iCommentsWithoutIPAdded; ?>
Успешно! Перенесено отзывов: =count($newCommentId)?>.
Не забудьте удалить файл BlogsCreater.php!