Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #25 #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
<?php
<?php

namespace PCAPredict\Tag\Setup;

use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;

// Upgrade will only trigger if the setup_version in the module.xml is increased.
class UpgradeData implements UpgradeDataInterface {

public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context ) {

class UpgradeData implements UpgradeDataInterface
{

public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{

// Take all current records and set the current version of the app as the module_version.
// We now fetch a record based on the last created time and not an id.
// This means any customer with multiple rows can expire all the session keys and will fix the bug where it was looking for a row with a particular id.
if (version_compare($context->getVersion(), '2.0.7') < 0) {

// This means any customer with multiple rows can expire all the session keys and will fix the bug where it was
// looking for a row with a particular id.
if (version_compare($context->getVersion(), '2.0.7', '<')) {
$tableName = $setup->getTable('pcapredict_tag_settingsdata');

$select = $setup->getConnection()->select()->from($tableName);

$result = $setup->getConnection()->fetchAll($select);

foreach ($result as $row)
{
foreach ($result as $row) {
// Set the new module_version column with the current of the app.
// Because we do not know what vesion they logged in under set to the last version will have to do.
$setup->updateTableRow($tableName, 'pcapredict_tag_settingsdata_id', $row['pcapredict_tag_settingsdata_id'], 'module_version', $context->getVersion());
$setup->updateTableRow(
$tableName,
'pcapredict_tag_settingsdata_id',
$row['pcapredict_tag_settingsdata_id'],
'module_version',
$context->getVersion()
);
}
}
}
}
}
37 changes: 17 additions & 20 deletions Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,42 @@

namespace PCAPredict\Tag\Setup;

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Setup\UpgradeSchemaInterface;

// Upgrade will only trigger if the setup_version in the module.xml is increased.
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context){
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();

if(!$context->getVersion()) {
// No previous version found.
}

if (version_compare($context->getVersion(), '2.0.7') < 0) {

if (version_compare($context->getVersion(), '2.0.7', '<')) {
// Get module table
$tableName = $setup->getTable('pcapredict_tag_settingsdata');

// Check if the table already exists
if ($setup->getConnection()->isTableExists($tableName) == true) {

if ($setup->getConnection()->isTableExists($tableName) === true) {
// Remove any columns we don't need.
$setup->getConnection()->dropColumn($tableName, 'update_time');

// Add the version column so we can record what version of the app the creds were created from.
// In UpgradeData we set this column to the current version.
$setup->getConnection()->addColumn($tableName, 'module_version',
[
'type' => Table::TYPE_TEXT,
'length' => 16,
'nullable' => true,
'comment' => 'Created With App Version'
]);
$setup->getConnection()->addColumn(
$tableName,
'module_version',
[
'type' => Table::TYPE_TEXT,
'length' => 16,
'nullable' => true,
'comment' => 'Created With App Version',
]
);
}
}

$setup->endSetup();
}
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
},
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0|~7.1.0"
"php": "~5.5.0|~5.6.0|~7.0.0|~7.1.0|~7.2.0|~7.3.0"
},
"autoload": {
"psr-4": {
Expand All @@ -19,7 +19,7 @@
]
},
"type": "magento2-module",
"version": "2.0.7",
"version": "2.0.7.1",
"authors": [
{
"name": "PCA Predict",
Expand Down