TYPO3 CMS  TYPO3_8-7
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 
23 
28 {
39  protected function getRecordFromDatabase($tableName, $uid)
40  {
41  if ($uid <= 0) {
42  throw new \InvalidArgumentException(
43  '$uid must be positive integer, ' . $uid . ' given',
44  1437656456
45  );
46  }
47  $row = $this->getDatabaseRow($tableName, $uid);
48  if (empty($row)) {
49  // Indicates a runtime error (eg. record was killed by other editor meanwhile) can be caught elsewhere
50  // and transformed to a message to the user or something
51  throw new DatabaseRecordException(
52  'Record with uid ' . $uid . ' from table ' . $tableName . ' not found',
53  1437656081,
54  null,
55  $tableName,
56  (int)$uid
57  );
58  }
59  return $row;
60  }
61 
69  protected function getDatabaseRow(string $tableName, int $uid): array
70  {
71  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
72  $queryBuilder->getRestrictions()
73  ->removeAll()
74  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
75 
76  $row = $queryBuilder->select('*')
77  ->from($tableName)
78  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
79  ->execute()
80  ->fetch();
81 
82  return $row ?: [];
83  }
84 }
static makeInstance($className,... $constructorArguments)