InstallSchema::install()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
namespace IntegerNet\AsyncVarnish\Setup;
4
5
use Magento\Framework\Setup\InstallSchemaInterface;
6
use Magento\Framework\Setup\ModuleContextInterface;
7
use Magento\Framework\Setup\SchemaSetupInterface;
8
use Magento\Framework\DB\Ddl\Table;
9
10
class InstallSchema implements InstallSchemaInterface
11
{
12
    /**
13
     * @param SchemaSetupInterface $setup
14
     * @param ModuleContextInterface $context
15
     * @throws \Zend_Db_Exception
16
     */
17
    public function install( //phpcs:ignore
18
        SchemaSetupInterface $setup,
19
        ModuleContextInterface $context
20
    ) {
21
        $setup->startSetup();
22
        $this->createTagsTable($setup);
23
        $setup->endSetup();
24
    }
25
26
    /**
27
     * @param SchemaSetupInterface $setup
28
     * @throws \Zend_Db_Exception
29
     */
30
    private function createTagsTable(SchemaSetupInterface $setup)
31
    {
32
        $tableName = $setup->getTable('integernet_async_varnish_tags');
33
        if (!$setup->getConnection()->isTableExists($tableName)) {
34
            $table = $setup->getConnection()
35
                ->newTable($tableName)
36
                ->addColumn(
37
                    'entity_id',
38
                    Table::TYPE_INTEGER,
39
                    null,
40
                    [
41
                        'identity' => true,
42
                        'unsigned' => true,
43
                        'nullable' => false,
44
                        'primary' => true
45
                    ],
46
                    'Entity ID'
47
                )
48
                ->addColumn(
49
                    'tag',
50
                    Table::TYPE_TEXT,
51
                    null,
52
                    ['nullable' => false, 'default' => ''],
53
                    'Tag'
54
                )
55
                ->setComment('Keeps track of cache tags that need to be purged')
56
                ->setOption('charset', 'utf8');
57
58
            $setup->getConnection()->createTable($table);
59
        }
60
    }
61
}
62