forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix shortlink references (decidim#12004)
* Fix shortlink references * Add rake task to fix data * Add release notes
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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
22 changes: 22 additions & 0 deletions
22
decidim-core/lib/tasks/upgrade/decidim_fix_short_url_resolver.rake
This file contains 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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
namespace :decidim do | ||
namespace :upgrade do | ||
desc "Fix wrongly mapped short links components" | ||
task fix_short_urls: :environment do | ||
logger = Logger.new($stdout) | ||
logger.info("Fixing wrongly mapped short links...") | ||
|
||
Decidim::ShortLink.where(target_type: "Decidim::Component").find_each do |short_url| | ||
real_component = Decidim::Component.find_by(id: short_url.target_id) | ||
|
||
next if real_component.nil? | ||
next if short_url.mounted_engine_name == real_component.mounted_engine | ||
|
||
logger.info("Fixing #{short_url.identifier}: #{short_url.mounted_engine_name} to #{real_component.mounted_engine}") | ||
short_url.update(mounted_engine_name: real_component.mounted_engine) | ||
end | ||
logger.info("Done fixing wrongly mapped short links.") | ||
end | ||
end | ||
end |
This file contains 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