Update: Install Plugin (or Update)
Check to update the plugin when installing to avoid uninstall->wait->install cycle.
This commit is contained in:
@@ -51,7 +51,7 @@ namespace Disco.Services.Plugins
|
||||
}
|
||||
|
||||
this.Status.Finished("Restarting Disco, please wait...", "/Config/Plugins");
|
||||
Plugins.RestartApp(1500);
|
||||
Plugins.RestartApp(2500);
|
||||
}
|
||||
|
||||
public static ScheduledTaskStatus UninstallPlugin(PluginManifest Manifest, bool UninstallData)
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Disco.Services.Plugins
|
||||
ExecuteTaskInternal(this.Status, pluginPackagesLocation, updatePlugins);
|
||||
|
||||
this.Status.Finished("Restarting Disco, please wait...", "/Config/Plugins");
|
||||
Plugins.RestartApp(1500);
|
||||
Plugins.RestartApp(2500);
|
||||
}
|
||||
|
||||
public static List<PluginManifest> OfflineInstalledPlugins(DiscoDataContext Database)
|
||||
@@ -226,8 +226,8 @@ namespace Disco.Services.Plugins
|
||||
|
||||
// Ensure not already installed
|
||||
if (existingManifest != null)
|
||||
if (updateManifest.Version <= existingManifest.Version)
|
||||
throw new InvalidOperationException("Only newer versions can be used to update a plugin");
|
||||
if (updateManifest.Version < existingManifest.Version)
|
||||
throw new InvalidOperationException("Older versions cannot update existing plugins");
|
||||
|
||||
Status.UpdateStatus(20, string.Format("{0} [{1} v{2}] by {3}", updateManifest.Name, updateManifest.Id, updateManifest.Version.ToString(4), updateManifest.Author), "Initializing Update Environment");
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Disco.Services.Plugins
|
||||
|
||||
// Restart
|
||||
this.Status.Finished("Restarting Disco, please wait...", "/");
|
||||
Plugins.RestartApp(1500);
|
||||
Plugins.RestartApp(2500);
|
||||
}
|
||||
|
||||
public static ScheduledTaskStatus UpdateDiscoPlugins(bool ReturnExistingStatusIfRunning)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using Disco.Services.Authorization;
|
||||
using Disco.Services.Plugins;
|
||||
using Disco.Services.Plugins.CommunityInterop;
|
||||
using Disco.Services.Tasks;
|
||||
using Disco.Services.Web;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
@@ -117,7 +119,28 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
|
||||
Plugin.SaveAs(tempPluginLocation);
|
||||
|
||||
var status = InstallPluginTask.InstallLocalPlugin(tempPluginLocation, true);
|
||||
// Check for Install/Update
|
||||
PluginManifest packageManifest;
|
||||
using (var packageStream = System.IO.File.OpenRead(tempPluginLocation))
|
||||
{
|
||||
using (ZipArchive packageArchive = new ZipArchive(packageStream, ZipArchiveMode.Read, false))
|
||||
{
|
||||
ZipArchiveEntry packageManifestEntry = packageArchive.GetEntry("manifest.json");
|
||||
if (packageManifestEntry == null)
|
||||
throw new InvalidDataException("The plugin package does not contain the 'manifest.json' entry");
|
||||
|
||||
using (Stream packageManifestStream = packageManifestEntry.Open())
|
||||
{
|
||||
packageManifest = PluginManifest.FromPluginManifestFile(packageManifestStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScheduledTaskStatus status;
|
||||
if (Plugins.PluginInstalled(packageManifest.Id))
|
||||
status = UpdatePluginTask.UpdateLocalPlugin(packageManifest.Id, tempPluginLocation);
|
||||
else
|
||||
status = InstallPluginTask.InstallLocalPlugin(tempPluginLocation, true);
|
||||
|
||||
return RedirectToAction(MVC.Config.Logging.TaskStatus(status.SessionId));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user