1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* File:InstallSchema.php |
6
|
|
|
* |
7
|
|
|
* @author Maciej Sławik <[email protected]> |
8
|
|
|
* @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace LizardMedia\PasswordMigrator\Setup; |
12
|
|
|
|
13
|
|
|
use LizardMedia\PasswordMigrator\Model\Password; |
14
|
|
|
use LizardMedia\PasswordMigrator\Model\ResourceModel\Password as PasswordResource; |
15
|
|
|
use Magento\Framework\DB\Ddl\Table; |
16
|
|
|
use Magento\Framework\Setup\InstallSchemaInterface; |
17
|
|
|
use Magento\Framework\Setup\ModuleContextInterface; |
18
|
|
|
use Magento\Framework\Setup\SchemaSetupInterface; |
19
|
|
|
use Magento\Framework\DB\Adapter\AdapterInterface; |
20
|
|
|
use Zend_Db_Exception; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class InstallSchema |
24
|
|
|
* @package LizardMedia\PasswordMigrator\Setup |
25
|
|
|
*/ |
26
|
|
|
class InstallSchema implements InstallSchemaInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @param SchemaSetupInterface $setup |
30
|
|
|
* @param ModuleContextInterface $context |
31
|
|
|
* @throws Zend_Db_Exception |
32
|
|
|
*/ |
33
|
|
|
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) |
34
|
|
|
{ |
35
|
|
|
$setup->startSetup(); |
36
|
|
|
|
37
|
|
|
$this->createPasswordMigratorTable($setup); |
38
|
|
|
|
39
|
|
|
$setup->endSetup(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param SchemaSetupInterface $setup |
44
|
|
|
* @return void |
45
|
|
|
* @throws Zend_Db_Exception |
46
|
|
|
*/ |
47
|
|
|
private function createPasswordMigratorTable(SchemaSetupInterface $setup): void |
48
|
|
|
{ |
49
|
|
|
$table = $setup->getConnection()->newTable( |
50
|
|
|
$setup->getTable(PasswordResource::TABLE_NAME) |
51
|
|
|
)->addColumn( |
52
|
|
|
Password::ID, |
53
|
|
|
Table::TYPE_INTEGER, |
54
|
|
|
null, |
55
|
|
|
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], |
56
|
|
|
'ID' |
57
|
|
|
)->addColumn( |
58
|
|
|
Password::CUSTOMER_ID, |
59
|
|
|
Table::TYPE_INTEGER, |
60
|
|
|
null, |
61
|
|
|
['unsigned' => true, 'nullable' => false], |
62
|
|
|
'Customer ID' |
63
|
|
|
)->addColumn( |
64
|
|
|
Password::PASSWORD, |
65
|
|
|
Table::TYPE_TEXT, |
66
|
|
|
null, |
67
|
|
|
['nullable' => false], |
68
|
|
|
'Password' |
69
|
|
|
)->addColumn( |
70
|
|
|
Password::SALT, |
71
|
|
|
Table::TYPE_TEXT, |
72
|
|
|
null, |
73
|
|
|
['nullable' => false], |
74
|
|
|
'Salt' |
75
|
|
|
)->addColumn( |
76
|
|
|
Password::CREATED_AT, |
77
|
|
|
Table::TYPE_TIMESTAMP, |
78
|
|
|
null, |
79
|
|
|
['nullable' => false, 'default' => Table::TIMESTAMP_INIT], |
80
|
|
|
'Create date' |
81
|
|
|
)->addForeignKey( |
82
|
|
|
$setup->getFkName( |
83
|
|
|
PasswordResource::TABLE_NAME, |
84
|
|
|
Password::CUSTOMER_ID, |
85
|
|
|
$setup->getTable('customer_entity'), |
86
|
|
|
'entity_id' |
87
|
|
|
), |
88
|
|
|
Password::CUSTOMER_ID, |
89
|
|
|
$setup->getTable('customer_entity'), |
90
|
|
|
'entity_id', |
91
|
|
|
Table::ACTION_CASCADE |
92
|
|
|
)->addIndex( |
93
|
|
|
$setup->getIdxName( |
94
|
|
|
PasswordResource::TABLE_NAME, |
95
|
|
|
[ |
96
|
|
|
Password::CUSTOMER_ID |
97
|
|
|
], |
98
|
|
|
AdapterInterface::INDEX_TYPE_UNIQUE |
99
|
|
|
), |
100
|
|
|
[ |
101
|
|
|
Password::CUSTOMER_ID |
102
|
|
|
], |
103
|
|
|
[ |
104
|
|
|
'type' => AdapterInterface::INDEX_TYPE_UNIQUE |
105
|
|
|
] |
106
|
|
|
)->setComment( |
107
|
|
|
'LizardMedia PasswordMigrator legacy passwords table' |
108
|
|
|
); |
109
|
|
|
$setup->getConnection()->createTable($table); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|