1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kaliop\eZMigrationBundle\Command; |
4
|
|
|
|
5
|
|
|
use eZ\Publish\API\Repository\Repository; |
6
|
|
|
use Kaliop\eZMigrationBundle\Core\MigrationService; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
use Kaliop\eZMigrationBundle\API\Value\Migration; |
11
|
|
|
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Command to display the status of migrations. |
15
|
|
|
* |
16
|
|
|
* @todo add option to skip displaying already executed migrations |
17
|
|
|
*/ |
18
|
|
|
class TestBenchCommand extends AbstractCommand |
19
|
|
|
{ |
20
|
|
|
protected function configure() |
21
|
|
|
{ |
22
|
|
|
$this->setName('kaliop:migration:test') |
23
|
|
|
->setDescription('TEST of TRANSACTIONS') |
24
|
|
|
; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
28
|
|
|
{ |
29
|
|
|
/** @var Repository $repo */ |
30
|
|
|
$repo = $this->getContainer()->get('ezpublish.api.repository'); |
31
|
|
|
|
32
|
|
|
$user = $repo->getUserService()->loadUser(14); |
33
|
|
|
$repo->setCurrentUser($user); |
34
|
|
|
|
35
|
|
|
$ls = $repo->getLocationService(); |
36
|
|
|
$location = $ls->loadLocation(140); |
37
|
|
|
$ls->hideLocation($location); |
38
|
|
|
return; |
39
|
|
|
|
40
|
|
|
/** @var MigrationService $ms */ |
41
|
|
|
$ms = $this->getContainer()->get('ez_migration_bundle.migration_service'); |
|
|
|
|
42
|
|
|
/*echo 'A'; |
|
|
|
|
43
|
|
|
$repo->commitEvent( |
44
|
|
|
function ( $lastEvent ) |
45
|
|
|
{ |
46
|
|
|
throw new \Exception('hahaha'); |
47
|
|
|
} |
48
|
|
|
); |
49
|
|
|
echo 'B';*/ |
50
|
|
|
|
51
|
|
|
$ms->executeMigration(new MigrationDefinition( |
52
|
|
|
'test_'.time(), |
53
|
|
|
'/hello', |
54
|
|
|
'123', |
55
|
|
|
MigrationDefinition::STATUS_PARSED, |
56
|
|
|
array(), |
57
|
|
|
str_repeat('.', 4096) |
58
|
|
|
)); |
59
|
|
|
|
60
|
|
|
return; |
61
|
|
|
/// |
62
|
|
|
|
63
|
|
|
$sh = $this->getContainer()->get('ez_migration_bundle.storage_handler'); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$m1 = 'hello_'.time(); |
66
|
|
|
$m2 = 'there_'.time(); |
67
|
|
|
$sh->startMigration(new MigrationDefinition( |
68
|
|
|
$m1, |
69
|
|
|
'/hello', |
70
|
|
|
'123' |
71
|
|
|
)); |
72
|
|
|
$sh->startMigration(new MigrationDefinition( |
73
|
|
|
$m2, |
74
|
|
|
'/there', |
75
|
|
|
'123' |
76
|
|
|
)); |
77
|
|
|
|
78
|
|
|
$repo->beginTransaction(); |
79
|
|
|
|
80
|
|
|
$repo->beginTransaction(); |
81
|
|
|
//$repo->commit(); |
|
|
|
|
82
|
|
|
$repo->rollback(); |
83
|
|
|
|
84
|
|
|
$sh->endMigration(new Migration( |
85
|
|
|
$m2, |
86
|
|
|
'123', |
87
|
|
|
'/there', |
88
|
|
|
time(), |
89
|
|
|
0 |
90
|
|
|
)); |
91
|
|
|
$sh->endMigration(new Migration( |
92
|
|
|
$m1, |
93
|
|
|
'123', |
94
|
|
|
'/hello', |
95
|
|
|
time(), |
96
|
|
|
0 |
97
|
|
|
)); |
98
|
|
|
|
99
|
|
|
$repo->commit(); |
100
|
|
|
|
101
|
|
|
echo "OK\n"; |
102
|
|
|
|
103
|
|
|
/// |
104
|
|
|
|
105
|
|
|
$dbHandler = $this->getContainer()->get('ezpublish.connection'); |
106
|
|
|
$conn = $dbHandler->getConnection(); |
107
|
|
|
$conn->setNestTransactionsWithSavepoints(true); |
108
|
|
|
|
109
|
|
|
$repo->beginTransaction(); |
110
|
|
|
$repo->commit(); |
111
|
|
|
$repo->beginTransaction(); |
112
|
|
|
$repo->rollback(); |
113
|
|
|
echo "BCBR: OK\n"; |
114
|
|
|
|
115
|
|
|
$repo->beginTransaction(); |
116
|
|
|
$repo->rollback(); |
117
|
|
|
$repo->beginTransaction(); |
118
|
|
|
$repo->commit(); |
119
|
|
|
echo "BRBC: OK\n"; |
120
|
|
|
|
121
|
|
|
$repo->beginTransaction(); |
122
|
|
|
$repo->beginTransaction(); |
123
|
|
|
$repo->commit(); |
124
|
|
|
$repo->commit(); |
125
|
|
|
echo "BBCC: OK\n"; |
126
|
|
|
|
127
|
|
|
$repo->beginTransaction(); |
128
|
|
|
$repo->beginTransaction(); |
129
|
|
|
$repo->commit(); |
130
|
|
|
$repo->rollback(); |
131
|
|
|
echo "BBCR: OK\n"; |
132
|
|
|
|
133
|
|
|
$repo->beginTransaction(); |
134
|
|
|
$repo->beginTransaction(); |
135
|
|
|
$repo->rollback(); |
136
|
|
|
$repo->rollback(); |
137
|
|
|
echo "BBRR: OK\n"; |
138
|
|
|
|
139
|
|
|
// will throw unless partial rollbacks (savepoints) are enabled |
140
|
|
|
$repo->beginTransaction(); |
141
|
|
|
$repo->beginTransaction(); |
142
|
|
|
$repo->rollback(); |
143
|
|
|
$repo->beginTransaction(); |
144
|
|
|
$repo->commit(); |
145
|
|
|
$repo->commit(); |
146
|
|
|
echo "BBRBCC: OK\n"; |
147
|
|
|
|
148
|
|
|
// will throw unless partial rollbacks (savepoints) are enabled |
149
|
|
|
$repo->beginTransaction(); |
150
|
|
|
$repo->beginTransaction(); |
151
|
|
|
$repo->rollback(); |
152
|
|
|
$repo->commit(); |
153
|
|
|
echo "BBRC: OK\n"; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.