2018-07-18 12:03:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-28 02:26:52 -05:00
|
|
|
module WikiPages
|
|
|
|
class UpdateService < WikiPages::BaseService
|
|
|
|
def execute(page)
|
2020-03-24 08:09:42 -04:00
|
|
|
# this class is not thread safe!
|
|
|
|
@old_slug = page.slug
|
|
|
|
|
2017-07-23 04:19:10 -04:00
|
|
|
if page.update(@params)
|
2020-03-24 08:09:42 -04:00
|
|
|
execute_hooks(page)
|
2020-08-27 11:10:21 -04:00
|
|
|
ServiceResponse.success(payload: { page: page })
|
|
|
|
else
|
|
|
|
ServiceResponse.error(
|
2020-09-08 11:08:41 -04:00
|
|
|
message: _('Could not update wiki page'),
|
2020-08-27 11:10:21 -04:00
|
|
|
payload: { page: page }
|
|
|
|
)
|
2016-02-28 02:26:52 -05:00
|
|
|
end
|
|
|
|
end
|
2020-03-24 08:09:42 -04:00
|
|
|
|
|
|
|
def usage_counter_action
|
|
|
|
:update
|
|
|
|
end
|
|
|
|
|
|
|
|
def external_action
|
|
|
|
'update'
|
|
|
|
end
|
|
|
|
|
|
|
|
def event_action
|
2020-05-28 11:08:02 -04:00
|
|
|
:updated
|
2020-03-24 08:09:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def slug_for_page(page)
|
|
|
|
@old_slug.presence || super
|
|
|
|
end
|
2016-02-28 02:26:52 -05:00
|
|
|
end
|
|
|
|
end
|