‪TYPO3CMS  10.4
AbstractDatabaseRecordProvider.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Log\LoggerAwareInterface;
19 use Psr\Log\LoggerAwareTrait;
24 
28 abstract class ‪AbstractDatabaseRecordProvider implements LoggerAwareInterface
29 {
30  use LoggerAwareTrait;
31 
42  protected function ‪getRecordFromDatabase($tableName, $uid)
43  {
44  if ($uid <= 0) {
45  throw new \InvalidArgumentException(
46  '$uid must be positive integer, ' . $uid . ' given',
47  1437656456
48  );
49  }
50  $row = $this->‪getDatabaseRow($tableName, $uid);
51  if (empty($row)) {
52  // Indicates a runtime error (eg. record was killed by other editor meanwhile) can be caught elsewhere
53  // and transformed to a message to the user or something
55  'Record with uid ' . $uid . ' from table ' . $tableName . ' not found',
56  1437656081,
57  null,
58  $tableName,
59  (int)$uid
60  );
61  }
62  return $row;
63  }
64 
72  protected function ‪getDatabaseRow(string $tableName, int $uid): array
73  {
74  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
75  $queryBuilder->getRestrictions()
76  ->removeAll()
77  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
78 
79  $row = $queryBuilder->select('*')
80  ->from($tableName)
81  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
82  ->execute()
83  ->fetch();
84 
85  return $row ?: [];
86  }
87 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\AbstractDatabaseRecordProvider
Definition: AbstractDatabaseRecordProvider.php:29
‪TYPO3\CMS\Backend\Form\FormDataProvider\AbstractDatabaseRecordProvider\getRecordFromDatabase
‪array getRecordFromDatabase($tableName, $uid)
Definition: AbstractDatabaseRecordProvider.php:42
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException
Definition: DatabaseRecordException.php:24
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Form\FormDataProvider\AbstractDatabaseRecordProvider\getDatabaseRow
‪array getDatabaseRow(string $tableName, int $uid)
Definition: AbstractDatabaseRecordProvider.php:72