Use doctrine dbal consistently

This commit is contained in:
Björn Fromme
2018-06-08 17:16:34 +02:00
parent 3220301161
commit 18d054c1fb
3 changed files with 53 additions and 43 deletions
@@ -28,6 +28,7 @@ namespace EP\EpProducts\Hook;
***************************************************************/ ***************************************************************/
use EP\EpProducts\Service\GeolocationService; use EP\EpProducts\Service\GeolocationService;
use EP\EpProducts\Utility\DbUtility;
use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Messaging\FlashMessage; use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService; use TYPO3\CMS\Core\Messaging\FlashMessageService;
@@ -67,38 +68,41 @@ class Tcemain
// Render flash message in case of duplicate entry // Render flash message in case of duplicate entry
if ($table === 'tx_epproducts_domain_model_matchcode' && $fields['code'] !== '') { if ($table === 'tx_epproducts_domain_model_matchcode' && $fields['code'] !== '') {
$code = $fields['code']; $code = $fields['code'];
$qb = DbUtility::getDbConnection()->createQueryBuilder();
$query = $qb
->select('uid')
->from('tx_epproducts_domain_model_matchcode')
->where('code = :code')
->andWhere('deleted = 0')
->setParameter('code', $code)
;
if (is_numeric($id)) { if (is_numeric($id)) {
$existing = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow( $query
'uid', ->andWhere('uid != :uid')
'tx_epproducts_domain_model_matchcode', ->setParameter('uid', $id)
'code="' . $code . '" AND uid != ' . $id . ' AND deleted=0' ;
);
} else {
$existing = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
'uid',
'tx_epproducts_domain_model_matchcode',
'code="' . $code . '" AND deleted=0'
);
} }
$existing = $query->execute()->fetch();
if ($existing) { if ($existing) {
$this->addFlashMessage('Der Hotelcode ' . $code . ' ist schon vergeben worden.', 'Hinweis', FlashMessage::WARNING); $this->addFlashMessage('Der Hotelcode ' . $code . ' ist schon vergeben worden.', 'Hinweis', FlashMessage::WARNING);
} }
} }
if ($table === 'tx_epproducts_domain_model_product' && $fields['code'] !== '') { if ($table === 'tx_epproducts_domain_model_product' && $fields['code'] !== '') {
$code = $fields['code']; $code = $fields['code'];
$qb = DbUtility::getDbConnection()->createQueryBuilder();
$query = $qb
->select('uid')
->from('tx_epproducts_domain_model_product')
->where('code = :code')
->andWhere('deleted = 0')
->setParameter('code', $code);
if (is_numeric($id)) { if (is_numeric($id)) {
$existing = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow( $query
'uid', ->andWhere('uid != :uid')
'tx_epproducts_domain_model_product', ->setParameter('uid', $id)
'code="' . $code . '" AND uid != ' . $id . ' AND deleted=0' ;
);
} else {
$existing = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
'uid',
'tx_epproducts_domain_model_product',
'code="' . $code . ' AND deleted=0'
);
} }
$existing = $query->execute()->fetch();
if ($existing) { if ($existing) {
$this->addFlashMessage('Der Productcode ' . $code . ' ist schon vergeben worden.', 'Hinweis', FlashMessage::WARNING); $this->addFlashMessage('Der Productcode ' . $code . ' ist schon vergeben worden.', 'Hinweis', FlashMessage::WARNING);
} }
@@ -28,7 +28,7 @@ namespace EP\EpProducts\Service;
***************************************************************/ ***************************************************************/
use EP\EpProducts\Domain\Model\FilterSettings; use EP\EpProducts\Domain\Model\FilterSettings;
use TYPO3\CMS\Core\Database\DatabaseConnection; use EP\EpProducts\Utility\DbUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility; use TYPO3\CMS\Core\Utility\HttpUtility;
@@ -44,22 +44,22 @@ class StaticSearchParamsRequestService
$uri = strtolower(parse_url($currentUri, \PHP_URL_PATH)); $uri = strtolower(parse_url($currentUri, \PHP_URL_PATH));
/** @var DatabaseConnection $db */ $qb = DbUtility::getDbConnection()->createQueryBuilder();
$db = $GLOBALS['TYPO3_DB']; $query = $qb
->select('*')
->from('tx_epproducts_domain_model_staticsearchparams')
->where('CONCAT("/", :prefix, "/", path_segment, "/")=LOWER(:uri)')
->andWhere('deleted = 0')
->andWhere('hidden = 0')
->setParameters([
'prefix' => self::PREFIX_PATH_SEGMENT,
'uri' => $uri,
])
;
$row = $db->exec_SELECTgetSingleRow( $row = $query->execute()->fetch();
'*',
'tx_epproducts_domain_model_staticsearchparams',
'CONCAT(
"/",
"' . self::PREFIX_PATH_SEGMENT . '",
"/", tx_epproducts_domain_model_staticsearchparams.path_segment,
"/"
)=LOWER(' . $db->fullQuoteStr($uri, 'tx_epproducts_domain_model_staticsearchparams') . ')'
. ' AND tx_epproducts_domain_model_staticsearchparams.deleted=0 AND tx_epproducts_domain_model_staticsearchparams.hidden=0'
);
if ($row === false) { if (!$row) {
return; return;
} }
@@ -27,6 +27,7 @@ namespace EP\EpTheme\DataProcessing;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
use EP\EpProducts\Utility\DbUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
@@ -67,11 +68,16 @@ class ContextProcessor implements DataProcessorInterface
*/ */
private function getContextRecord($uid, $table) private function getContextRecord($uid, $table)
{ {
$where = $GLOBALS['TSFE']->sys_page->enableFields($table); $qb = DbUtility::getDbConnection()->createQueryBuilder();
return $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow( $query = $qb
'*', ->select('*')
$table, ->from($table)
$table . '.uid=' . $uid . $where ->where('uid = :uid')
); ->andWhere('deleted = 0')
->andWhere('hidden = 0')
->setParameter('uid', $uid)
;
return $query->execute()->fetch();
} }
} }