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

Commit 25e19b8

Browse files
committed
Switch to BLOB for ajxp_mq_queues
1 parent 06788be commit 25e19b8

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

core/src/plugins/mq.sql/SqlMessageExchanger.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function loadChannel($channelName, $create = false)
9090
if($res->count()){
9191
if(!isset(self::$channels)) self::$channels = array();
9292
$single = $res->fetchSingle();
93-
$data = unserialize(base64_decode($single));
93+
$data = unserialize($single);
9494
if (is_array($data)) {
9595
if(!is_array($data["MESSAGES"])) $data["MESSAGES"] = array();
9696
if(!is_array($data["CLIENTS"])) $data["CLIENTS"] = array();
@@ -109,6 +109,7 @@ public function __destruct()
109109
{
110110
if (isSet(self::$channels) && is_array(self::$channels) && !empty($this->sqlDriver)) {
111111
$inserts = [];
112+
$insertValues = [];
112113
$deletes = [];
113114
$driver = $this->sqlDriver["driver"];
114115
if(!dibi::isConnected()){
@@ -117,12 +118,14 @@ public function __destruct()
117118
foreach (self::$channels as $channelName => $data) {
118119
if (is_array($data)) {
119120
if(isSet($data["CLIENTS"]) && count($data["CLIENTS"])) {
120-
$serialized = base64_encode(serialize($data));
121+
$serialized = serialize($data);
121122
if($driver === "postgre"){
122123
dibi::query("DELETE FROM [ajxp_mq_queues] WHERE [channel_name] = %s", $channelName);
123124
dibi::query('INSERT INTO [ajxp_mq_queues]', ["channel_name" => $channelName, "content" => $serialized]);
124125
}else{
125-
$inserts[] = "('$channelName', '".$serialized."')";
126+
$inserts[] = "(%s, %bin)";
127+
$insertValues[] = $channelName;
128+
$insertValues[] = $serialized;
126129
}
127130
}else{
128131
$deletes[] = $channelName;
@@ -131,7 +134,9 @@ public function __destruct()
131134
}
132135
if(count($inserts)){
133136
try{
134-
dibi::query('REPLACE INTO [ajxp_mq_queues] ([channel_name],[content]) VALUES '.implode(",", $inserts));
137+
$args = ['REPLACE INTO [ajxp_mq_queues] ([channel_name],[content]) VALUES '.implode(",", $inserts)];
138+
$args = array_merge($args, $insertValues);
139+
call_user_func_array(array("dibi", "query"), $args);
135140
}catch(\DibiException $dE){
136141
$this->logError(__CLASS__, $dE->getMessage());
137142
}

core/src/plugins/mq.sql/create.mysql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CREATE TABLE IF NOT EXISTS `ajxp_mq_queues` (
22
`channel_name` varchar(255) NOT NULL,
3-
`content` text NOT NULL,
3+
`content` BLOB NOT NULL,
44
PRIMARY KEY (`channel_name`)
55
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

core/src/plugins/mq.sql/create.pgsql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CREATE TABLE IF NOT EXISTS ajxp_mq_queues (
22
channel_name varchar(255) NOT NULL,
3-
content text NOT NULL,
3+
content BLOB NOT NULL,
44
constraint pk primary key(channel_name)
55
);

core/src/plugins/mq.sql/create.sqlite

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
CREATE TABLE IF NOT EXISTS ajxp_mq_queues (
22
channel_name TEXT NOT NULL PRIMARY KEY,
3-
content text NOT NULL,
3+
content BLOB NOT NULL,
44
);

0 commit comments

Comments
 (0)