diff --git a/app/Console/Commands/Sync.php b/app/Console/Commands/Sync.php index 42cce2b6ad..8154e03e52 100644 --- a/app/Console/Commands/Sync.php +++ b/app/Console/Commands/Sync.php @@ -13,9 +13,20 @@ class Sync extends Command /** * The name and signature of the console command. * + * The placeholder %s will be filled by the constructor with the default + * value from the user configuration. + * * @var string */ - protected $signature = 'lychee:sync {dir : directory to sync} {--album_id=0 : Album ID to import to} {--owner_id=0 : Owner ID of imported photos} {--resync_metadata : Re-sync metadata of existing files}'; + protected $signature = + 'lychee:sync ' . + '{dir : directory to sync} ' . + '{--album_id=0 : Album ID to import to} ' . + '{--owner_id=0 : Owner ID of imported photos} ' . + '{--resync_metadata : Re-sync metadata of existing files} ' . + '{--delete_imported=%s : Delete the original files} ' . + '{--import_via_symlink=%s : Imports photos from via a symlink instead of copying the files} ' . + '{--skip_duplicates=%s : Don\'t Skip photos and albums if they already exist in the gallery}'; /** * The console command description. @@ -24,6 +35,18 @@ class Sync extends Command */ protected $description = 'Sync a directory to lychee'; + public function __construct() + { + // Fill signature with default values from user configuration + $this->signature = sprintf( + $this->signature, + Configs::get_value('delete_imported', '0'), + Configs::get_value('import_via_symlink', '0'), + Configs::get_value('skip_duplicates', '0') + ); + parent::__construct(); + } + /** * Execute the console command. * @@ -31,7 +54,6 @@ class Sync extends Command */ public function handle(Exec $exec) { - $this->info('Start syncing.'); $directory = $this->argument('dir'); $owner_id = (int) $this->option('owner_id'); // in case no ID provided -> import as root user $album_id = (int) $this->option('album_id'); // in case no ID provided -> import to root folder @@ -39,13 +61,22 @@ public function handle(Exec $exec) // Enable CLI formatting of status $exec->statusCLIFormatting = true; $exec->memCheck = false; - $exec->delete_imported = false; // we want to sync -> do not delete imported files - $exec->import_via_symlink = (Configs::get_value('import_via_symlink', '0') === '1'); - $exec->skip_duplicates = true; $exec->resync_metadata = $this->option('resync_metadata'); + $exec->delete_imported = $this->option('delete_imported') === '1'; + $exec->import_via_symlink = $this->option('import_via_symlink') === '1'; + $exec->skip_duplicates = $this->option('skip_duplicates') === '1'; + + if ($exec->import_via_symlink && $exec->delete_imported) { + $this->error('The settings for import via symbolic links and deletion of imported files are conflicting'); + $this->info(' Use --import_via_symlink={0|1} and --delete-imported={0|1} explicitly to apply a conflict-free setting'); + + return 1; + } AccessControl::log_as_id($owner_id); + $this->info('Start syncing.'); + try { $exec->do($directory, $album_id); } catch (Exception $e) {