1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stu\Orm\Transaction; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Configuration; |
6
|
|
|
use Doctrine\ORM\Decorator\EntityManagerDecorator; |
7
|
|
|
use Doctrine\ORM\EntityRepository; |
8
|
|
|
use Override; |
|
|
|
|
9
|
|
|
use Stu\Module\Logging\LoggerUtilFactoryInterface; |
10
|
|
|
use Stu\Module\Logging\LoggerUtilInterface; |
11
|
|
|
use Stu\Orm\Transaction\EntityManagerFactoryInterface; |
12
|
|
|
|
13
|
|
|
class ReopeningEntityManager extends EntityManagerDecorator |
14
|
|
|
{ |
15
|
|
|
private LoggerUtilInterface $logger; |
16
|
|
|
|
17
|
6 |
|
public function __construct( |
18
|
|
|
private EntityManagerFactoryInterface $entityManagerFactory, |
19
|
|
|
private Configuration $configuration, |
20
|
|
|
LoggerUtilFactoryInterface $loggerUtilFactory |
21
|
|
|
) { |
22
|
6 |
|
parent::__construct($entityManagerFactory->createEntityManager()); |
23
|
6 |
|
$this->logger = $loggerUtilFactory->getLoggerUtil(true); |
24
|
|
|
} |
25
|
|
|
|
26
|
1 |
|
private function reset(): void |
27
|
|
|
{ |
28
|
1 |
|
$this->wrapped = $this->entityManagerFactory->createEntityManager(); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
3 |
|
#[Override] |
32
|
|
|
public function getRepository(string $className): EntityRepository |
33
|
|
|
{ |
34
|
3 |
|
return $this |
35
|
3 |
|
->configuration |
36
|
3 |
|
->getRepositoryFactory() |
37
|
3 |
|
->getRepository($this, $className); |
38
|
|
|
} |
39
|
|
|
|
40
|
3 |
|
#[Override] |
41
|
|
|
public function beginTransaction(): void |
42
|
|
|
{ |
43
|
3 |
|
if (!$this->wrapped->isOpen()) { |
44
|
1 |
|
$this->logger->log('!!! TRANSACTION_CLOSED: now resetting!'); |
45
|
1 |
|
$this->reset(); |
46
|
1 |
|
$this->logger->log('!!! TRANSACTION_RESETTED'); |
47
|
|
|
} |
48
|
|
|
|
49
|
3 |
|
if (!$this->wrapped->getConnection()->isTransactionActive()) { |
50
|
|
|
//$this->logger->log('BEGIN_TRANSACTION'); |
51
|
2 |
|
$this->wrapped->beginTransaction(); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
#[Override] |
56
|
|
|
public function flush(): void |
57
|
|
|
{ |
58
|
|
|
if ($this->wrapped->isOpen()) { |
59
|
|
|
$this->wrapped->flush(); |
60
|
|
|
} else { |
61
|
|
|
throw new TransactionException('entity manager is closed.'); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
#[Override] |
66
|
|
|
public function commit(): void |
67
|
|
|
{ |
68
|
|
|
if ($this->wrapped->getConnection()->isTransactionActive()) { |
69
|
|
|
//$this->logger->log('COMMIT_TRANSACTION'); |
70
|
|
|
$this->wrapped->commit(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
#[Override] |
75
|
|
|
public function rollback(): void |
76
|
|
|
{ |
77
|
|
|
if ($this->wrapped->getConnection()->isTransactionActive()) { |
78
|
|
|
$this->logger->log('ROLLBACK_TRANSACTION'); |
79
|
|
|
$this->wrapped->rollback(); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths