1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Utility; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2014-2015 Ingo Renner <[email protected]> |
8
|
|
|
* All rights reserved |
9
|
|
|
* |
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
11
|
|
|
* free software; you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU General Public License as published by |
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
14
|
|
|
* (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* The GNU General Public License can be found at |
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
18
|
|
|
* |
19
|
|
|
* This script is distributed in the hope that it will be useful, |
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22
|
|
|
* GNU General Public License for more details. |
23
|
|
|
* |
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
25
|
|
|
***************************************************************/ |
26
|
|
|
|
27
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
28
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
29
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Database utility class to do things the core currently does not support |
33
|
|
|
* |
34
|
|
|
* @author Ingo Renner <[email protected]> |
35
|
|
|
* @deprecated Since 8.0.0, will be removed in 9.0.0. Use doctrines DBAL Connection::beginTransaction()|commit()|rollBack() |
36
|
|
|
* See ApacheSolrForTypo3\Solr\System\Records\AbstractRepository::getConnectionForAllInTransactionInvolvedTables() |
37
|
|
|
*/ |
38
|
|
|
class DatabaseUtility |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return Connection |
43
|
|
|
*/ |
44
|
|
|
protected static function getFirstAvailableConnection() |
45
|
|
|
{ |
46
|
|
|
return GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Start a transaction |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public static function transactionStart() |
55
|
|
|
{ |
56
|
|
|
self::getFirstAvailableConnection()->beginTransaction(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Commit a transaction |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public static function transactionCommit() |
65
|
|
|
{ |
66
|
|
|
self::getFirstAvailableConnection()->commit(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Roll back a transaction |
71
|
|
|
* |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
|
|
public static function transactionRollback() |
75
|
|
|
{ |
76
|
|
|
self::getFirstAvailableConnection()->rollBack(); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|