Permalink
Browse files

Make sure to use %bin modifier

  • Loading branch information...
1 parent 5a2faed commit 6a7240dd5718ab0025b6c7dfc05bb93fa2bc65e0 @cdujeu cdujeu committed Oct 7, 2016
@@ -44,6 +44,21 @@ class SqlTasksProvider implements ITasksProvider
* @return array
*/
protected function taskToDBValues(Task $task, $removeId = false){
+ $modifiers = [
+ "[type]" => "%i",
+ "[parent_uid]" => "%s",
+ "[flags]" => "%i",
+ "[label]" => "%s",
+ "[user_id]" => "%s",
+ "[ws_id]" => "%s",
+ "[status]" => "%i",
+ "[status_msg]" => "%s",
+ "[progress]" => "%i",
+ "[schedule]" => "%i",
+ "[schedule_value]" => "%s",
+ "[action]" => "%s",
+ "[parameters]" => "%bin",
+ ];
$values = [
"type" => $task->getType(),
"parent_uid" => $task->getParentId(),
@@ -62,11 +77,14 @@ protected function taskToDBValues(Task $task, $removeId = false){
if(!$removeId){
// This is a creation
$values["creation_date"] = time();
+ $modifiers["[creation_date]"] = "%i";
$values = array_merge(["uid" => $task->getId()], $values);
+ $modifiers = array_merge(["[uid]" => "%s"], $modifiers);
}else{
$values["status_update"] = time();
+ $modifiers["[status_update]"] = "%i";
}
- return $values;
+ return [$modifiers, $values];
}
/**
@@ -134,7 +152,12 @@ protected function loadTaskNodes(&$task){
*/
public function createTask(Task $task, Schedule $when)
{
- dibi::query("INSERT INTO [ajxp_tasks] ", $this->taskToDBValues($task));
+ list($modifiers, $values) = $this->taskToDBValues($task);
+ $fields = implode(",", array_keys($modifiers));
+ $mods = implode(",", array_values($modifiers));
+ $values = array_values($values);
+ array_unshift($values, "INSERT INTO [ajxp_tasks] (".$fields.") VALUES (".$mods.")");
+ call_user_func_array(["dibi", "query"], $values);
$this->insertOrUpdateNodes($task);
}
@@ -158,7 +181,15 @@ public function getTaskById($taskId)
public function updateTask(Task $task)
{
try{
- dibi::query("UPDATE [ajxp_tasks] SET ", $this->taskToDBValues($task, true), " WHERE [uid] =%s", $task->getId());
+ list($modifiers, $values) = $this->taskToDBValues($task, true);
+ $mods = [];
+ foreach($modifiers as $field => $mod){
+ $mods[] = "$field=$mod";
+ }
+ $values = array_values($values);
+ $values[] = $task->getId();
+ array_unshift($values, "UPDATE [ajxp_tasks] SET ".implode(",", $mods)." WHERE [uid] =%s");
+ call_user_func_array(["dibi", "query"], $values);
$this->insertOrUpdateNodes($task, true);
}catch (\DibiException $ex){
Logger::error(__CLASS__, __FUNCTION__, "Error while updating task: ".$ex->getSql());
@@ -127,7 +127,7 @@ public function __destruct()
$serialized = gzdeflate(serialize($data), 9);
if($driver === "postgre"){
dibi::query("DELETE FROM [ajxp_mq_queues] WHERE [channel_name] = %s", $channelName);
- dibi::query('INSERT INTO [ajxp_mq_queues]', ["channel_name" => $channelName, "content" => $serialized]);
+ dibi::query('INSERT INTO [ajxp_mq_queues] ([channel_name], [content]) VALUES (%s, %bin)', $channelName, $serialized);
}else{
$inserts[] = "(%s, %bin)";
$insertValues[] = $channelName;

0 comments on commit 6a7240d

Please sign in to comment.