Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix export job

Oliver Güntherc16f03407b8f
diff --git a/app/services/base_services/base_contracted.rb b/app/services/base_services/base_contracted.rb
index 91af3410976..25dbc8bf12a 100644
--- a/app/services/base_services/base_contracted.rb
+++ b/app/services/base_services/base_contracted.rb
@@ -29,7 +29,7 @@
#++
module BaseServices
-class BaseContracted < BaseCallable
+ class BaseContracted < BaseCallable
include Contracted
include Shared::ServiceContext
@@ -92,6 +92,7 @@ class BaseContracted < BaseCallable
# nothing for now but subclasses can override
call
end
+
alias_method :after_save, :after_perform
def persist(call)
diff --git a/app/workers/backup_job.rb b/app/workers/backup_job.rb
index b5e76b448ba..964d5229ee2 100644
--- a/app/workers/backup_job.rb
+++ b/app/workers/backup_job.rb
@@ -120,17 +120,24 @@ class BackupJob < ::ApplicationJob
def store_backup(file_name, backup:, user:)
File.open(file_name) do |file|
- attachment = Attachments::CreateService
- .new(backup, author: user)
- .call(uploaded_file: file, description: 'OpenProject backup')
-
- download_url = ::API::V3::Utilities::PathHelper::ApiV3Path.attachment_content(attachment.id)
+ call = Attachments::CreateService
+ .new(user: user)
+ .call(container: backup, filename: file_name, file: file, description: 'OpenProject backup')
+
+ call.on_success do
+ download_url = ::API::V3::Utilities::PathHelper::ApiV3Path.attachment_content(call.result.id)
+
+ upsert_status(
+ status: :success,
+ message: I18n.t('export.succeeded'),
+ payload: download_payload(download_url)
+ )
+ end
- upsert_status(
- status: :success,
- message: I18n.t('export.succeeded'),
- payload: download_payload(download_url)
- )
+ call.on_failure do
+ upsert_status status: :failure,
+ message: I18n.t('export.failed', message: call.message)
+ end
end
end