forked from ezsystems/ezpublish-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransactionHandler.php
113 lines (102 loc) · 3.14 KB
/
TransactionHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* File containing the Legacy Storage TransactionHandler
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace eZ\Publish\Core\Persistence\Legacy;
use eZ\Publish\SPI\Persistence\TransactionHandler as TransactionHandlerInterface;
use eZ\Publish\Core\Persistence\Legacy\Content\Type\MemoryCachingHandler as CachingContentTypeHandler;
use eZ\Publish\Core\Persistence\Legacy\Content\Language\CachingHandler as CachingLanguageHandler;
use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
use Exception;
use RuntimeException;
/**
* The Transaction handler for Legacy Storage Engine
*
* @since 5.3
*/
class TransactionHandler implements TransactionHandlerInterface
{
/**
* @var \eZ\Publish\Core\Persistence\Database\DatabaseHandler
*/
protected $dbHandler;
/**
* @var \eZ\Publish\SPI\Persistence\Content\Type\Handler
*/
protected $contentTypeHandler;
/**
* @var \eZ\Publish\SPI\Persistence\Content\Language\Handler
*/
protected $languageHandler;
/**
* @param \eZ\Publish\Core\Persistence\Database\DatabaseHandler $dbHandler
* @param \eZ\Publish\Core\Persistence\Legacy\Content\Type\MemoryCachingHandler $contentTypeHandler
* @param \eZ\Publish\Core\Persistence\Legacy\Content\Language\CachingHandler $languageHandler
*/
public function __construct(
DatabaseHandler $dbHandler,
CachingContentTypeHandler $contentTypeHandler = null,
CachingLanguageHandler $languageHandler = null
)
{
$this->dbHandler = $dbHandler;
$this->contentTypeHandler = $contentTypeHandler;
$this->languageHandler = $languageHandler;
}
/**
* Begin transaction
*/
public function beginTransaction()
{
$this->dbHandler->beginTransaction();
}
/**
* Commit transaction
*
* Commit transaction, or throw exceptions if no transactions has been started.
*
* @throws \RuntimeException If no transaction has been started
*/
public function commit()
{
try
{
$this->dbHandler->commit();
}
catch ( Exception $e )
{
throw new RuntimeException( $e->getMessage() );
}
}
/**
* Rollback transaction
*
* Rollback transaction, or throw exceptions if no transactions has been started.
*
* @throws \RuntimeException If no transaction has been started
*/
public function rollback()
{
try
{
$this->dbHandler->rollback();
// Clear all caches after rollback
if ( $this->contentTypeHandler instanceof CachingContentTypeHandler )
{
$this->contentTypeHandler->clearCache();
}
if ( $this->languageHandler instanceof CachingLanguageHandler )
{
$this->languageHandler->clearCache();
}
}
catch ( Exception $e )
{
throw new RuntimeException( $e->getMessage() );
}
}
}