1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* File: InstallSchema.php |
7
|
|
|
* |
8
|
|
|
* @author Bartosz Kubicki [email protected]> |
9
|
|
|
* @copyright Copyright (C) 2019 Lizard Media (http://lizardmedia.pl) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace LizardMedia\ProductAttachment\Setup; |
13
|
|
|
|
14
|
|
|
use LizardMedia\ProductAttachment\Model\Attachment; |
15
|
|
|
use Magento\Framework\Setup\InstallSchemaInterface; |
16
|
|
|
use Magento\Framework\Setup\ModuleContextInterface; |
17
|
|
|
use Magento\Framework\Setup\SchemaSetupInterface; |
18
|
|
|
use Magento\Framework\DB\Ddl\Table; |
19
|
|
|
use Zend_Db_Exception; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class InstallSchema |
23
|
|
|
* @package LizardMedia\ProductAttachment\Setup |
24
|
|
|
*/ |
25
|
|
|
class InstallSchema implements InstallSchemaInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @param SchemaSetupInterface $setup |
29
|
|
|
* @param ModuleContextInterface $context |
30
|
|
|
* |
31
|
|
|
* @throws Zend_Db_Exception |
32
|
|
|
* |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) |
36
|
|
|
{ |
37
|
|
|
$setup->startSetup(); |
38
|
|
|
|
39
|
|
|
$productAttachments = $setup->getConnection()->newTable( |
40
|
|
|
$setup->getTable(Attachment::MAIN_TABLE) |
41
|
|
|
)->addColumn( |
42
|
|
|
Attachment::ID, |
43
|
|
|
Table::TYPE_INTEGER, |
44
|
|
|
11, |
45
|
|
|
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], |
46
|
|
|
'Id' |
47
|
|
|
)->addColumn( |
48
|
|
|
Attachment::PRODUCT_ID, |
49
|
|
|
Table::TYPE_INTEGER, |
50
|
|
|
11, |
51
|
|
|
['unsigned' => true, 'nullable' => false], |
52
|
|
|
'Product id' |
53
|
|
|
)->addColumn( |
54
|
|
|
Attachment::SORT_ORDER, |
55
|
|
|
Table::TYPE_INTEGER, |
56
|
|
|
11, |
57
|
|
|
['unsigned' => true, 'nullable' => false], |
58
|
|
|
'Sort order' |
59
|
|
|
)->addColumn( |
60
|
|
|
Attachment::ATTACHMENT_TYPE, |
61
|
|
|
Table::TYPE_TEXT, |
62
|
|
|
21, |
63
|
|
|
['nullable' => false], |
64
|
|
|
'Type' |
65
|
|
|
)->addColumn( |
66
|
|
|
Attachment::ATTACHMENT_FILE, |
67
|
|
|
Table::TYPE_TEXT, |
68
|
|
|
255, |
69
|
|
|
['nullable' => true], |
70
|
|
|
'File' |
71
|
|
|
)->addColumn( |
72
|
|
|
Attachment::ATTACHMENT_URL, |
73
|
|
|
Table::TYPE_TEXT, |
74
|
|
|
255, |
75
|
|
|
['nullable' => true], |
76
|
|
|
'File' |
77
|
|
|
)->addForeignKey( |
78
|
|
|
$setup->getFkName( |
79
|
|
|
$setup->getTable(Attachment::MAIN_TABLE), |
80
|
|
|
Attachment::PRODUCT_ID, |
81
|
|
|
$setup->getTable('catalog_product_entity'), |
82
|
|
|
'entity_id' |
83
|
|
|
), |
84
|
|
|
Attachment::PRODUCT_ID, |
85
|
|
|
$setup->getTable('catalog_product_entity'), |
86
|
|
|
'entity_id', |
87
|
|
|
Table::ACTION_CASCADE |
88
|
|
|
)->setComment( |
89
|
|
|
'Product attachments' |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
$setup->getConnection()->createTable($productAttachments); |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
|
96
|
|
|
$productAttachmentsTitle = $setup->getConnection()->newTable( |
97
|
|
|
$setup->getTable(Attachment::TITLE_TABLE) |
98
|
|
|
)->addColumn( |
99
|
|
|
Attachment::TITLE_ID, |
100
|
|
|
Table::TYPE_INTEGER, |
101
|
|
|
11, |
102
|
|
|
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], |
103
|
|
|
'Id' |
104
|
|
|
)->addColumn( |
105
|
|
|
Attachment::ATTACHMENT_ID, |
106
|
|
|
Table::TYPE_INTEGER, |
107
|
|
|
11, |
108
|
|
|
['unsigned' => true, 'nullable' => false], |
109
|
|
|
'Attachment id' |
110
|
|
|
)->addColumn( |
111
|
|
|
Attachment::STORE_ID, |
112
|
|
|
Table::TYPE_INTEGER, |
113
|
|
|
11, |
114
|
|
|
['unsigned' => true, 'nullable' => false], |
115
|
|
|
'Store id' |
116
|
|
|
)->addColumn( |
117
|
|
|
Attachment::TITLE, |
118
|
|
|
Table::TYPE_TEXT, |
119
|
|
|
120, |
120
|
|
|
['nullable' => false], |
121
|
|
|
'Title' |
122
|
|
|
)->addForeignKey( |
123
|
|
|
$setup->getFkName( |
124
|
|
|
$setup->getTable(Attachment::TITLE_TABLE), |
125
|
|
|
Attachment::ATTACHMENT_ID, |
126
|
|
|
$setup->getTable(Attachment::MAIN_TABLE), |
127
|
|
|
Attachment::ID |
128
|
|
|
), |
129
|
|
|
Attachment::ATTACHMENT_ID, |
130
|
|
|
$setup->getTable(Attachment::MAIN_TABLE), |
131
|
|
|
Attachment::ID, |
132
|
|
|
Table::ACTION_CASCADE |
133
|
|
|
)->setComment( |
134
|
|
|
'Product attachments titles' |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
$setup->getConnection()->createTable($productAttachmentsTitle); |
138
|
|
|
|
139
|
|
|
$setup->endSetup(); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|