Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Avoid using : and * chars for queue files on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Oct 3, 2016
1 parent 60ee9fd commit 034bc4f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions core/src/plugins/mq.serial/SerialMessageExchanger.php
Expand Up @@ -42,6 +42,19 @@ class SerialMessageExchanger extends Plugin implements IMessageExchanger
private $channels;
private $clientsGCTime = 10;

/**
* Windows-ify channel name to avoid forbidden characters
* @param $channelName
* @return mixed
*/
protected function channelNameToFileName($channelName){
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
return str_replace(array(":", "*"), array("---", "__ALL__"), $channelName);
}else{
return $channelName;
}
}

/**
* @param $channelName
* @param bool $create
Expand All @@ -54,7 +67,7 @@ public function loadChannel($channelName, $create = false)
}
if (is_file($this->getPluginWorkDir()."/queues/channel-$channelName")) {
if(!isset($this->channels)) $this->channels = array();
$data = FileHelper::loadSerialFile($this->getPluginWorkDir() . "/queues/channel-$channelName");
$data = FileHelper::loadSerialFile($this->getPluginWorkDir() . "/queues/channel-".$this->channelNameToFileName($channelName));
if (is_array($data)) {
if(!is_array($data["MESSAGES"])) $data["MESSAGES"] = array();
if(!is_array($data["CLIENTS"])) $data["CLIENTS"] = array();
Expand All @@ -74,7 +87,7 @@ public function __destruct()
if (isSet($this->channels) && is_array($this->channels)) {
foreach ($this->channels as $channelName => $data) {
if (is_array($data)) {
FileHelper::saveSerialFile($this->getPluginWorkDir() . "/queues/channel-$channelName", $data);
FileHelper::saveSerialFile($this->getPluginWorkDir() . "/queues/channel-".$this->channelNameToFileName($channelName), $data);
}
}
}
Expand Down

0 comments on commit 034bc4f

Please sign in to comment.