Skip to content

Commit

Permalink
Update Nc2ToNc3Bbs.php
Browse files Browse the repository at this point in the history
fix: 掲示板、1個も配置されてなくても移行する
  • Loading branch information
akagane99 committed Dec 28, 2018
1 parent a1a6319 commit b35e8bf
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions Model/Nc2ToNc3Bbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,33 @@ private function __saveNc3BbsFromNc2($nc2Bbses) {
$Block = ClassRegistry::init('Blocks.Block');
$Topic = ClassRegistry::init('Topics.Topic');

/* @see Nc2ToNc3Map::getMapIdList() */
$Nc2ToNc3Map = ClassRegistry::init('Nc2ToNc3.Nc2ToNc3Map');
$mapRoomIdList = $Nc2ToNc3Map->getMapIdList('Room');

foreach ($nc2Bbses as $nc2Bbs) {
//var_dump($nc2Bbs);exit;
/** @var array $nc2BbsBlock */
$nc2BbsBlock = $Nc2BbsBlock->findByBbsId($nc2Bbs['Nc2Bb']['bbs_id'], null, null, -1);
if (!$nc2BbsBlock) {
continue;
}
// nc2配置してなくても移行する
//if (!$nc2BbsBlock) {
// continue;
//}
$Bbs->begin();
try {
$data = $this->generateNc3BbsData($nc2Bbs, $nc2BbsBlock);
$nc2RoomId = $nc2Bbs['Nc2Bb']['room_id'];
// nc3 room_id取得
if (! isset($mapRoomIdList[$nc2RoomId])) {
// 基本ありえない想定
$message = __d('nc2_to_nc3', '%s No room ID corresponding to nc3',
'nc2_room_id:' . $nc2RoomId);
$this->writeMigrationLog($message);
$Bbs->rollback();
continue;
}
$nc3RoomId = $mapRoomIdList[$nc2RoomId];

$data = $this->generateNc3BbsData($nc2Bbs, $nc2BbsBlock, $nc3RoomId);
if (!$data) {
$Bbs->rollback();
continue;
Expand Down Expand Up @@ -227,7 +244,6 @@ private function __saveNc3BbsArticleFromNc2($nc2BbsPosts) {
continue;
}

$Block = ClassRegistry::init('Blocks.Block');
$Blocks = $Block->findById($data['Block']['id'], null, null, -1);
$nc3RoomId = $Blocks['Block']['room_id'];

Expand All @@ -249,8 +265,6 @@ private function __saveNc3BbsArticleFromNc2($nc2BbsPosts) {
$BbsArticle->validate = [];
$BbsArticleTree->validate = [];

//error_log(print_r('dddddddddddddddddddddddddddddddddddd', true)."\n\n", 3, LOGS."/debug.log");

if (!$BbsArticle->saveBbsArticle($data)) {
// 各プラグインのsave○○にてvalidation error発生時falseが返ってくるがrollbackしていないので、
// ここでrollback
Expand Down Expand Up @@ -365,4 +379,4 @@ private function __saveNc3BbsFrameSettingFromNc2($nc2BbsBlocks) {
return true;
}

}
}

0 comments on commit b35e8bf

Please sign in to comment.