|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <https://github.com/baleen/migrations>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Baleen\Migrations\Service\MigrationBus\Middleware; |
|
21
|
|
|
|
|
22
|
|
|
use Baleen\Migrations\Migration\Capabilities\TransactionAwareInterface; |
|
23
|
|
|
use Baleen\Migrations\Service\MigrationBus\MigrateCommand; |
|
24
|
|
|
use League\Tactician\Middleware; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Wraps the migration in a transaction if the migration implements |
|
28
|
|
|
* TransactionAwareInterface. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Gabriel Somoza <[email protected]> |
|
31
|
|
|
*/ |
|
32
|
|
|
final class TransactionMiddleware implements Middleware |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* execute |
|
36
|
|
|
* |
|
37
|
|
|
* @param MigrateCommand $command |
|
38
|
|
|
* @param callable $next |
|
39
|
|
|
* |
|
40
|
|
|
* @return void |
|
41
|
|
|
*/ |
|
42
|
15 |
|
public function execute($command, callable $next) |
|
43
|
|
|
{ |
|
44
|
15 |
|
$migration = $command->getMigration(); |
|
45
|
15 |
|
if (!$migration instanceof TransactionAwareInterface) { |
|
46
|
14 |
|
$next($command); |
|
47
|
14 |
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
$result = null; |
|
|
|
|
|
|
51
|
|
|
try { |
|
52
|
1 |
|
$migration->begin(); |
|
53
|
1 |
|
$next($command); |
|
54
|
1 |
|
$migration->finish(); |
|
55
|
1 |
|
} catch (\Exception $e) { |
|
56
|
1 |
|
$migration->abort($e); |
|
57
|
|
|
} |
|
58
|
1 |
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.