Skip to content

Commit

Permalink
Merge pull request #14730 from opf/impl/onedrive-ampf-cron-job
Browse files Browse the repository at this point in the history
CronJob enabling AMPF for OneDrive
  • Loading branch information
mereghost committed Feb 7, 2024
2 parents 82202e2 + 6aa862d commit e3161f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions modules/storages/app/models/storages/project_storage.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 the OpenProject GmbH
Expand Down Expand Up @@ -52,10 +54,10 @@ class Storages::ProjectStorage < ApplicationRecord

scope :automatic, -> { where(project_folder_mode: 'automatic') }
scope :active, -> { joins(:project).where(project: { active: true }) }
scope :active_nextcloud_automatically_managed, -> do
scope :active_automatically_managed, -> do
automatic
.active
.where(storages: Storages::NextcloudStorage.automatic_management_enabled)
.where(storages: Storages::Storage.automatic_management_enabled)
end

def automatic_management_possible?
Expand Down
Expand Up @@ -37,7 +37,7 @@ class ManageNextcloudIntegrationCronJob < Cron::CronJob
self.cron_expression = '*/5 * * * *'

def self.ensure_scheduled!
if ::Storages::ProjectStorage.active_nextcloud_automatically_managed.exists?
if ::Storages::ProjectStorage.active_automatically_managed.exists?
super
else
remove
Expand Down
Expand Up @@ -39,8 +39,8 @@ def perform
timeout_seconds: 0,
transaction: false
) do
::Storages::NextcloudStorage.automatic_management_enabled.includes(:oauth_client).find_each do |storage|
result = NextcloudGroupFolderPropertiesSyncService.call(storage)
::Storages::Storage.automatic_management_enabled.includes(:oauth_client).find_each do |storage|
result = service_for(storage).call(storage)
result.match(
on_success: ->(_) do
storage.mark_as_healthy
Expand All @@ -53,5 +53,14 @@ def perform
true
end
end

private

def service_for(storage)
return NextcloudGroupFolderPropertiesSyncService if storage.provider_type_nextcloud?
return OneDriveManagedFolderSyncService if storage.provider_type_one_drive?

raise 'Unknown Storage'
end
end
end

0 comments on commit e3161f6

Please sign in to comment.