adds option to only read albums from the server and not creating new ones (helps during init sync with existing piwigo setup)
This commit is contained in:
parent
2fe5270d93
commit
ee2e9e3b77
@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PiwigoDirectorySync.Infrastructure;
|
||||
using PiwigoDirectorySync.Services;
|
||||
@ -23,7 +24,7 @@ internal class SyncAlbumsCommand : CancellableAsyncCommand<SyncAlbumsCommand.Syn
|
||||
|
||||
var stopWatch = Stopwatch.StartNew();
|
||||
|
||||
await _albumSynchronizer.SynchronizeAlbums(settings.PiwigoServerId, cancellationToken);
|
||||
await _albumSynchronizer.SynchronizeAlbums(settings.PiwigoServerId, settings.CreateAlbumsOnServer, cancellationToken);
|
||||
|
||||
stopWatch.Stop();
|
||||
_logger.LogInformation("Synchronized all albums with piwigo server {SettingsPiwigoServerId} in {ElapsedTotalSeconds} seconds", settings.PiwigoServerId,
|
||||
@ -34,5 +35,8 @@ internal class SyncAlbumsCommand : CancellableAsyncCommand<SyncAlbumsCommand.Syn
|
||||
|
||||
internal class SyncAlbumsSettings : CommonCommandSettings
|
||||
{
|
||||
[CommandOption("-c|--create-albums")]
|
||||
[DefaultValue(true)]
|
||||
public bool CreateAlbumsOnServer { get; set; }
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ internal class SyncFullCommand : CancellableAsyncCommand<SyncFullCommand.SyncFul
|
||||
await ScanCommand.ScanDirectory(_logger, _fileIndexer, _fileSystemScanner, settings.PiwigoServerId, cancellationToken);
|
||||
|
||||
_logger.LogInformation("running album synchronization");
|
||||
await _albumSynchronizer.SynchronizeAlbums(settings.PiwigoServerId, cancellationToken);
|
||||
await _albumSynchronizer.SynchronizeAlbums(settings.PiwigoServerId, true, cancellationToken);
|
||||
|
||||
_logger.LogInformation("running image synchronization");
|
||||
await _imageSynchronizer.SynchronizeImagesAsync(settings.PiwigoServerId, cancellationToken);
|
||||
|
@ -20,7 +20,7 @@ internal class AlbumSynchronizer : IAlbumSynchronizer
|
||||
_persistenceContext = persistenceContext;
|
||||
}
|
||||
|
||||
public async Task SynchronizeAlbums(int piwigoServerId, CancellationToken ct)
|
||||
public async Task SynchronizeAlbums(int piwigoServerId, bool createAlbumsOnServer, CancellationToken ct)
|
||||
{
|
||||
var piwigoServer = await _persistenceContext.PiwigoServers.FindAsync(new object?[] { piwigoServerId }, ct);
|
||||
if (piwigoServer is null)
|
||||
@ -32,8 +32,16 @@ internal class AlbumSynchronizer : IAlbumSynchronizer
|
||||
var piwigoClient = await _piwigoClientFactory.GetPiwigoClientAsync(piwigoServer, ct);
|
||||
|
||||
await UpdatePiwigoAlbumsFromServerAsync(piwigoClient, piwigoServer, ct);
|
||||
if (createAlbumsOnServer)
|
||||
{
|
||||
_logger.LogInformation("Creating missing albums on server {PiwigoServerId} - {PiwigoServerName}", piwigoServer.Id, piwigoServer.Name);
|
||||
await AddMissingAlbumsToServerAsync(piwigoClient, piwigoServer, ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("Skipping album creation on server {PiwigoServerId} - {PiwigoServerName}", piwigoServer.Id, piwigoServer.Name);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AddMissingAlbumsToServerAsync(IPiwigoClient piwigoClient, ServerEntity piwigoServer, CancellationToken ct)
|
||||
{
|
||||
|
@ -2,5 +2,5 @@ namespace PiwigoDirectorySync.Services;
|
||||
|
||||
internal interface IAlbumSynchronizer
|
||||
{
|
||||
Task SynchronizeAlbums(int piwigoServerId, CancellationToken ct);
|
||||
Task SynchronizeAlbums(int piwigoServerId, bool createAlbumsOnServer, CancellationToken ct);
|
||||
}
|
Loading…
Reference in New Issue
Block a user