Skip to content
This repository has been archived by the owner on Apr 22, 2019. It is now read-only.

Feature/421 48 add support for split db #58

Merged
merged 5 commits into from
Apr 18, 2017
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 1.0.0 (2017-04-14)

* Add support for [Magento Enterprise's split database mode](http://devdocs.magento.com/guides/v2.1/config-guide/multi-master/multi-master.html) [#54](https://github.com/classyllama/ClassyLlama_AvaTax/issues/54)
* Refactor code to create AvaTax tables in the 'sales' database when running in split database mode
* Reference issue [#54](https://github.com/classyllama/ClassyLlama_AvaTax/issues/54) for additional notes and details

### 0.4.0 (2017-03-14)

* Add code to create new database tables dedicated to storing AvaTax data
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ This extension contains integration tests to verify the extension's functionalit

As of version 0.3.0 of this extension, this extension supported Magento 2.1.x (Community and Enterprise). Suppport for Magento 2.0.x was dropped as of version 0.3.0. See [this page](https://github.com/classyllama/ClassyLlama_AvaTax/releases) for a list of all releases.

As of version 1.0.0 of this extension, this extension supports [Magento Enterprise's split database mode](http://devdocs.magento.com/guides/v2.1/config-guide/multi-master/multi-master.html). Reference issue [#54](https://github.com/classyllama/ClassyLlama_AvaTax/issues/54) for additional notes and details.

# License

This project is licensed under the Open Software License 3.0 (OSL-3.0). See included LICENSE file for full text of OSL-3.0
23 changes: 15 additions & 8 deletions Setup/InstallSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
*/
class InstallSchema implements InstallSchemaInterface
{
/**
* Define connection name to connect to 'sales' database on split database install; falls back to default for a
* conventional install
* @var string
*/
private static $connectionName = 'sales';

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
Expand All @@ -38,7 +45,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
/**
* Create table 'avatax_log'
*/
$table = $installer->getConnection()
$table = $installer->getConnection(self::$connectionName)
->newTable(
$installer->getTable('avatax_log')
)
Expand Down Expand Up @@ -134,12 +141,12 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX]
)
->setComment('AvaTax Log Table');
$installer->getConnection()->createTable($table);
$installer->getConnection(self::$connectionName)->createTable($table);

/**
* Create table 'avatax_queue'
*/
$table = $installer->getConnection()
$table = $installer->getConnection(self::$connectionName)
->newTable(
$installer->getTable('avatax_queue')
)
Expand Down Expand Up @@ -268,12 +275,12 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
]
)
->setComment('AvaTax Queue Table');
$installer->getConnection()->createTable($table);
$installer->getConnection(self::$connectionName)->createTable($table);

/**
* Create table 'avatax_sales_invoice'
*/
$table = $setup->getConnection()
$table = $setup->getConnection(self::$connectionName)
->newTable(
$setup->getTable('avatax_sales_invoice')
)
Expand Down Expand Up @@ -348,12 +355,12 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
Table::ACTION_CASCADE
)
->setComment('AvaTax Sales Invoice Table');
$setup->getConnection()->createTable($table);
$setup->getConnection(self::$connectionName)->createTable($table);

/**
* Create table 'avatax_sales_creditmemo'
*/
$table = $setup->getConnection()
$table = $setup->getConnection(self::$connectionName)
->newTable(
$setup->getTable('avatax_sales_creditmemo')
)
Expand Down Expand Up @@ -428,7 +435,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
Table::ACTION_CASCADE
)
->setComment('AvaTax Sales Credit Memo Table');
$setup->getConnection()->createTable($table);
$setup->getConnection(self::$connectionName)->createTable($table);

$installer->endSetup();
}
Expand Down
41 changes: 26 additions & 15 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@

class UpgradeData implements UpgradeDataInterface
{
/**
* Define connection name to connect to 'sales' database on split database install; falls back to default for a
* conventional install
* @var string
*/
private static $connectionName = 'sales';

/**
* Upgrade scripts
*
Expand All @@ -20,15 +27,17 @@ class UpgradeData implements UpgradeDataInterface
*/
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
$setup->startSetup();
if (version_compare($context->getVersion(), '0.4.0', '<' )) {
if (version_compare($context->getVersion(), '1.0.0', '<' )) {

// Only copy data and drop columns from "sales_invoice" if the columns exist
if (
$setup->getConnection()->tableColumnExists('sales_invoice', 'avatax_is_unbalanced')
&& $setup->getConnection()->tableColumnExists('sales_invoice', 'base_avatax_tax_amount')
$setup->getConnection(self::$connectionName)
->tableColumnExists('sales_invoice', 'avatax_is_unbalanced')
&& $setup->getConnection(self::$connectionName)
->tableColumnExists('sales_invoice', 'base_avatax_tax_amount')
) {
// Copy any existing AvaTax data from core Invoice table into new AvaTax Invoice table
$select = $setup->getConnection()->select()
$select = $setup->getConnection(self::$connectionName)->select()
->from(
$setup->getTable('sales_invoice'),
[
Expand All @@ -37,7 +46,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
'base_avatax_tax_amount'
])
->where('base_avatax_tax_amount IS NOT NULL OR avatax_is_unbalanced IS NOT NULL');
$select = $setup->getConnection()->insertFromSelect(
$select = $setup->getConnection(self::$connectionName)->insertFromSelect(
$select,
$setup->getTable('avatax_sales_invoice'),
[
Expand All @@ -46,17 +55,17 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
'base_avatax_tax_amount'
]
);
$setup->getConnection()->query($select);
$setup->getConnection(self::$connectionName)->query($select);

// Drop "avatax_is_unbalanced" column from "sales_invoice" table
$setup->getConnection()
$setup->getConnection(self::$connectionName)
->dropColumn(
$setup->getTable('sales_invoice'),
'avatax_is_unbalanced'
);

// Drop "base_avatax_tax_amount" column from "sales_invoice" table
$setup->getConnection()
$setup->getConnection(self::$connectionName)
->dropColumn(
$setup->getTable('sales_invoice'),
'base_avatax_tax_amount'
Expand All @@ -65,11 +74,13 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface

// Only copy data and drop columns from "sales_creditmemo" if the columns exist
if (
$setup->getConnection()->tableColumnExists('sales_creditmemo', 'avatax_is_unbalanced')
&& $setup->getConnection()->tableColumnExists('sales_creditmemo', 'base_avatax_tax_amount')
$setup->getConnection(self::$connectionName)
->tableColumnExists('sales_creditmemo', 'avatax_is_unbalanced')
&& $setup->getConnection(self::$connectionName)
->tableColumnExists('sales_creditmemo', 'base_avatax_tax_amount')
) {
// Copy any existing AvaTax data from core Credit Memo table into new AvaTax Credit Memo table
$select = $setup->getConnection()->select()
$select = $setup->getConnection(self::$connectionName)->select()
->from(
$setup->getTable('sales_creditmemo'),
[
Expand All @@ -78,7 +89,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
'base_avatax_tax_amount'
])
->where('base_avatax_tax_amount IS NOT NULL OR avatax_is_unbalanced IS NOT NULL');
$select = $setup->getConnection()->insertFromSelect(
$select = $setup->getConnection(self::$connectionName)->insertFromSelect(
$select,
$setup->getTable('avatax_sales_creditmemo'),
[
Expand All @@ -87,17 +98,17 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
'base_avatax_tax_amount'
]
);
$setup->getConnection()->query($select);
$setup->getConnection(self::$connectionName)->query($select);

// Drop "avatax_is_unbalanced" column from "sales_creditmemo" table
$setup->getConnection()
$setup->getConnection(self::$connectionName)
->dropColumn(
$setup->getTable('sales_creditmemo'),
'avatax_is_unbalanced'
);

// Drop "base_avatax_tax_amount" column from "sales_creditmemo" table
$setup->getConnection()
$setup->getConnection(self::$connectionName)
->dropColumn(
$setup->getTable('sales_creditmemo'),
'base_avatax_tax_amount'
Expand Down
17 changes: 12 additions & 5 deletions Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
*/
class UpgradeSchema implements UpgradeSchemaInterface
{
/**
* Define connection name to connect to 'sales' database on split database install; falls back to default for a
* conventional install
* @var string
*/
private static $connectionName = 'sales';

/**
* {@inheritdoc}
*/
Expand All @@ -49,7 +56,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
);
}

if (version_compare($context->getVersion(), '0.4.0', '<')) {
if (version_compare($context->getVersion(), '1.0.0', '<')) {
/** As a part of the upgrade process for this revision, data is migrated from the sales_invoice and
* sales_creditmemo tables into the newly created tables above. After the data migration, the previously
* mentioned tables are altered to drop the now-unused columns in each (base_avatax_tax_amount and
Expand All @@ -59,7 +66,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
/**
* Create table 'avatax_sales_invoice'
*/
$table = $setup->getConnection()
$table = $setup->getConnection(self::$connectionName)
->newTable(
$setup->getTable('avatax_sales_invoice')
)
Expand Down Expand Up @@ -134,12 +141,12 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
Table::ACTION_CASCADE
)
->setComment('AvaTax Sales Invoice Table');
$setup->getConnection()->createTable($table);
$setup->getConnection(self::$connectionName)->createTable($table);

/**
* Create table 'avatax_sales_creditmemo'
*/
$table = $setup->getConnection()
$table = $setup->getConnection(self::$connectionName)
->newTable(
$setup->getTable('avatax_sales_creditmemo')
)
Expand Down Expand Up @@ -214,7 +221,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
Table::ACTION_CASCADE
)
->setComment('AvaTax Sales Credit Memo Table');
$setup->getConnection()->createTable($table);
$setup->getConnection(self::$connectionName)->createTable($table);
}
$setup->endSetup();
}
Expand Down
26 changes: 26 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,30 @@
</argument>
</arguments>
</type>
<!--
/**
* The following code will rewrite the connection name to connect to 'sales' database on split database install;
* falls back to default for a conventional install
*/
-->
<type name="ClassyLlama\AvaTax\Model\ResourceModel\CreditMemo">
<arguments>
<argument name="connectionName" xsi:type="string">sales</argument>
</arguments>
</type>
<type name="ClassyLlama\AvaTax\Model\ResourceModel\Invoice">
<arguments>
<argument name="connectionName" xsi:type="string">sales</argument>
</arguments>
</type>
<type name="ClassyLlama\AvaTax\Model\ResourceModel\Log">
<arguments>
<argument name="connectionName" xsi:type="string">sales</argument>
</arguments>
</type>
<type name="ClassyLlama\AvaTax\Model\ResourceModel\Queue">
<arguments>
<argument name="connectionName" xsi:type="string">sales</argument>
</arguments>
</type>
</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<!-- The setup_version attribute is unrelated to the module version stored in composer.json -->
<module name="ClassyLlama_AvaTax" setup_version="0.4.0">
<module name="ClassyLlama_AvaTax" setup_version="1.0.0">
<sequence>
<module name="Magento_Checkout"/>
<module name="Magento_Customer"/>
Expand Down