Migration1::upgrade()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 4
nop 0
dl 0
loc 18
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * webtrees-lib: MyArtJaub library for webtrees
5
 *
6
 * @package MyArtJaub\Webtrees
7
 * @subpackage Hooks
8
 * @author Jonathan Jaubart <[email protected]>
9
 * @copyright Copyright (c) 2011-2022, Jonathan Jaubart
10
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3
11
 */
12
13
declare(strict_types=1);
14
15
namespace MyArtJaub\Webtrees\Module\Hooks\Schema;
16
17
use Fisharebest\Webtrees\Schema\MigrationInterface;
18
use Illuminate\Database\Capsule\Manager as DB;
19
use Illuminate\Database\Schema\Blueprint;
20
21
/**
22
 * Upgrade the database schema from version 1 to version 2.
23
 */
24
class Migration1 implements MigrationInterface
25
{
26
    /**
27
     * {@inheritDoc}
28
     * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
29
     */
30
    public function upgrade(): void
31
    {
32
        $in_transaction = DB::connection()->getPdo()->inTransaction();
33
34
        if (DB::schema()->hasTable('maj_hooks')) {
35
            DB::schema()->drop('maj_hooks');
36
        }
37
38
        DB::schema()->create('maj_hook_order', static function (Blueprint $table): void {
39
            $table->string('majho_module_name', 32);
40
            $table->string('majho_hook_name', 64);
41
            $table->integer('majho_hook_order')->nullable();
42
43
            $table->primary(['majho_module_name', 'majho_hook_name']);
44
        });
45
46
        if ($in_transaction && !DB::connection()->getPdo()->inTransaction()) {
47
            DB::connection()->beginTransaction();
48
        }
49
    }
50
}
51