TYPO3  7.6
AbstractDatabaseRecordProvider.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Form\FormDataProvider;
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 
19 use TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException;
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  );
62  }
63  if (!is_array($row)) {
64  // Database connection behaves weird ...
65  throw new \UnexpectedValueException(
66  'Database exec_SELECTgetSingleRow() did not return error type or result',
67  1437656323
68  );
69  }
70  return $row;
71  }
72 
76  protected function getDatabase()
77  {
78  return $GLOBALS['TYPO3_DB'];
79  }
80 }