ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
24 include_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 $ilDB;
63 
64  $query = "SELECT obj_id, obj_type FROM search_command_queue " .
65  "WHERE obj_id = " . $ilDB->quote($element->getObjId(), 'integer') . " " .
66  "AND obj_type = " . $ilDB->quote($element->getObjType(), 'text');
67  $res = $ilDB->query($query);
68  if ($res->numRows()) {
69  $this->update($element);
70  } else {
71  $this->insert($element);
72  }
73  }
74 
78  protected function insert(ilSearchCommandQueueElement $element)
79  {
80  global $ilDB;
81 
82  $query = "INSERT INTO search_command_queue (obj_id,obj_type,sub_id,sub_type,command,last_update,finished) " .
83  "VALUES( " .
84  $ilDB->quote($element->getObjId(), 'integer') . ", " .
85  $ilDB->quote($element->getObjType(), 'text') . ", " .
86  "0, " .
87  "''," .
88  $ilDB->quote($element->getCommand(), 'text') . ", " .
89  $ilDB->now() . ", " .
90  "0 " .
91  ")";
92  $res = $ilDB->manipulate($query);
93  return true;
94  }
95 
99  protected function update(ilSearchCommandQueueElement $element)
100  {
101  global $ilDB;
102 
103  $query = "UPDATE search_command_queue " .
104  "SET command = " . $ilDB->quote($element->getCommand(), 'text') . ", " .
105  "last_update = " . $ilDB->now() . ", " .
106  "finished = " . $ilDB->quote(0, 'integer') . " " .
107  "WHERE obj_id = " . $ilDB->quote($element->getObjId(), 'integer') . " " .
108  "AND obj_type = " . $ilDB->quote($element->getObjType(), 'text');
109  $res = $ilDB->manipulate($query);
110  return true;
111  }
112 }
Represents an entry for the search command queue.
store(ilSearchCommandQueueElement $element)
update / save new entry
insert(ilSearchCommandQueueElement $element)
Insert new entry.
static factory()
get singleton instance
update(ilSearchCommandQueueElement $element)
Update existing entry.
foreach($_POST as $key=> $value) $res
$query
global $ilDB