Class: WikiPages::UpdateService

Inherits:
BaseService show all
Defined in:
app/services/wiki_pages/update_service.rb

Constant Summary collapse

UpdateError =
Class.new(StandardError)

Instance Attribute Summary

Attributes inherited from BaseContainerService

#container, #current_user, #group, #params, #project

Instance Method Summary collapse

Methods inherited from BaseContainerService

#group_container?, #initialize, #namespace_container?, #project_container?, #project_group

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseContainerService

Instance Method Details

#event_actionObject



34
35
36
# File 'app/services/wiki_pages/update_service.rb', line 34

def event_action
  :updated
end

#execute(page) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/wiki_pages/update_service.rb', line 7

def execute(page)
  # this class is not thread safe!
  @old_slug = page.slug

  if page.wiki.capture_git_error(event_action) { page.update(@params) }
    execute_hooks(page)
    ServiceResponse.success(payload: { page: page })
  else
    raise UpdateError, _('Could not update wiki page')
  end
rescue UpdateError, WikiPage::PageChangedError, WikiPage::PageRenameError => e
  page.update_attributes(@params) # rubocop:disable Rails/ActiveRecordAliases

  ServiceResponse.error(
    message: e.message,
    payload: { page: page }
  )
end

#external_actionObject



30
31
32
# File 'app/services/wiki_pages/update_service.rb', line 30

def external_action
  'update'
end

#slug_for_page(page) ⇒ Object



38
39
40
# File 'app/services/wiki_pages/update_service.rb', line 38

def slug_for_page(page)
  @old_slug.presence || super
end

#usage_counter_actionObject



26
27
28
# File 'app/services/wiki_pages/update_service.rb', line 26

def usage_counter_action
  :update
end