ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
arConnectorDB Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for arConnectorDB:
+ Collaboration diagram for arConnectorDB:

Public Member Functions

 __construct (?ilDBInterface $ilDB=null)
 
 checkConnection (ActiveRecord $activeRecord)
 
 nextID (ActiveRecord $activeRecord)
 
 installDatabase (ActiveRecord $activeRecord, array $fields)
 
 updateIndices (ActiveRecord $activeRecord)
 
 updateDatabase (ActiveRecord $activeRecord)
 
 resetDatabase (ActiveRecord $activeRecord)
 
 truncateDatabase (ActiveRecord $activeRecord)
 
 checkTableExists (ActiveRecord $activeRecord)
 
 checkFieldExists (ActiveRecord $activeRecord, string $field_name)
 
 removeField (ActiveRecord $activeRecord, string $field_name)
 
 renameField (ActiveRecord $activeRecord, string $old_name, string $new_name)
 
 create (ActiveRecord $activeRecord)
 
 read (ActiveRecord $activeRecord)
 
 update (ActiveRecord $activeRecord)
 
 delete (ActiveRecord $activeRecord)
 
 readSet (ActiveRecordList $activeRecordList)
 
 affectedRows (ActiveRecordList $activeRecordList)
 
 quote ($value, string $type)
 
- Public Member Functions inherited from arConnector
 nextID (ActiveRecord $ar)
 
 checkConnection (ActiveRecord $ar)
 
 installDatabase (ActiveRecord $ar, array $fields)
 
 updateDatabase (ActiveRecord $ar)
 
 resetDatabase (ActiveRecord $ar)
 
 truncateDatabase (ActiveRecord $ar)
 
 checkTableExists (ActiveRecord $ar)
 
 checkFieldExists (ActiveRecord $ar, string $field_name)
 
 removeField (ActiveRecord $ar, string $field_name)
 
 renameField (ActiveRecord $ar, string $old_name, string $new_name)
 
 create (ActiveRecord $ar)
 
 read (ActiveRecord $ar)
 
 update (ActiveRecord $ar)
 
 delete (ActiveRecord $ar)
 
 readSet (ActiveRecordList $arl)
 
 affectedRows (ActiveRecordList $arl)
 
 quote ($value, string $type)
 
 updateIndices (ActiveRecord $ar)
 
 fixDate (string $value)
 

Protected Member Functions

 returnDB ()
 
 buildQuery (ActiveRecordList $activeRecordList)
 

Private Attributes

ilDBInterface $db = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class arConnectorDB

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Timon Amstutz timon.nosp@m..ams.nosp@m.tutz@.nosp@m.ilub.nosp@m..unib.nosp@m.e.ch
Version
2.0.7

Definition at line 25 of file class.arConnectorDB.php.

Constructor & Destructor Documentation

◆ __construct()

arConnectorDB::__construct ( ?ilDBInterface  $ilDB = null)

Definition at line 29 of file class.arConnectorDB.php.

References $DIC, $GLOBALS, and $ilDB.

30  {
31  if (is_null($ilDB)) {
32  global $DIC;
33 
34  $this->db = $GLOBALS['ilDB'] ?? $DIC['ilDB'] ?? null;
35  } else {
36  $this->db = $ilDB;
37  }
38  }
global $DIC
Definition: feed.php:28
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64

Member Function Documentation

◆ affectedRows()

arConnectorDB::affectedRows ( ActiveRecordList  $activeRecordList)

PhpParamsInspection

Definition at line 255 of file class.arConnectorDB.php.

References $ilDB, buildQuery(), and returnDB().

Referenced by arConnectorCache\affectedRows().

255  : int
256  {
257  $ilDB = $this->returnDB();
258  $q = $this->buildQuery($activeRecordList);
259 
260  $set = $ilDB->query($q);
261 
263  return $ilDB->numRows($set);
264  }
buildQuery(ActiveRecordList $activeRecordList)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildQuery()

arConnectorDB::buildQuery ( ActiveRecordList  $activeRecordList)
protected
Returns
mixed|string

Definition at line 269 of file class.arConnectorDB.php.

References ActiveRecordList\getAR(), ActiveRecordList\getArConcatCollection(), ActiveRecordList\getArHavingCollection(), ActiveRecordList\getArJoinCollection(), ActiveRecordList\getArLimitCollection(), ActiveRecordList\getArOrderCollection(), ActiveRecordList\getArSelectCollection(), ActiveRecordList\getArWhereCollection(), and ActiveRecordList\setLastQuery().

Referenced by affectedRows(), and readSet().

269  : string
270  {
271  // SELECTS
272  $q = $activeRecordList->getArSelectCollection()->asSQLStatement($this->db);
273  // Concats
274  $q .= $activeRecordList->getArConcatCollection()->asSQLStatement($this->db);
275  $q .= ' FROM ' . $activeRecordList->getAR()->getConnectorContainerName();
276  // JOINS
277  $q .= $activeRecordList->getArJoinCollection()->asSQLStatement($this->db);
278  // WHERE
279  $q .= $activeRecordList->getArWhereCollection()->asSQLStatement($this->db);
280  // HAVING
281  $q .= $activeRecordList->getArHavingCollection()->asSQLStatement($this->db);
282  // ORDER
283  $q .= $activeRecordList->getArOrderCollection()->asSQLStatement($this->db);
284  // LIMIT
285  $q .= $activeRecordList->getArLimitCollection()->asSQLStatement($this->db);
286 
287  $activeRecordList->setLastQuery($q);
288 
289  return $q;
290  }
static setLastQuery(string $last_query)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkConnection()

arConnectorDB::checkConnection ( ActiveRecord  $activeRecord)

Definition at line 48 of file class.arConnectorDB.php.

References returnDB().

Referenced by arConnectorCache\checkConnection().

48  : bool
49  {
50  return is_object($this->returnDB());
51  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkFieldExists()

arConnectorDB::checkFieldExists ( ActiveRecord  $activeRecord,
string  $field_name 
)

Definition at line 153 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getConnectorContainerName(), and returnDB().

Referenced by arConnectorCache\checkFieldExists().

153  : bool
154  {
155  $ilDB = $this->returnDB();
156 
157  return $ilDB->tableColumnExists($activeRecord->getConnectorContainerName(), $field_name);
158  }
getConnectorContainerName()
Return the Name of your Connector Table
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkTableExists()

arConnectorDB::checkTableExists ( ActiveRecord  $activeRecord)

: This is the proper ILIAS approach on how to do this BUT: This is exteremely slow (listTables is used)! However, this is not the place to fix this issue. Report.

Definition at line 142 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getConnectorContainerName(), and returnDB().

Referenced by arConnectorCache\checkTableExists().

142  : bool
143  {
144  $ilDB = $this->returnDB();
145 
150  return $ilDB->tableExists($activeRecord->getConnectorContainerName());
151  }
getConnectorContainerName()
Return the Name of your Connector Table
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create()

arConnectorDB::create ( ActiveRecord  $activeRecord)

Definition at line 185 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getArrayForConnector(), ActiveRecord\getConnectorContainerName(), and returnDB().

Referenced by arConnectorCache\create().

185  : void
186  {
187  $ilDB = $this->returnDB();
188  $ilDB->insert($activeRecord->getConnectorContainerName(), $activeRecord->getArrayForConnector());
189  }
getConnectorContainerName()
Return the Name of your Connector Table
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

arConnectorDB::delete ( ActiveRecord  $activeRecord)

Definition at line 227 of file class.arConnectorDB.php.

References $ilDB, arFieldCache\getPrimaryFieldName(), arFieldCache\getPrimaryFieldType(), and returnDB().

Referenced by arConnectorCache\delete().

227  : void
228  {
229  $ilDB = $this->returnDB();
230 
231  $ilDB->manipulate(
232  'DELETE FROM ' . $activeRecord->getConnectorContainerName() . ' WHERE ' . arFieldCache::getPrimaryFieldName(
233  $activeRecord
234  ) . ' = '
235  . $ilDB->quote($activeRecord->getPrimaryFieldValue(), arFieldCache::getPrimaryFieldType($activeRecord))
236  );
237  }
static getPrimaryFieldName(ActiveRecord $ar)
static getPrimaryFieldType(ActiveRecord $ar)
getConnectorContainerName()
Return the Name of your Connector Table
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ installDatabase()

arConnectorDB::installDatabase ( ActiveRecord  $activeRecord,
array  $fields 
)

Definition at line 61 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getArFieldList(), ActiveRecord\getConnectorContainerName(), returnDB(), and updateIndices().

Referenced by arConnectorCache\installDatabase().

61  : bool
62  {
63  $ilDB = $this->returnDB();
64  $ilDB->createTable($activeRecord->getConnectorContainerName(), $fields);
65  $arFieldList = $activeRecord->getArFieldList();
66  if ($arFieldList->getPrimaryField()->getName() !== '' && $arFieldList->getPrimaryField()->getName() !== '0') {
67  $ilDB->addPrimaryKey(
68  $activeRecord->getConnectorContainerName(),
69  [$arFieldList->getPrimaryField()->getName()]
70  );
71  }
72  if (!$ilDB->sequenceExists($activeRecord->getConnectorContainerName()) && $activeRecord->getArFieldList(
73  )->getPrimaryField()->getSequence()) {
74  $ilDB->createSequence($activeRecord->getConnectorContainerName());
75  }
76  $this->updateIndices($activeRecord);
77 
78  return true;
79  }
updateIndices(ActiveRecord $activeRecord)
getConnectorContainerName()
Return the Name of your Connector Table
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nextID()

arConnectorDB::nextID ( ActiveRecord  $activeRecord)
Returns
mixed

Definition at line 56 of file class.arConnectorDB.php.

References ActiveRecord\getConnectorContainerName(), and returnDB().

Referenced by arConnectorCache\nextID().

56  : int
57  {
58  return $this->returnDB()->nextId($activeRecord->getConnectorContainerName());
59  }
getConnectorContainerName()
Return the Name of your Connector Table
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quote()

arConnectorDB::quote (   $value,
string  $type 
)
Parameters
$value

Definition at line 295 of file class.arConnectorDB.php.

References $ilDB, and returnDB().

Referenced by arConnectorCache\quote().

295  : string
296  {
297  $ilDB = $this->returnDB();
298 
299  return $ilDB->quote($value, $type);
300  }
$type
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

arConnectorDB::read ( ActiveRecord  $activeRecord)
Returns
mixed[]

Definition at line 194 of file class.arConnectorDB.php.

References $ilDB, $query, ActiveRecord\getConnectorContainerName(), arFieldCache\getPrimaryFieldName(), arFieldCache\getPrimaryFieldType(), ActiveRecord\getPrimaryFieldValue(), and returnDB().

Referenced by arConnectorCache\read().

194  : array
195  {
196  $ilDB = $this->returnDB();
197 
198  $query = 'SELECT * FROM ' . $activeRecord->getConnectorContainerName(
199  ) . ' ' . ' WHERE ' . arFieldCache::getPrimaryFieldName($activeRecord) . ' = '
200  . $ilDB->quote($activeRecord->getPrimaryFieldValue(), arFieldCache::getPrimaryFieldType($activeRecord));
201 
202  $set = $ilDB->query($query);
203  $records = [];
204  while ($rec = $ilDB->fetchObject($set)) {
205  $records[] = $rec;
206  }
207 
208  return $records;
209  }
static getPrimaryFieldName(ActiveRecord $ar)
static getPrimaryFieldType(ActiveRecord $ar)
getConnectorContainerName()
Return the Name of your Connector Table
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readSet()

arConnectorDB::readSet ( ActiveRecordList  $activeRecordList)
Returns
mixed[]

Definition at line 243 of file class.arConnectorDB.php.

References $ilDB, buildQuery(), and returnDB().

Referenced by arConnectorCache\readSet().

243  : array
244  {
245  $ilDB = $this->returnDB();
246  $set = $ilDB->query($this->buildQuery($activeRecordList));
247  $records = [];
248  while ($rec = $ilDB->fetchAssoc($set)) {
249  $records[] = $rec;
250  }
251 
252  return $records;
253  }
buildQuery(ActiveRecordList $activeRecordList)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeField()

arConnectorDB::removeField ( ActiveRecord  $activeRecord,
string  $field_name 
)

Definition at line 160 of file class.arConnectorDB.php.

References $ilDB, arException\COLUMN_DOES_NOT_EXIST, ActiveRecord\getConnectorContainerName(), and returnDB().

Referenced by arConnectorCache\removeField().

160  : bool
161  {
162  $ilDB = $this->returnDB();
163  if (!$ilDB->tableColumnExists($activeRecord->getConnectorContainerName(), $field_name)) {
164  throw new arException($field_name, arException::COLUMN_DOES_NOT_EXIST);
165  }
166  $ilDB->dropTableColumn($activeRecord->getConnectorContainerName(), $field_name);
167  return true;
168  }
getConnectorContainerName()
Return the Name of your Connector Table
Class arException.
const COLUMN_DOES_NOT_EXIST
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renameField()

arConnectorDB::renameField ( ActiveRecord  $activeRecord,
string  $old_name,
string  $new_name 
)

Definition at line 170 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getConnectorContainerName(), and returnDB().

Referenced by arConnectorCache\renameField().

170  : bool
171  {
172  $ilDB = $this->returnDB();
173  //throw new arException($old_name, arException::COLUMN_DOES_NOT_EXIST);
174  if (!$ilDB->tableColumnExists($activeRecord->getConnectorContainerName(), $old_name)) {
175  return true;
176  }
177  if ($ilDB->tableColumnExists($activeRecord->getConnectorContainerName(), $new_name)) {
178  return true;
179  }
180  //throw new arException($new_name, arException::COLUMN_DOES_ALREADY_EXIST);
181  $ilDB->renameTableColumn($activeRecord->getConnectorContainerName(), $old_name, $new_name);
182  return true;
183  }
getConnectorContainerName()
Return the Name of your Connector Table
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetDatabase()

arConnectorDB::resetDatabase ( ActiveRecord  $activeRecord)

Definition at line 118 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getConnectorContainerName(), ActiveRecord\installDB(), and returnDB().

Referenced by arConnectorCache\resetDatabase().

118  : bool
119  {
120  $ilDB = $this->returnDB();
121  if ($ilDB->tableExists($activeRecord->getConnectorContainerName())) {
122  $ilDB->dropTable($activeRecord->getConnectorContainerName());
123  }
124  $activeRecord->installDB();
125 
126  return true;
127  }
getConnectorContainerName()
Return the Name of your Connector Table
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ returnDB()

arConnectorDB::returnDB ( )
protected

Definition at line 40 of file class.arConnectorDB.php.

References $db.

Referenced by affectedRows(), checkConnection(), checkFieldExists(), checkTableExists(), create(), delete(), installDatabase(), nextID(), quote(), read(), readSet(), removeField(), renameField(), resetDatabase(), truncateDatabase(), update(), updateDatabase(), and updateIndices().

41  {
42  if (is_null($this->db)) {
43  throw new arException("No DB-Connection available");
44  }
45  return $this->db;
46  }
ilDBInterface $db
Class arException.
+ Here is the caller graph for this function:

◆ truncateDatabase()

arConnectorDB::truncateDatabase ( ActiveRecord  $activeRecord)

Definition at line 129 of file class.arConnectorDB.php.

References $ilDB, $query, ActiveRecord\getConnectorContainerName(), and returnDB().

Referenced by arConnectorCache\truncateDatabase().

129  : bool
130  {
131  $ilDB = $this->returnDB();
132  $query = 'TRUNCATE TABLE ' . $activeRecord->getConnectorContainerName();
133  $ilDB->query($query);
134  if ($ilDB->tableExists($activeRecord->getConnectorContainerName() . '_seq')) {
135  $ilDB->dropSequence($activeRecord->getConnectorContainerName());
136  $ilDB->createSequence($activeRecord->getConnectorContainerName());
137  }
138 
139  return true;
140  }
getConnectorContainerName()
Return the Name of your Connector Table
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

arConnectorDB::update ( ActiveRecord  $activeRecord)

Definition at line 211 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getArrayForConnector(), ActiveRecord\getConnectorContainerName(), arFieldCache\getPrimaryFieldName(), arFieldCache\getPrimaryFieldType(), ActiveRecord\getPrimaryFieldValue(), and returnDB().

Referenced by arConnectorCache\update().

211  : void
212  {
213  $ilDB = $this->returnDB();
214 
215  $ilDB->update(
216  $activeRecord->getConnectorContainerName(),
217  $activeRecord->getArrayForConnector(),
218  [
219  arFieldCache::getPrimaryFieldName($activeRecord) => [
220  arFieldCache::getPrimaryFieldType($activeRecord),
221  $activeRecord->getPrimaryFieldValue()
222  ]
223  ]
224  );
225  }
static getPrimaryFieldName(ActiveRecord $ar)
static getPrimaryFieldType(ActiveRecord $ar)
getConnectorContainerName()
Return the Name of your Connector Table
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateDatabase()

arConnectorDB::updateDatabase ( ActiveRecord  $activeRecord)

Definition at line 101 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getArFieldList(), ActiveRecord\getConnectorContainerName(), returnDB(), and updateIndices().

Referenced by arConnectorCache\updateDatabase().

101  : bool
102  {
103  $ilDB = $this->returnDB();
104  foreach ($activeRecord->getArFieldList()->getFields() as $arField) {
105  if (!$ilDB->tableColumnExists($activeRecord->getConnectorContainerName(), $arField->getName())) {
106  $ilDB->addTableColumn(
107  $activeRecord->getConnectorContainerName(),
108  $arField->getName(),
109  $arField->getAttributesForConnector()
110  );
111  }
112  }
113  $this->updateIndices($activeRecord);
114 
115  return true;
116  }
updateIndices(ActiveRecord $activeRecord)
getConnectorContainerName()
Return the Name of your Connector Table
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateIndices()

arConnectorDB::updateIndices ( ActiveRecord  $activeRecord)

Definition at line 81 of file class.arConnectorDB.php.

References $i, $ilDB, ActiveRecord\getArFieldList(), ActiveRecord\getConnectorContainerName(), and returnDB().

Referenced by installDatabase(), updateDatabase(), and arConnectorCache\updateIndices().

81  : void
82  {
83  $ilDB = $this->returnDB();
84  $arFieldList = $activeRecord->getArFieldList();
85  $existing_indices = $ilDB->loadModule('Manager')->listTableIndexes($activeRecord->getConnectorContainerName());
86 
87  foreach ($arFieldList->getFields() as $i => $arField) {
88  if (!$arField->getIndex()) {
89  continue;
90  }
91  if (in_array($arField->getName(), $existing_indices)) {
92  continue;
93  }
94  if ($ilDB->indexExistsByFields($activeRecord->getConnectorContainerName(), [$arField->getName()])) {
95  continue;
96  }
97  $ilDB->addIndex($activeRecord->getConnectorContainerName(), [$arField->getName()], 'i' . $i);
98  }
99  }
getConnectorContainerName()
Return the Name of your Connector Table
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface arConnectorDB::$db = null
private

Definition at line 27 of file class.arConnectorDB.php.

Referenced by returnDB().


The documentation for this class was generated from the following file: