ILIAS  release_8 Revision v8.24
class.ilSearchCommandQueue.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/*
5 +-----------------------------------------------------------------------------+
6 | ILIAS open source |
7 +-----------------------------------------------------------------------------+
8 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9 | |
10 | This program is free software; you can redistribute it and/or |
11 | modify it under the terms of the GNU General Public License |
12 | as published by the Free Software Foundation; either version 2 |
13 | of the License, or (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software |
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 +-----------------------------------------------------------------------------+
24*/
25
35{
36 private static ?self $instance = null;
37
38 protected ilDBInterface $db;
39
43 protected function __construct()
44 {
45 global $DIC;
46
47 $this->db = $DIC->database();
48 }
49
53 public static function factory(): ilSearchCommandQueue
54 {
55 if (self::$instance instanceof ilSearchCommandQueue) {
56 return self::$instance;
57 }
58 return self::$instance = new ilSearchCommandQueue();
59 }
60
64 public function store(ilSearchCommandQueueElement $element): void
65 {
66 $query = "SELECT obj_id, obj_type FROM search_command_queue " .
67 "WHERE obj_id = " . $this->db->quote($element->getObjId(), 'integer') . " " .
68 "AND obj_type = " . $this->db->quote($element->getObjType(), 'text');
69 $res = $this->db->query($query);
70 if ($res->numRows()) {
71 $this->update($element);
72 } else {
73 $this->insert($element);
74 }
75 }
76
80 protected function insert(ilSearchCommandQueueElement $element): void
81 {
82 $query = "INSERT INTO search_command_queue (obj_id,obj_type,sub_id,sub_type,command,last_update,finished) " .
83 "VALUES( " .
84 $this->db->quote($element->getObjId(), 'integer') . ", " .
85 $this->db->quote($element->getObjType(), 'text') . ", " .
86 "0, " .
87 "''," .
88 $this->db->quote($element->getCommand(), 'text') . ", " .
89 $this->db->now() . ", " .
90 "0 " .
91 ")";
92 $res = $this->db->manipulate($query);
93 }
94
98 protected function update(ilSearchCommandQueueElement $element): void
99 {
100 $query = "UPDATE search_command_queue " .
101 "SET command = " . $this->db->quote($element->getCommand(), 'text') . ", " .
102 "last_update = " . $this->db->now() . ", " .
103 "finished = " . $this->db->quote(0, 'integer') . " " .
104 "WHERE obj_id = " . $this->db->quote($element->getObjId(), 'integer') . " " .
105 "AND obj_type = " . $this->db->quote($element->getObjType(), 'text');
106 $res = $this->db->manipulate($query);
107 }
108}
Represents an entry for the search command queue.
insert(ilSearchCommandQueueElement $element)
Insert new entry.
update(ilSearchCommandQueueElement $element)
Update existing entry.
store(ilSearchCommandQueueElement $element)
update / save new entry
static factory()
get singleton instance
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query