debian-mirror-gitlab/app/services/wiki_pages/update_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
968 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
module WikiPages
class UpdateService < WikiPages::BaseService
2021-06-08 01:23:25 +05:30
UpdateError = Class.new(StandardError)
2016-06-02 11:05:42 +05:30
def execute(page)
2020-04-22 19:07:51 +05:30
# this class is not thread safe!
@old_slug = page.slug
2021-09-30 23:02:18 +05:30
if page.wiki.capture_git_error(event_action) { page.update(@params) }
2020-04-22 19:07:51 +05:30
execute_hooks(page)
2020-11-24 15:15:51 +05:30
ServiceResponse.success(payload: { page: page })
else
2021-06-08 01:23:25 +05:30
raise UpdateError, s_('Could not update wiki page')
2016-06-02 11:05:42 +05:30
end
2021-06-08 01:23:25 +05:30
rescue UpdateError, WikiPage::PageChangedError, WikiPage::PageRenameError => e
page.update_attributes(@params) # rubocop:disable Rails/ActiveRecordAliases
ServiceResponse.error(
message: e.message,
payload: { page: page }
)
2016-06-02 11:05:42 +05:30
end
2020-04-22 19:07:51 +05:30
def usage_counter_action
:update
end
def external_action
'update'
end
def event_action
2020-06-23 00:09:42 +05:30
:updated
2020-04-22 19:07:51 +05:30
end
def slug_for_page(page)
@old_slug.presence || super
end
2016-06-02 11:05:42 +05:30
end
end