Class: Spree::MaintenanceTasks::Upgrade::BackfillOrderMarkets
- Inherits:
-
Spree::MaintenanceTask
- Object
- Spree::MaintenanceTask
- Spree::MaintenanceTasks::Upgrade::BackfillOrderMarkets
- Defined in:
- app/maintenance_tasks/spree/maintenance_tasks/upgrade/backfill_order_markets.rb
Overview
5.6 → 6.0: market is mandatory on orders in Spree 6, and orders placed before markets existed carry NULLs. Each order takes its own store's default market, so the walk is per order rather than one UPDATE per store — that is what gives the run a cursor to resume from and a progress bar to watch on a catalog-sized table.
Orders whose store has no default market are counted and left alone; there is nothing to assign, and failing the run would strand every other store's orders behind them.
Constant Summary
Constants inherited from Spree::MaintenanceTask
Spree::MaintenanceTask::DEFAULT_BATCH_SIZE, Spree::MaintenanceTask::MAX_RUN_TIME, Spree::MaintenanceTask::RAKE_LOAD_LOCK
Instance Attribute Summary
Attributes inherited from Spree::MaintenanceTask
Instance Method Summary collapse
Methods inherited from Spree::MaintenanceTask
#after_complete, api_type_for, collection_batch_size, #count, #dry_run?, find_by_api_type, find_registered, #invoke_rake_task, no_collection, #no_collection?, #rake_file_defining, registered_classes, supports_dry_run, #tallies, #tally
Methods included from ApiTyped
#api_type, api_type_for, #api_typed_family, class_name_for, find, registered_class
Instance Method Details
#collection ⇒ Object
17 18 19 |
# File 'app/maintenance_tasks/spree/maintenance_tasks/upgrade/backfill_order_markets.rb', line 17 def collection Spree::Order.unscoped.where(market_id: nil).order(:id) end |
#process(order) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/maintenance_tasks/spree/maintenance_tasks/upgrade/backfill_order_markets.rb', line 21 def process(order) market_id = default_market_id_for(order.store_id) if market_id.nil? tally(:skipped_no_default_market) return end return tally(:would_update) if dry_run? order.update_columns(market_id: market_id, updated_at: Time.current) tally(:updated) end |