Skip to content

Commit 2779172

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-69648-UserModuleVersionCheck' into Okapis-develop-pr
2 parents 370c69e + a5ec2f8 commit 2779172

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

app/code/Magento/User/Setup/UpgradeSchema.php

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,27 @@ class UpgradeSchema implements UpgradeSchemaInterface
2121
*/
2222
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
2323
{
24-
$installer = $setup;
25-
$installer->startSetup();
26-
$tableAdmins = $installer->getTable('admin_user');
24+
$setup->startSetup();
2725

28-
$installer->getConnection()->addColumn(
26+
if (version_compare($context->getVersion(), '2.0.1', '<')) {
27+
$this->addFailuresToAdminUserTable($setup);
28+
$this->createAdminPasswordsTable($setup);
29+
}
30+
31+
$setup->endSetup();
32+
}
33+
34+
/**
35+
* Adds 'failures_num', 'first_failure', and 'lock_expires' columns to 'admin_user' table
36+
*
37+
* @param SchemaSetupInterface $setup
38+
* @return void
39+
*/
40+
private function addFailuresToAdminUserTable(SchemaSetupInterface $setup)
41+
{
42+
$tableAdmins = $setup->getTable('admin_user');
43+
44+
$setup->getConnection()->addColumn(
2945
$tableAdmins,
3046
'failures_num',
3147
[
@@ -35,28 +51,38 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
3551
'comment' => 'Failure Number'
3652
]
3753
);
38-
$installer->getConnection()->addColumn(
54+
$setup->getConnection()->addColumn(
3955
$tableAdmins,
4056
'first_failure',
4157
[
4258
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
4359
'comment' => 'First Failure'
4460
]
4561
);
46-
$installer->getConnection()->addColumn(
62+
$setup->getConnection()->addColumn(
4763
$tableAdmins,
4864
'lock_expires',
4965
[
5066
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
5167
'comment' => 'Expiration Lock Dates'
5268
]
5369
);
70+
}
71+
72+
/**
73+
* Create table 'admin_passwords'
74+
*
75+
* @param SchemaSetupInterface $setup
76+
* @return void
77+
*/
78+
private function createAdminPasswordsTable(SchemaSetupInterface $setup)
79+
{
80+
if ($setup->tableExists($setup->getTable('admin_passwords'))) {
81+
return;
82+
}
5483

55-
/**
56-
* Create table 'admin_passwords'
57-
*/
58-
$table = $installer->getConnection()->newTable(
59-
$installer->getTable('admin_passwords')
84+
$table = $setup->getConnection()->newTable(
85+
$setup->getTable('admin_passwords')
6086
)->addColumn(
6187
'password_id',
6288
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
@@ -88,19 +114,17 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
88114
['unsigned' => true, 'nullable' => false, 'default' => '0'],
89115
'Last Updated'
90116
)->addIndex(
91-
$installer->getIdxName('admin_passwords', ['user_id']),
117+
$setup->getIdxName('admin_passwords', ['user_id']),
92118
['user_id']
93119
)->addForeignKey(
94-
$installer->getFkName('admin_passwords', 'user_id', 'admin_user', 'user_id'),
120+
$setup->getFkName('admin_passwords', 'user_id', 'admin_user', 'user_id'),
95121
'user_id',
96-
$installer->getTable('admin_user'),
122+
$setup->getTable('admin_user'),
97123
'user_id',
98124
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
99125
)->setComment(
100126
'Admin Passwords'
101127
);
102-
$installer->getConnection()->createTable($table);
103-
104-
$installer->endSetup();
128+
$setup->getConnection()->createTable($table);
105129
}
106130
}

0 commit comments

Comments
 (0)