‪TYPO3CMS  9.5
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 
17 use Psr\Log\LoggerAwareInterface;
18 use Psr\Log\LoggerAwareTrait;
23 
27 abstract class ‪AbstractDatabaseRecordProvider implements LoggerAwareInterface
28 {
29  use LoggerAwareTrait;
30 
41  protected function ‪getRecordFromDatabase($tableName, $uid)
42  {
43  if ($uid <= 0) {
44  throw new \InvalidArgumentException(
45  '$uid must be positive integer, ' . $uid . ' given',
46  1437656456
47  );
48  }
49  $row = $this->‪getDatabaseRow($tableName, $uid);
50  if (empty($row)) {
51  // Indicates a runtime error (eg. record was killed by other editor meanwhile) can be caught elsewhere
52  // and transformed to a message to the user or something
54  'Record with uid ' . $uid . ' from table ' . $tableName . ' not found',
55  1437656081,
56  null,
57  $tableName,
58  (int)$uid
59  );
60  }
61  return $row;
62  }
63 
71  protected function ‪getDatabaseRow(string $tableName, int $uid): array
72  {
73  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
74  $queryBuilder->getRestrictions()
75  ->removeAll()
76  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
77 
78  $row = $queryBuilder->select('*')
79  ->from($tableName)
80  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
81  ->execute()
82  ->fetch();
83 
84  return $row ?: [];
85  }
86 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\AbstractDatabaseRecordProvider
Definition: AbstractDatabaseRecordProvider.php:28
‪TYPO3\CMS\Backend\Form\FormDataProvider\AbstractDatabaseRecordProvider\getRecordFromDatabase
‪array getRecordFromDatabase($tableName, $uid)
Definition: AbstractDatabaseRecordProvider.php:41
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:2
‪TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException
Definition: DatabaseRecordException.php:23
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:26
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Form\FormDataProvider\AbstractDatabaseRecordProvider\getDatabaseRow
‪array getDatabaseRow(string $tableName, int $uid)
Definition: AbstractDatabaseRecordProvider.php:71