Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

コミュニティルームに配置した施設予約、登録できない #1546

Closed
akagane99 opened this issue Dec 12, 2019 · 2 comments
Closed

Comments

@akagane99
Copy link
Contributor

akagane99 commented Dec 12, 2019

NC3.3.0で確認しました。

コミュニティルームに配置した施設予約で施設予約すると「申し訳ありませんが、予約の登録・編集は画面に正しく設置された施設予約から行ってください。」となり、登録できなくなりました。

image

調査

調査したところ、ReservationPlansController::add()のCurrent::read('Frame.id')がNULLになり、上記can_not_editのviewに飛ばされてました。
https://github.com/NetCommons3/Reservations/blob/3.3.0.1/Controller/ReservationPlansController.php#L289-L291

/**
 * add
 *
 * @return void
 */
	public function add() {
		// 施設情報
		$locations = $this->ReservationLocation->getReservableLocations();
		$this->set('locations', $locations);
		$frameId = Current::read('Frame.id');      // NULL
		if (! $frameId) {
			$this->setAction('can_not_edit');    // ここで「申し訳ありませんが、予約の登録・編集は画面に正しく設置された施設予約から行ってください。」ページに飛ばされる
			return;
		}

報告まで。

@akagane99
Copy link
Contributor Author

調査2

調査したところ、CurrentのフレームIDのセット時にblockとframeのroom_idがずれて、フレームがNULLで帰ってきてました。

https://github.com/NetCommons3/NetCommons/blob/3.3.0.1/Lib/Current/CurrentLibFrame.php#L148

/**
 * フレームIDの取得
 *
 * @return string|null フレームID。nullの場合、パラメータ等からframe_idが取得できなかった
 */
	public function getCurrentFrameId() {
		$frameId = $this->__getFrameIdInRequest();
		if (! $frameId) {
			return null;
		}
		$frame = $this->findFrameById($frameId);
		if (! $frame) {
			return null;
		}
		if ($frame['Frame']['block_id'] &&
				$this->CurrentLibBlock->isBlockIdInRequest()) {
			$blockId = $this->CurrentLibBlock->getCurrentBlockId();
			$block = $this->CurrentLibBlock->findBlockById($blockId);
			//指定されたブロックとフレームのブロックについて、
			//ルームIDとプラグインキーが同じかチェックする
			if (! $this->isSameRoomAndPluginByRequestBlockAndFrameBlock($frame, $block)) {
				return null;     // ←ここでnullになり、Frame.idがCurrentで取れなくなっていた。
			}
		}
		return $frame['Frame']['id'];
	}

$this->isSameRoomAndPluginByRequestBlockAndFrameBlock($frame, $block)

https://github.com/NetCommons3/NetCommons/blob/3.3.0.1/Lib/Current/CurrentLibFrame.php#L410

/**
 * リクエストのBlockとFrameのBlockが同じプラグインと同じルームかどうかチェックする。
 *
 * @param array $frame フレームデータ
 * @param array $block ブロックデータ
 * @return bool
 */
	public function isSameRoomAndPluginByRequestBlockAndFrameBlock($frame, $block) {
		if (isset($block['Block']['room_id']) &&
				($block['Block']['room_id'] !== $frame['Frame']['room_id'] ||
				$block['Block']['plugin_key'] !== $frame['Frame']['plugin_key'])) {
			return false;
		} else {
			return true;
		}
	}

$this->isSameRoomAndPluginByRequestBlockAndFrameBlock($frame, $block)の$frame, $blockのdebug

2019-12-12 10:59:07 Debug: [CurrentLibFrame::getCurrentFrameId] /srv/public_html/nc3default.opensource-workshop.jp/app/Plugin/NetCommons/Lib/Current/CurrentLibFrame.php (line 150)
2019-12-12 10:59:07 Debug: array (
  'Frame' => 
  array (
    'id' => '407',
    'room_id' => '8',      // blockと違う
    'box_id' => '3254',
    'plugin_key' => 'reservations',      // blockと同じ
    'block_id' => '5',
    'key' => '1cc3be309b1d916ce0f3c164acb57ce7',
    'header_type' => 'default',
    'weight' => '1',
    'is_deleted' => false,
    'default_action' => '',
    'default_setting_action' => '',
  ),
  'FramePublicLanguage' => 
  array (
    'id' => '405',
    'language_id' => '0',
    'frame_id' => '407',
    'is_public' => true,
  ),
  'FramesLanguage' => 
  array (
    'id' => '405',
    'language_id' => '2',
    'frame_id' => '407',
    'name' => '施設予約',
    'is_origin' => true,
    'is_translation' => false,
    'is_original_copy' => false,
  ),
  'Block' => 
  array (
    'id' => '5',
    'room_id' => '1',                           // frameと違う
    'plugin_key' => 'reservations',      // frameと同じ
    'key' => '06daa57a1bec336dbf86c7c37d812dee',
    'public_type' => '1',
    'publish_start' => NULL,
    'publish_end' => NULL,
    'content_count' => '0',
  ),
  'BlocksLanguage' => 
  array (
    'language_id' => NULL,
    'block_id' => NULL,
    'name' => NULL,
    'is_origin' => NULL,
    'is_translation' => NULL,
    'is_original_copy' => NULL,
  ),
)

暫定対応

app/Plugin/NetCommons/Lib/Current/CurrentLibFrame.phpの414行目あたりを修正します。

$this->isSameRoomAndPluginByRequestBlockAndFrameBlock($frame, $block)

https://github.com/NetCommons3/NetCommons/blob/3.3.0.1/Lib/Current/CurrentLibFrame.php#L410

/**
 * リクエストのBlockとFrameのBlockが同じプラグインと同じルームかどうかチェックする。
 *
 * @param array $frame フレームデータ
 * @param array $block ブロックデータ
 * @return bool
 */
	public function isSameRoomAndPluginByRequestBlockAndFrameBlock($frame, $block) {
		if (isset($block['Block']['room_id']) &&
				($block['Block']['room_id'] !== $frame['Frame']['room_id'] ||
				$block['Block']['plugin_key'] !== $frame['Frame']['plugin_key'])) {
			// 暫定対応bugfix
			// https://github.com/NetCommons3/NetCommons3/issues/1546
			// 施設要約はサイトで1つのため、blockはroom_id=1、frameは例えばroom_id =8(コミュニティルーム)と違くなりfalse返っていた。
			// そのため、施設予約の場合、room_idの比較は行わないで、blockとframeのplugin_keyが同じならtrueとする。
			// カレンダーも同じはずだが、登録できた。なぜだろう?
			if ($block['Block']['plugin_key'] == 'reservations' && $block['Block']['plugin_key'] === $frame['Frame']['plugin_key']) {
				return true;
			}


			return false;
		} else {
			return true;
		}
	}

CurrentLibFrame.phpを修正するのがいいのか、施設予約側の修正が足りてないのかは、ちょっと判別つきませんでした。

報告まで。

@akagane99
Copy link
Contributor Author

調査3

複数のカレンダー、施設予約をパブリックルームとコミュニティルームに配置済み。
その状態で、DBのblocksテーブルを確認したところ、カレンダーは複数件ありましたが、施設予約は1件のみでした。
施設予約のblockが1件のみだったため、今回の不具合が出たようです。

実行した SQL:

SELECT * FROM `nc3_blocks` WHERE `plugin_key` IN ('calendars','reservations') ORDER BY 
`nc3_blocks`.`plugin_key` ASC LIMIT 0, 30 ;

行: 9

id room_id plugin_key プラグインKey key ブロックKey public_type 公開タイプ(0:非公開, 1:公開, 2:期間限定公開。期間限定公開の場合、現在時刻がfrom-toカラムの範囲内の時に公開。) publish_start 公開日時(from) publish_end 公開日時(to) content_count created_user created modified_user modified  
6 1 calendars cddc643dc58e944cda8f761f09cffee7 1 NULL NULL 0 1 2019-01-09 12:28:20 2 2019-10-15 09:05:25
16 6 calendars c7a7ac9bb97d7089965af6850848608d 1 NULL NULL 0 2 2019-02-25 07:28:24 2 2019-02-25 07:28:24
17 7 calendars 45b6e58b6674e9ad0b197ae57842f94a 1 NULL NULL 0 2 2019-02-25 07:28:24 9 2019-03-27 04:53:32
18 8 calendars f668cdb4d8ebdfc18fe180c8bd31d2ad 1 NULL NULL 0 2 2019-02-25 07:28:24 1 2019-12-12 11:38:43
19 9 calendars e5211fae0e9b377e163c21bf5bc088aa 1 NULL NULL 0 2 2019-02-25 07:28:24 2 2019-02-25 07:28:24
20 10 calendars 2bd7345f8404aec8c8fe3a2b068dcefb 1 NULL NULL 0 2 2019-02-25 07:28:24 2 2019-02-25 07:28:24
21 11 calendars 3d056d11a7de026fec179019b96b3159 1 NULL NULL 0 2 2019-02-25 07:28:24 2 2019-02-25 07:28:24
22 3 calendars 0ee2917f48eab185117b907b929ef7dc 1 NULL NULL 0 2 2019-02-25 07:28:24 2 2019-02-25 07:28:24
5 1 reservations 06daa57a1bec336dbf86c7c37d812dee 1 NULL NULL 0 1 2019-01-09 12:28:19 1 2019-01-09 12:28:19

報告まで。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants