TYPO3 CMS  TYPO3_7-6
AbstractDatabaseRecordProvider.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
25 {
36  protected function getRecordFromDatabase($tableName, $uid)
37  {
38  if ($uid <= 0) {
39  throw new \InvalidArgumentException(
40  '$uid must be positive integer, ' . $uid . ' given',
41  1437656456
42  );
43  }
44  $database = $this->getDatabase();
45  $tableName = $database->quoteStr($tableName, $tableName);
46  $where = 'uid=' . (int)$uid . BackendUtility::deleteClause($tableName);
47  $row = $database->exec_SELECTgetSingleRow('*', $tableName, $where);
48  if ($row === null) {
49  // Indicates a program / usage error
50  throw new \RuntimeException(
51  'Database error fetching record from tablename ' . $tableName . ' with uid ' . $uid,
52  1437655862
53  );
54  }
55  if ($row === false) {
56  // Indicates a runtime error (eg. record was killed by other editor meanwhile) can be caught elsewhere
57  // and transformed to a message to the user or something
58  throw new DatabaseRecordException(
59  'Record with uid ' . $uid . ' from table ' . $tableName . ' not found',
60  1437656081,
61  null,
62  $tableName,
63  (int)$uid
64  );
65  }
66  if (!is_array($row)) {
67  // Database connection behaves weird ...
68  throw new \UnexpectedValueException(
69  'Database exec_SELECTgetSingleRow() did not return error type or result',
70  1437656323
71  );
72  }
73  return $row;
74  }
75 
79  protected function getDatabase()
80  {
81  return $GLOBALS['TYPO3_DB'];
82  }
83 }
$database
Definition: server.php:40
$uid
Definition: server.php:38
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static deleteClause($table, $tableAlias='')