-
Notifications
You must be signed in to change notification settings - Fork 174
[5.7] Consolidate processing of catalog pricing jobs #4072
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
Open
nfourtythree
wants to merge
19
commits into
5.7
Choose a base branch
from
nathaniel/pt-2823-5x-catalog-pricing-doesnt-update-for-purchasables-that-meet
base: 5.7
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
73c108e
WIP consolidate catalog pricing jobs
nfourtythree d0d83c7
Merge branch '5.x' into nathaniel/pt-2823-5x-catalog-pricing-doesnt-u…
nfourtythree d0dc031
Simplify consolidation code
nfourtythree 1ce41fa
Merge branch '5.x' into nathaniel/pt-2823-5x-catalog-pricing-doesnt-u…
nfourtythree 87b6c73
Merge branch '5.7' into nathaniel/pt-2823-5x-catalog-pricing-doesnt-u…
nfourtythree 1954beb
More tidying and changelog
nfourtythree 153b001
Fix install migration
nfourtythree 826ad9f
Make sure upgrade migration and install match
nfourtythree 99b8e57
rector tidy
nfourtythree 5494520
Merge branch '5.7' into nathaniel/pt-2823-5x-catalog-pricing-doesnt-u…
nfourtythree 8513bac
Fix change of rule IDs not being queued
nfourtythree 40de3f2
Tweak method names
nfourtythree 5b731f8
Initialise variables early to make sure they exist
nfourtythree dcd4bc2
Fix queuing of IDs
nfourtythree 50832fd
Merge branch 'nathaniel/pt-2823-5x-catalog-pricing-doesnt-update-for-…
nfourtythree feee469
Throw on mutex failure
nfourtythree fae1fc9
Merge branch 'nathaniel/pt-2823-5x-catalog-pricing-doesnt-update-for-…
nfourtythree 0a82a27
Add test and fixes
nfourtythree 2443f55
fix cs
nfourtythree File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| # WIP Release Notes for Craft Commerce 5.7 | ||
|
|
||
| ## System | ||
| ### Extensibility | ||
| - Added `craft\commerce\db\Table::CATALOG_PRICING_QUEUE`. | ||
| - Added `craft\commerce\records\CatalogPricingQueue`. | ||
| - Added `craft\commerce\services\CatalogPricing::reserveCatalogPricingQueueRow()`. | ||
| - Added `craft\commerce\services\CatalogPricing::releaseCatalogPricingQueueRowById()`. | ||
| - Added `craft\commerce\services\CatalogPricing::deleteCatalogPricingQueueRowById()`. | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/migrations/m260407_000000_add_catalog_pricing_queue_table.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| namespace craft\commerce\migrations; | ||
|
|
||
| use craft\commerce\db\Table; | ||
| use craft\commerce\records\CatalogPricingQueue; | ||
| use craft\db\Migration; | ||
|
|
||
| /** | ||
| * m260407_000000_add_catalog_pricing_queue_table migration. | ||
| */ | ||
| class m260407_000000_add_catalog_pricing_queue_table extends Migration | ||
| { | ||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function safeUp(): bool | ||
| { | ||
| if (!$this->db->tableExists(Table::CATALOG_PRICING_QUEUE)) { | ||
| $this->createTable(Table::CATALOG_PRICING_QUEUE, [ | ||
| 'id' => $this->primaryKey(), | ||
| 'storeId' => $this->integer(), | ||
| 'type' => $this->enum('type', [CatalogPricingQueue::TYPE_PURCHASABLE, CatalogPricingQueue::TYPE_RULE])->notNull(), | ||
| 'ids' => $this->mediumText(), | ||
| 'reserved' => $this->boolean()->notNull()->defaultValue(false), | ||
| 'dateCreated' => $this->dateTime()->notNull(), | ||
| 'dateUpdated' => $this->dateTime()->notNull(), | ||
| 'uid' => $this->uid(), | ||
| ]); | ||
| } | ||
|
|
||
| $this->createIndexIfMissing(Table::CATALOG_PRICING_QUEUE, 'reserved', false); | ||
| $this->createIndexIfMissing(Table::CATALOG_PRICING_QUEUE, ['storeId', 'type', 'reserved'], false); | ||
| $this->addForeignKey(null, Table::CATALOG_PRICING_QUEUE, ['storeId'], Table::STORES, ['id'], 'CASCADE', 'CASCADE'); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function safeDown(): bool | ||
| { | ||
| echo "m260407_000000_add_catalog_pricing_queue_table cannot be reverted.\n"; | ||
| return false; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| <?php | ||
| /** | ||
| * @link https://craftcms.com/ | ||
| * @copyright Copyright (c) Pixel & Tonic, Inc. | ||
| * @license https://craftcms.github.io/license/ | ||
| */ | ||
|
|
||
| namespace craft\commerce\records; | ||
|
|
||
| use craft\commerce\db\Table; | ||
| use craft\db\ActiveRecord; | ||
| use craft\helpers\Json; | ||
| use yii\db\ActiveQueryInterface; | ||
|
|
||
| /** | ||
| * Catalog Pricing Queue record. | ||
| * | ||
| * @property int $id | ||
| * @property int|null $storeId | ||
| * @property string $type | ||
| * @property array|null $ids | ||
| * @property bool $reserved | ||
| * @property \DateTime $dateCreated | ||
| * @property \DateTime $dateUpdated | ||
| * @property string $uid | ||
| * @author Pixel & Tonic, Inc. <support@pixelandtonic.com> | ||
| * @since 5.7.0 | ||
| */ | ||
| class CatalogPricingQueue extends ActiveRecord | ||
| { | ||
| /** | ||
| * Row type for purchasable-ID-based catalog pricing work. | ||
| */ | ||
| public const TYPE_PURCHASABLE = 'purchasable'; | ||
|
|
||
| /** | ||
| * Row type for rule-ID-based (or full-regeneration) catalog pricing work. | ||
| */ | ||
| public const TYPE_RULE = 'rule'; | ||
|
|
||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public static function tableName(): string | ||
| { | ||
| return Table::CATALOG_PRICING_QUEUE; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the decoded IDs array from the JSON column value. | ||
| * | ||
| * @return array|null | ||
| */ | ||
| public function getIds(): ?array | ||
| { | ||
| $raw = $this->getAttribute('ids'); | ||
|
|
||
| if ($raw === null || $raw === '') { | ||
| return null; | ||
| } | ||
|
|
||
| $decoded = Json::decodeIfJson($raw); | ||
|
|
||
| return is_array($decoded) ? $decoded : null; | ||
| } | ||
|
|
||
| /** | ||
| * Encodes the IDs array to JSON and stores it in the column. | ||
| * | ||
| * @param array|null $ids | ||
| */ | ||
| public function setIds(?array $ids): void | ||
| { | ||
| $this->setAttribute('ids', $ids !== null ? Json::encode($ids) : null); | ||
| } | ||
|
|
||
| /** | ||
| * @return ActiveQueryInterface | ||
| */ | ||
| public function getStore(): ActiveQueryInterface | ||
| { | ||
| return $this->hasOne(Store::class, ['id' => 'storeId']); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.