Skip to content

Commit

Permalink
upgrade speedup
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Oct 6, 2023
1 parent 04d8249 commit e71e766
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class Plugin extends BasePlugin
public const EDITION_LITE = 'lite';
public const EDITION_PRO = 'pro';

public bool $isUpgradingToCommerce4 = false;

public static function config(): array
{
return [
Expand Down Expand Up @@ -209,7 +211,7 @@ public static function editions(): array
/**
* @inheritDoc
*/
public string $schemaVersion = '4.2.6';
public string $schemaVersion = '4.2.7';

/**
* @inheritdoc
Expand Down
1 change: 1 addition & 0 deletions src/console/controllers/UpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ private function _getOrphanedCustomerIds(): array
*/
public function init(): void
{
Plugin::getInstance()->isUpgradingToCommerce4 = true;
$this->_allowAdminChanges = Craft::$app->getConfig()->getGeneral()->allowAdminChanges;
$this->_addressFieldLayout = Craft::$app->getAddresses()->getLayout();
parent::init();
Expand Down
2 changes: 2 additions & 0 deletions src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,8 @@ public function createIndexes(): void
$this->createIndex(null, Table::ORDERS, 'shippingAddressId', false);
$this->createIndex(null, Table::ORDERS, 'estimatedBillingAddressId', false);
$this->createIndex(null, Table::ORDERS, 'estimatedShippingAddressId', false);
$this->createIndex(null, Table::ORDERS, 'sourceBillingAddressId', false);
$this->createIndex(null, Table::ORDERS, 'sourceShippingAddressId', false);
$this->createIndex(null, Table::ORDERS, 'gatewayId', false);
$this->createIndex(null, Table::ORDERS, 'customerId', false);
$this->createIndex(null, Table::ORDERS, 'orderStatusId', false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace craft\commerce\migrations;

use Craft;
use craft\commerce\db\Table;
use craft\db\Migration;

/**
* m231006_034833_add_indexes_for_source_address_on_order migration.
*/
class m231006_034833_add_indexes_for_source_address_on_order extends Migration
{
/**
* @inheritdoc
*/
public function safeUp(): bool
{
$this->createIndex(null, Table::ORDERS, 'sourceBillingAddressId', false);
$this->createIndex(null, Table::ORDERS, 'sourceShippingAddressId', false);

return true;
}

/**
* @inheritdoc
*/
public function safeDown(): bool
{
echo "m231006_034833_add_indexes_for_source_address_on_order cannot be reverted.\n";
return false;
}
}
5 changes: 5 additions & 0 deletions src/services/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Craft;
use craft\commerce\db\Table;
use craft\commerce\elements\Order;
use craft\commerce\Plugin;
use craft\db\Query;
use craft\elements\Address;
use craft\elements\User;
Expand Down Expand Up @@ -194,6 +195,10 @@ public function beforeDeleteUserHandler(ModelEvent $event): void
*/
public function afterSaveAddressHandler(ModelEvent $event): void
{
if (Plugin::getInstance()->isUpgradingToCommerce4) {
return;
}

/** @var Address $address */
$address = $event->sender;
if ($address->getIsDraft()) {
Expand Down

0 comments on commit e71e766

Please sign in to comment.