Skip to content

Commit

Permalink
Keep estimated addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Jul 21, 2023
1 parent e448894 commit 76e85b8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/console/controllers/UpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use craft\commerce\db\Table;
use craft\commerce\elements\conditions\addresses\PostalCodeFormulaConditionRule;
use craft\commerce\Plugin;
use craft\commerce\records\Customer;
use craft\commerce\records\Store;
use craft\db\Query;
use craft\db\Table as CraftTable;
Expand All @@ -37,7 +36,6 @@
use craft\models\FieldLayout;
use craft\validators\HandleValidator;
use Throwable;
use yii\base\InvalidArgumentException;
use yii\console\ExitCode;
use yii\db\Exception;
use yii\db\Expression;
Expand Down Expand Up @@ -881,14 +879,28 @@ private function _migrateAddresses()
FROM $ordersTable AS o2
WHERE o2.v3shippingAddressId = a.id
)
AND NOT EXISTS (
SELECT 1
FROM $ordersTable AS o2
WHERE o2.v3estimatedBillingAddressId = a.id
)
AND NOT EXISTS (
SELECT 1
FROM $ordersTable AS o2
WHERE o2.v3shippingAddressId = a.id
)
AND NOT EXISTS (
SELECT 1
FROM $ordersTable AS o2
WHERE o2.v3estimatedShippingAddressId = a.id
)
AND NOT EXISTS (
SELECT 1
FROM $customersAddressesTable AS ca
WHERE ca.addressId = a.id
);
SQL;

$deletableAddresses = Craft::$app->getDb()->createCommand($sql);
$deletableAddressesIds = Craft::$app->getDb()->createCommand($sql)->queryColumn();
$deleted = Craft::$app->getDb()->createCommand()->delete($addressesTable, ['id' => $deletableAddressesIds])->execute();

Expand Down

0 comments on commit 76e85b8

Please sign in to comment.