Skip to content

Commit 0c02e1a

Browse files
author
Matthew Garde
committed
WIP
1 parent 9ae8192 commit 0c02e1a

File tree

12 files changed

+159
-58
lines changed

12 files changed

+159
-58
lines changed

Controller/Adminhtml/Login/Index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function execute() {
2424
$accCode = $this->getRequest()->getParam('account_code');
2525
$accTok = $this->getRequest()->getParam('account_token');
2626
$settings = $this->settingsDataFactory->create();
27+
2728
try
2829
{
2930
$settingsData = $settings->load(1);
@@ -33,7 +34,7 @@ public function execute() {
3334
}
3435
catch(\Exception $ex)
3536
{
36-
return $result->setData(['success' => false]);
37+
return $result->setData(['success' => false, 'exception' => $ex->getMessage()]);
3738
}
3839

3940
return $result->setData(['success' => true]);

Model/ResourceModel/SettingsData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class SettingsData extends AbstractDb
88
{
99
protected function _construct()
1010
{
11-
$this->_init('pcapredict_tag_settingsdata','pcapredict_tag_settingsdata_id');
11+
$this->_init('pcapredict_tag_settingsdata','id');
1212
}
1313
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ e.g. ``` git clone https://github.com/pcapredict/magento2.git Tag```
1616

1717
### If your using Composer
1818
- Integrated with Packagist, so you should be able to get the latest version with:
19-
```composer require pcapredict/tag:^2.0.1```
19+
```composer require pcapredict/tag:^2.0.7```
2020

2121
### Magento Setup
2222
- Make sure you have the correct file and folder permissions set on your magento installation so that the magnento store can install the app.

Setup/InstallData.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

Setup/InstallSchema.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
class InstallSchema implements InstallSchemaInterface
1111
{
1212
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
13-
{
14-
$installer = $setup;
15-
$installer->startSetup();
13+
{
14+
$setup->startSetup();
1615

17-
$tableName = $installer->getTable('pcapredict_tag_settingsdata');
18-
19-
$table = $installer->getConnection()
20-
->newTable($tableName)
16+
$table = $setup->getConnection()
17+
->newTable(
18+
$setup->getTable('pcapredict_tag_settingsdata')
19+
)
2120
->addColumn(
22-
'pcapredict_tag_settingsdata_id',
21+
'id',
2322
Table::TYPE_INTEGER,
2423
null,
2524
[ 'identity' => true, 'nullable' => false, 'primary' => true, 'unsigned' => true ],
@@ -61,14 +60,15 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
6160
'Creation Time'
6261
)
6362
->addColumn(
64-
'update_time',
65-
Table::TYPE_TIMESTAMP,
66-
null,
67-
[ 'nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE ],
68-
'Modification Time'
63+
'module_version',
64+
Table::TYPE_TEXT,
65+
16,
66+
[ 'nullable' => true ],
67+
'Created With App Version'
6968
);
7069

71-
$installer->getConnection()->createTable($table);
72-
$installer->endSetup();
70+
$setup->getConnection()->createTable($table);
71+
72+
$setup->endSetup();
7373
}
7474
}

Setup/Uninstall.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace PCAPredict\Tag\Setup;
4+
5+
use Magento\Framework\Setup\UninstallInterface;
6+
use Magento\Framework\Setup\SchemaSetupInterface;
7+
use Magento\Framework\Setup\ModuleContextInterface;
8+
9+
class Uninstall implements UninstallInterface
10+
{
11+
/**
12+
* Module uninstall code.
13+
* This will only run if uninstalled via composer.
14+
*
15+
* @param SchemaSetupInterface $setup
16+
* @param ModuleContextInterface $context
17+
* @return void
18+
*/
19+
public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context) {
20+
21+
$setup->startSetup();
22+
$setup->getConnection()->dropTable($connection->getTableName('pcapredict_tag_settingsdata'));
23+
$setup->endSetup();
24+
}
25+
}

Setup/UpgradeData.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace PCAPredict\Tag\Setup;
4+
5+
use Magento\Framework\Setup\UpgradeDataInterface;
6+
use Magento\Framework\Setup\ModuleDataSetupInterface;
7+
use Magento\Framework\Setup\ModuleContextInterface;
8+
9+
// Upgrade will only trigger if the setup_version in the module.xml is increased.
10+
class UpgradeData implements UpgradeDataInterface {
11+
12+
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context ) {
13+
14+
// Take all current records and set the current version of the app as the module_version.
15+
// Tidy up by taking either the row which has id 1 as this was what the old logic looked for.
16+
// If there is id=1 then simply keep the row with the latest creation time as this logic is what will
17+
// be used when checking for credentials, even though one record will still only be needed.
18+
if (version_compare($context->getVersion(), '2.0.7') < 0) {
19+
20+
$tableName = $setup->getTable('pcapredict_tag_settingsdata');
21+
22+
$select = $setup->getConnection()->select()->from($tableName);
23+
24+
$result = $setup->getConnection()->fetchAll($select);
25+
26+
foreach ($result as $row)
27+
{
28+
// Set the new module_version column with the current of the app.
29+
// Because we do not know what vesion they logged in under set to the last version will have to do.
30+
$setup->updateTableRow($tableName, 'id', $row['id'], 'module_version', $context->getVersion());
31+
}
32+
33+
$select = $setup->getConnection()->select()->from($tableName)->where('id = 1');
34+
35+
$row = $this->setup->getConnection()->fetchOne($select);
36+
37+
var_dump($row);
38+
39+
$select2 = $setup->getConnection()->select()->from($tableName)->where('id = 2');
40+
41+
$row2 = $this->setup->getConnection()->fetchOne($select2);
42+
43+
var_dump($row2);
44+
}
45+
}
46+
}

Setup/UpgradeSchema.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace PCAPredict\Tag\Setup;
4+
5+
use Magento\Framework\Setup\UpgradeSchemaInterface;
6+
use Magento\Framework\Setup\ModuleContextInterface;
7+
use Magento\Framework\Setup\SchemaSetupInterface;
8+
use Magento\Framework\DB\Ddl\Table;
9+
10+
// Upgrade will only trigger if the setup_version in the module.xml is increased.
11+
class UpgradeSchema implements UpgradeSchemaInterface
12+
{
13+
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context){
14+
15+
$setup->startSetup();
16+
17+
if(!$context->getVersion()) {
18+
// No previous version found.
19+
}
20+
21+
if (version_compare($context->getVersion(), '2.0.7') < 0) {
22+
23+
// Get module table
24+
$tableName = $setup->getTable('pcapredict_tag_settingsdata');
25+
26+
// Check if the table already exists
27+
if ($setup->getConnection()->isTableExists($tableName) == true) {
28+
29+
// Alter the id name, to long for no reason at the moment.
30+
$setup->getConnection()->changeColumn($tableName, 'pcapredict_tag_settingsdata_id', 'id',
31+
[
32+
'type' => Table::TYPE_INTEGER,
33+
'nullable' => false,
34+
'identity' => true,
35+
'primary' => true,
36+
'unsigned' => true
37+
], false);
38+
39+
// Remove any columns we don't need.
40+
$setup->getConnection()->dropColumn($tableName, 'update_time');
41+
42+
// Add the version column so we can record what version of the app the creds were created from.
43+
// In UpgradeData we set this column to the current version.
44+
$setup->getConnection()->addColumn($tableName, 'module_version',
45+
[
46+
'type' => Table::TYPE_TEXT,
47+
'length' => 16,
48+
'nullable' => true,
49+
'comment' => 'Created With App Version'
50+
]);
51+
}
52+
}
53+
54+
$setup->endSetup();
55+
}
56+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
]
2020
},
2121
"type": "magento2-module",
22-
"version": "2.0.6",
22+
"version": "2.0.7",
2323
"authors": [
2424
{
2525
"name": "PCA Predict",

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="PCAPredict_Tag" setup_version="2.0.6">
3+
<module name="PCAPredict_Tag" setup_version="2.0.7">
44
<sequence>
55
<module name="Magento_Store"/>
66
</sequence>

0 commit comments

Comments
 (0)