ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSearchCommandQueue.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24include_once './Services/Search/classes/class.ilSearchCommandQueueElement.php';
35{
36 private static $instance = null;
37
38
42 protected function __construct()
43 {
44 }
45
49 public static function factory()
50 {
51 if (isset(self::$instance) and self::$instance) {
52 return self::$instance;
53 }
54 return self::$instance = new ilSearchCommandQueue();
55 }
56
60 public function store(ilSearchCommandQueueElement $element)
61 {
62 global $DIC;
63
64 $ilDB = $DIC['ilDB'];
65
66 $query = "SELECT obj_id, obj_type FROM search_command_queue " .
67 "WHERE obj_id = " . $ilDB->quote($element->getObjId(), 'integer') . " " .
68 "AND obj_type = " . $ilDB->quote($element->getObjType(), 'text');
69 $res = $ilDB->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)
81 {
82 global $DIC;
83
84 $ilDB = $DIC['ilDB'];
85
86 $query = "INSERT INTO search_command_queue (obj_id,obj_type,sub_id,sub_type,command,last_update,finished) " .
87 "VALUES( " .
88 $ilDB->quote($element->getObjId(), 'integer') . ", " .
89 $ilDB->quote($element->getObjType(), 'text') . ", " .
90 "0, " .
91 "''," .
92 $ilDB->quote($element->getCommand(), 'text') . ", " .
93 $ilDB->now() . ", " .
94 "0 " .
95 ")";
96 $res = $ilDB->manipulate($query);
97 return true;
98 }
99
103 protected function update(ilSearchCommandQueueElement $element)
104 {
105 global $DIC;
106
107 $ilDB = $DIC['ilDB'];
108
109 $query = "UPDATE search_command_queue " .
110 "SET command = " . $ilDB->quote($element->getCommand(), 'text') . ", " .
111 "last_update = " . $ilDB->now() . ", " .
112 "finished = " . $ilDB->quote(0, 'integer') . " " .
113 "WHERE obj_id = " . $ilDB->quote($element->getObjId(), 'integer') . " " .
114 "AND obj_type = " . $ilDB->quote($element->getObjType(), 'text');
115 $res = $ilDB->manipulate($query);
116 return true;
117 }
118}
An exception for terminatinating execution or to throw for unit testing.
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
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB