From d31e826305f5df498aa8ed4486898920e9034897 Mon Sep 17 00:00:00 2001 From: yuri Date: Mon, 8 Jul 2019 16:18:22 +0300 Subject: [PATCH] fix websocket --- application/Espo/Core/WebSocket/Pusher.php | 36 +++++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/application/Espo/Core/WebSocket/Pusher.php b/application/Espo/Core/WebSocket/Pusher.php index d6181eca7c..3318e7cd0e 100644 --- a/application/Espo/Core/WebSocket/Pusher.php +++ b/application/Espo/Core/WebSocket/Pusher.php @@ -80,9 +80,10 @@ class Pusher implements WampServerInterface if ($checkCommand) { $checkResult = shell_exec($checkCommand); if ($checkResult !== 'true') { - if ($this->isDebugMode) $this->log("check access failed for topic {$topicId} for user {$userId}"); + if ($this->isDebugMode) $this->log("{$connectionId}: check access failed for topic {$topicId} for user {$userId}"); return; } + if ($this->isDebugMode) $this->log("{$connectionId}: check access succeed for topic {$topicId} for user {$userId}"); } if (!in_array($topicId, $this->connectionIdTopicIdListMap[$connectionId])) { @@ -110,20 +111,37 @@ class Pusher implements WampServerInterface if ($index !== false) { if ($this->isDebugMode) $this->log("{$connectionId}: remove topic {$topicId} for user {$userId}"); unset($this->connectionIdTopicIdListMap[$connectionId][$index]); - $this->connectionIdTopicIdListMap[$connectionId][$index] = array_values($this->connectionIdTopicIdListMap[$connectionId][$index]); + $this->connectionIdTopicIdListMap[$connectionId] = array_values($this->connectionIdTopicIdListMap[$connectionId]); } } } + protected function getCategoryData(string $topicId) : array + { + $arr = explode('.', $topicId); + $category = $arr[0]; + + if (array_key_exists($category, $this->categoriesData)) { + $data = $this->categoriesData[$category]; + } else if (array_key_exists($topicId, $this->categoriesData)) { + $data = $this->categoriesData[$topicId]; + } else { + $data = []; + } + + return $data; + } + protected function getParamsFromTopicId(string $topicId) : array { $arr = explode('.', $topicId); - $category = $arr[0]; + + $data = $this->getCategoryData($topicId); $params = []; - if (array_key_exists('paramList', $this->categoriesData[$category])) { - foreach ($this->categoriesData[$category]['paramList'] as $i => $item) { + if (array_key_exists('paramList', $data)) { + foreach ($data['paramList'] as $i => $item) { if (isset($arr[$i + 1])) { $params[$item] = $arr[$i + 1]; } else { @@ -146,10 +164,12 @@ class Pusher implements WampServerInterface return null; } - $category = $this->getTopicCategory($topic); - if (!array_key_exists('accessCheckCommand', $this->categoriesData[$category])) return null; + $data = $this->getCategoryData($topic->getId()); + + if (!array_key_exists('accessCheckCommand', $data)) return null; + + $command = $this->phpExecutablePath . " command.php " . $data['accessCheckCommand']; - $command = $this->phpExecutablePath . " command.php " . $this->categoriesData[$category]['accessCheckCommand']; foreach ($params as $key => $value) { $command = str_replace(':' . $key, $value, $command); }