mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 23:46:21 +08:00
6c91148db8
* DEV: Implement uploads command entrypoint - Setup Thor UploadsCommand for CLI - First pass at modularizing various parts of the exising `uploads_import` script * DEV: First attempt at modularizing missing uploads fixer task Move missing upload fix to a dedicated uploads task implementation unit * DEV: First attempt at modularizing missing uploads uploader task Move uploader to a dedicated uploads task implementation unit * DEV: First attempt at modularizing missing uploads optimizer task Move optimizer to a dedicated uploads task implementation unit * DEV: Various follow up fixes to get optimization working - Start threads early - Improve "log" message formatting - Add missing `copy_to_tempfile` method on "uploader" task * DEV: Refactor a bit more Deduplicate and move most of threading premitives to base task as-is * DEV: Remove redundant condition in uploads db migration * DEV: More deduplication Move task retry logic to base class and tidy up other implementation details carried over from the existing script
50 lines
1.3 KiB
Ruby
50 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Migrations::CLI::UploadCommand
|
|
def self.included(thor)
|
|
thor.class_eval do
|
|
desc "upload", "Upload media uploads"
|
|
option :settings,
|
|
type: :string,
|
|
desc: "Uploads settings file path",
|
|
default: "./migrations/config/upload.yml",
|
|
aliases: "-s",
|
|
banner: "path"
|
|
option :fix_missing, type: :boolean, desc: "Fix missing uploads"
|
|
option :optimize, type: :boolean, desc: "Optimize uploads"
|
|
def upload
|
|
puts "Starting uploads..."
|
|
|
|
validate_settings_file!
|
|
settings = load_settings
|
|
|
|
::Migrations::Uploader::Uploads.perform!(settings)
|
|
|
|
puts ""
|
|
end
|
|
|
|
private
|
|
|
|
def load_settings
|
|
settings = ::Migrations::SettingsParser.parse!(options.settings)
|
|
merge_settings_from_cli_args!(settings)
|
|
|
|
settings
|
|
end
|
|
|
|
def merge_settings_from_cli_args!(settings)
|
|
settings[:fix_missing] = options.fix_missing if options.fix_missing.present?
|
|
settings[:create_optimized_images] = options.optimize if options.optimize.present?
|
|
end
|
|
|
|
def validate_settings_file!
|
|
path = options.settings
|
|
|
|
if !File.exist?(path)
|
|
raise ::Migrations::NoSettingsFound, "Settings file not found: #{path}"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|