Class: Hyrax::Transactions::Steps::SyncRedirectPaths

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/transactions/steps/sync_redirect_paths.rb

Overview

A dry-transaction step that mirrors a saved resource's redirects entries into the hyrax_redirect_paths redirects table. The unique index on from_path enforces global uniqueness at the DB level — if a concurrent save already claimed a path, the insert raises ActiveRecord::RecordNotUnique and this step returns Failure, which short-circuits the enclosing transaction.

Every row carries the resource's canonical UUID URL in permalink_path. Column semantics:

  • from_path — the URL the visitor entered (an alias or the UUID URL itself).
  • to_path — the URL the address bar should display after the resolver routes the request. For the display row, equals its own from_path (the visitor stays at the display URL). For non-display rows, points at the display row's from_path (the visitor lands at the user-facing display URL). When no entry is marked, every alias's to_path is the UUID URL.
  • permalink_path — the resource's canonical UUID URL. Constant per resource across all rows.

When a display URL is set, the sync step also writes an extra row with from_path = permalink_path so visitors hitting the bare UUID URL are routed to the display alias.

No-op when the redirects feature is off (config or Flipflop) or when the resource doesn't carry the redirects attribute.

See documentation/redirects.md.

Since:

  • 2.4.0

Instance Method Summary collapse

Instance Method Details

#call(object) ⇒ Dry::Monads::Result

Parameters:

  • object (Valkyrie::Resource)

    the saved resource (must have an id)

Returns:

  • (Dry::Monads::Result)

Since:

  • 2.4.0



41
42
43
44
45
46
47
48
49
50
# File 'lib/hyrax/transactions/steps/sync_redirect_paths.rb', line 41

def call(object)
  return Success(object) unless syncable?(object)
  replace_rows(object, build_rows(object))
  Success(object)
rescue ActiveRecord::RecordNotUnique => e
  Failure([:redirect_path_collision, e.message])
rescue ActiveRecord::StatementInvalid => e
  Hyrax.logger.error("[redirects] sync_redirect_paths failed: #{e.message}")
  Failure([:redirect_path_sync_error, e.message])
end