Skip to content

Commit

Permalink
Merge branch 'epic/site-import-export' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
galatrash committed Apr 26, 2017
2 parents 353e064 + f6cd997 commit c916f35
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 325 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public int QueueOperation(int userId, ExportDto exportDto)
exportDto.FromDateUtc = GetLastJobTime(exportDto.PortalId, JobType.Export);
}
var dataObject = JsonConvert.SerializeObject(exportDto);

exportDto.IsDirty = false;//This should be set to false for new job.
var jobId = DataProvider.Instance().AddNewJob(exportDto.PortalId, userId,
JobType.Export, exportDto.ExportName, exportDto.ExportDescription, directory, dataObject);
//Run the scheduler if required.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace Dnn.ExportImport.Components.Dto
[JsonObject]
public class ExportDto
{
public int Id { get; set; }
/// <summary>
/// Specifies the version of the exportes schema.
/// </summary>
Expand Down Expand Up @@ -158,6 +159,11 @@ public class ExportDto
/// Whether to run the job immediately or not.
/// </summary>
public bool RunNow { get; set; }

/// <summary>
/// Used to determine if the DB file needs cleanup before starting import or not.
/// </summary>
public bool IsDirty { get; set; }
}

/// <summary>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,28 @@
using Dnn.ExportImport.Components.Entities;
using Dnn.ExportImport.Components.Models;
using Dnn.ExportImport.Components.Services;
using Dnn.ExportImport.Dto;
using Dnn.ExportImport.Dto.Assets;
using Dnn.ExportImport.Dto.PageTemplates;
using Dnn.ExportImport.Dto.Portal;
using Dnn.ExportImport.Dto.ProfileProperties;
using Dnn.ExportImport.Interfaces;
using Dnn.ExportImport.Repository;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Services.Cache;
using DotNetNuke.Services.Scheduling;
using Newtonsoft.Json;
using PlatformDataProvider = DotNetNuke.Data.DataProvider;
using DotNetNuke.Framework.Reflections;
using Dnn.ExportImport.Dto.Users;
using DotNetNuke.Instrumentation;

namespace Dnn.ExportImport.Components.Engines
{
public class ExportImportEngine
{
//private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(ExportImportEngine));
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(ExportImportEngine));

private const StringComparison IgnoreCaseComp = StringComparison.InvariantCultureIgnoreCase;

Expand Down Expand Up @@ -289,6 +298,7 @@ public void Import(ExportImportJob importJob, ExportImportResult result, Schedul
{
result.AddSummary("Starting Importing Repository", finfo.Name);
result.AddSummary("Importing File Size", Util.FormatSize(finfo.Length));
CleanupDatabaseIfDirty(ctx);
}
else
{
Expand Down Expand Up @@ -606,6 +616,37 @@ private static long GetExportSize(string exportFolder)
return files.Sum(file => new FileInfo(file).Length);
}

private static void CleanupDatabaseIfDirty(IExportImportRepository repository)
{
var exportDto = repository.GetSingleItem<ExportDto>();
var isDirty = exportDto.IsDirty;
exportDto.IsDirty = true;
repository.UpdateSingleItem(exportDto);
if (!isDirty) return;
var typeLocator = new TypeLocator();
var types = typeLocator.GetAllMatchingTypes(
t => t != null && t.IsClass && !t.IsAbstract && t.IsVisible &&
typeof(BasicExportImportDto).IsAssignableFrom(t));

foreach (var type in from type in types
let typeName = type.Name
where !CleanUpIgnoredClasses.Contains(typeName)
select type)
{
try
{
repository.CleanUpLocal(type.Name);
}
catch (Exception e)
{
Logger.ErrorFormat("Unable to clear {0} while calling CleanupDatabaseIfDirty. Error: {1}",
type.Name,
e.Message);
}
}

}

private static string[] NotAllowedCategoriesinRequestArray => new[]
{
Constants.Category_Content,
Expand All @@ -623,6 +664,25 @@ private static long GetExportSize(string exportFolder)
Constants.Category_Workflows,
};

private static string[] CleanUpIgnoredClasses => new[]
{
typeof (ExportFile).Name,
typeof (ExportFolder).Name,
typeof (ExportFolderMapping).Name,
typeof (ExportFolderPermission).Name,
typeof (ExportPageTemplate).Name,
typeof (ExportPortalSetting).Name,
typeof (ExportPortalLanguage).Name,
typeof (ExportProfileProperty).Name,
typeof (ExportUser).Name,
typeof (ExportAspnetUser).Name,
typeof (ExportAspnetMembership).Name,
typeof (ExportUserAuthentication).Name,
typeof (ExportUserPortal).Name,
typeof (ExportUserProfile).Name,
typeof (ExportUserRole).Name
};

public void AddLogsToDatabase(int jobId, ICollection<LogItem> completeLog)
{
if (completeLog == null || completeLog.Count == 0) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ public IDataReader GetAllVocabularyTypes()
return _dataProvider.ExecuteReader("ExportTaxonomy_VocabularyTypes");
}

public IDataReader GetAllTerms(DateTime toDate, DateTime? fromDate)
public IDataReader GetAllTerms(int portalId, DateTime toDate, DateTime? fromDate)
{
return _dataProvider.ExecuteReader("ExportTaxonomy_Terms", toDate, _dataProvider.GetNull(fromDate));
return _dataProvider.ExecuteReader("ExportTaxonomy_Terms", portalId, toDate, _dataProvider.GetNull(fromDate));
}

public IDataReader GetAllVocabularies(DateTime toDate, DateTime? fromDate)
public IDataReader GetAllVocabularies(int portalId, DateTime toDate, DateTime? fromDate)
{
return _dataProvider.ExecuteReader("ExportTaxonomy_Vocabularies", toDate, _dataProvider.GetNull(fromDate));
return _dataProvider.ExecuteReader("ExportTaxonomy_Vocabularies", portalId, toDate, _dataProvider.GetNull(fromDate));
}

public IDataReader GetAllRoleGroups(int portalId, DateTime toDate, DateTime? fromDate)
Expand Down
Loading

0 comments on commit c916f35

Please sign in to comment.