/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Ionic.Zip;
using Everest.Library.ExtensionMethod;
using Everest.CmsServices.Exceptions;
namespace Everest.CmsServices.Installation{
public static class Updater
{
public static void Upgrade(KoobooInstance olderInstance, KoobooInstance newerInstance, bool upgradeDb, bool copyContentFiles)
{
UpdaterBase updater = GetUpdater(olderInstance);
if (updater != null)
{
updater.Upgrade(olderInstance, newerInstance, upgradeDb, copyContentFiles);
}
}
private static UpdaterBase GetUpdater(KoobooInstance olderInstance)
{
UpdaterBase updater = null;
switch (olderInstance.DatabaseType)
{
case KoobooDatabaseType.Unsupported:
break;
case KoobooDatabaseType.MSSQL:
updater = new MSSQLUpdater();
break;
case KoobooDatabaseType.SQLite:
updater = new SQLiteUpdater();
break;
default:
break;
}
return updater;
}
public static void IntergratedUpgrade(KoobooInstance olderKooboo, string upgradeFile)
{
CheckPermission(olderKooboo.KoobooPath);
UpdaterBase updater = GetUpdater(olderKooboo);
if (updater != null)
{
OverrideFiles(olderKooboo, upgradeFile);
KoobooInstance newerKooboInstance = new KoobooInstance(olderKooboo.KoobooPath);
updater.UpgradeConfig(olderKooboo, newerKooboInstance);
updater.UpgradeDatabase(olderKooboo, newerKooboInstance);
}
}
private static void CheckPermission(string koobooPath)
{
if (!FileExtensions.HasWritePermissionOnDir(koobooPath))
{
throw new UpgradeException(Resources.Upgrade_FolderRequiredWritable);
}
}
private static void OverrideFiles(KoobooInstance kooboo, string upgradeFile)
{
var tempPath = Path.Combine(CmsGlobal.TempPath, Guid.NewGuid().ToString());
try
{
using (ZipFile zipFile = new ZipFile(upgradeFile, Encoding.UTF8))
{
zipFile.ExtractAll(tempPath, ExtractExistingFileAction.OverwriteSilently);
}
File.Delete(Path.Combine(tempPath, "web.config"));
try
{
string sqliteDbFile = Path.Combine(tempPath, "App_Data\\Kooboo.db");
if (File.Exists(sqliteDbFile))
{
File.Delete(sqliteDbFile);
}
}
catch
{
}
FileExtensions.CopyDirectory(tempPath, kooboo.KoobooPath);
}
finally
{
if (Directory.Exists(tempPath))
Directory.Delete(tempPath, true);
}
}
}
}
|