Beispiel #1
0
        public override void ExportData(ExportImportJob exportJob, ExportDto exportDto)
        {
            var fromDate = (exportDto.FromDateUtc ?? Constants.MinDbTime).ToLocalTime();
            var toDate = exportDto.ToDateUtc.ToLocalTime();
            if (CheckPoint.Stage > 1) return;
            if (CheckCancelled(exportJob)) return;
            List<ExportPortalLanguage> portalLanguages = null;
            if (CheckPoint.Stage == 0)
            {
                var portalSettings = new List<ExportPortalSetting>();
                var settingToMigrate =
                    SettingsController.Instance.GetSetting(Constants.PortalSettingExportKey)?.SettingValue?.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (settingToMigrate != null)
                {
                    portalSettings = CBO.FillCollection<ExportPortalSetting>(DataProvider.Instance().GetPortalSettings(exportJob.PortalId, toDate, fromDate));

                    //Migrate only allowed portal settings.
                    portalSettings =
                        portalSettings.Where(x => settingToMigrate.Any(setting => setting.Trim().Equals(x.SettingName, StringComparison.InvariantCultureIgnoreCase))).ToList();

                    //Update the total items count in the check points. This should be updated only once.
                    CheckPoint.TotalItems = CheckPoint.TotalItems <= 0 ? portalSettings.Count : CheckPoint.TotalItems;
                    if (CheckPoint.TotalItems == portalSettings.Count)
                    {
                        portalLanguages =
                            CBO.FillCollection<ExportPortalLanguage>(
                                DataProvider.Instance().GetPortalLanguages(exportJob.PortalId, toDate, fromDate));
                        CheckPoint.TotalItems += portalLanguages.Count;
                    }
                    CheckPointStageCallback(this);

                    Repository.CreateItems(portalSettings);
                }
                Result.AddSummary("Exported Portal Settings", portalSettings.Count.ToString());

                CheckPoint.Progress = 50;
                CheckPoint.ProcessedItems = portalSettings.Count;
                CheckPoint.Stage++;
                if (CheckPointStageCallback(this)) return;
            }

            if (CheckPoint.Stage == 1)
            {
                if (CheckCancelled(exportJob)) return;
                if (portalLanguages == null)
                    portalLanguages = CBO.FillCollection<ExportPortalLanguage>(DataProvider.Instance()
                        .GetPortalLanguages(exportJob.PortalId, toDate, fromDate));

                Repository.CreateItems(portalLanguages);
                Result.AddSummary("Exported Portal Languages", portalLanguages.Count.ToString());
                CheckPoint.Progress = 100;
                CheckPoint.Completed = true;
                CheckPoint.Stage++;
                CheckPoint.ProcessedItems += portalLanguages.Count;
                CheckPointStageCallback(this);
            }
        }
Beispiel #2
0
        private void ProcessPortalLanguages(ExportImportJob importJob, ImportDto importDto,
                                            IEnumerable <ExportPortalLanguage> portalLanguages)
        {
            var portalId             = importJob.PortalId;
            var localPortalLanguages =
                CBO.FillCollection <ExportPortalLanguage>(DataProvider.Instance().GetPortalLanguages(portalId, DateUtils.GetDatabaseUtcTime().AddYears(1), null));
            var localLanguages = CBO.FillCollection <Locale>(DotNetNuke.Data.DataProvider.Instance().GetLanguages());

            foreach (var exportPortalLanguage in portalLanguages)
            {
                if (CheckCancelled(importJob))
                {
                    return;
                }
                var localLanguageId =
                    localLanguages.FirstOrDefault(x => x.Code == exportPortalLanguage.CultureCode)?.LanguageId;
                var existingPortalLanguage =
                    localPortalLanguages.FirstOrDefault(
                        t =>
                        t.LanguageId == localLanguageId);
                var isUpdate = false;
                if (existingPortalLanguage != null)
                {
                    switch (importDto.CollisionResolution)
                    {
                    case CollisionResolution.Overwrite:
                        isUpdate = true;
                        break;

                    case CollisionResolution.Ignore:
                        Result.AddLogEntry("Ignored portal language", exportPortalLanguage.CultureCode);
                        continue;

                    default:
                        throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                    }
                }
                if (isUpdate)
                {
                    var modifiedBy = Util.GetUserIdByName(importJob, exportPortalLanguage.LastModifiedByUserId, exportPortalLanguage.LastModifiedByUserName);

                    DotNetNuke.Data.DataProvider.Instance()
                    .UpdatePortalLanguage(importJob.PortalId, exportPortalLanguage.LanguageId,
                                          exportPortalLanguage.IsPublished, modifiedBy);

                    Result.AddLogEntry("Updated portal language", exportPortalLanguage.CultureCode);
                }
                else
                {
                    var createdBy = Util.GetUserIdByName(importJob, exportPortalLanguage.CreatedByUserId, exportPortalLanguage.CreatedByUserName);

                    exportPortalLanguage.PortalLanguageId = DotNetNuke.Data.DataProvider.Instance()
                                                            .AddPortalLanguage(importJob.PortalId, exportPortalLanguage.LanguageId,
                                                                               exportPortalLanguage.IsPublished, createdBy);
                    Result.AddLogEntry("Added portal language", exportPortalLanguage.CultureCode);
                }
            }
        }
Beispiel #3
0
        private void ProcessPortalSettings(ExportImportJob importJob, ImportDto importDto,
            IEnumerable<ExportPortalSetting> portalSettings)
        {
            var portalId = importJob.PortalId;
            var localPortalSettings =
                CBO.FillCollection<ExportPortalSetting>(DataProvider.Instance().GetPortalSettings(portalId, DateUtils.GetDatabaseUtcTime().AddYears(1), null));
            foreach (var exportPortalSetting in portalSettings)
            {
                if (CheckCancelled(importJob)) return;

                var existingPortalSetting =
                    localPortalSettings.FirstOrDefault(
                        t =>
                            t.SettingName == exportPortalSetting.SettingName &&
                            (t.CultureCode == exportPortalSetting.CultureCode ||
                             (string.IsNullOrEmpty(t.CultureCode) &&
                              string.IsNullOrEmpty(exportPortalSetting.CultureCode))));
                var isUpdate = false;
                if (existingPortalSetting != null)
                {
                    switch (importDto.CollisionResolution)
                    {
                        case CollisionResolution.Overwrite:
                            isUpdate = true;
                            break;
                        case CollisionResolution.Ignore:
                            Result.AddLogEntry("Ignored portal settings", exportPortalSetting.SettingName);
                            continue;
                        default:
                            throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                    }
                }
                if (isUpdate)
                {
                    var modifiedBy = Util.GetUserIdByName(importJob, exportPortalSetting.LastModifiedByUserId,
                     exportPortalSetting.LastModifiedByUserName);

                    exportPortalSetting.PortalSettingId = existingPortalSetting.PortalSettingId;
                    DotNetNuke.Data.DataProvider.Instance()
                        .UpdatePortalSetting(importJob.PortalId, exportPortalSetting.SettingName,
                            exportPortalSetting.SettingValue, modifiedBy, exportPortalSetting.CultureCode);
                    Result.AddLogEntry("Updated portal settings", exportPortalSetting.SettingName);
                }
                else
                {
                    var createdBy = Util.GetUserIdByName(importJob, exportPortalSetting.CreatedByUserId, exportPortalSetting.CreatedByUserName);

                    DotNetNuke.Data.DataProvider.Instance()
                        .UpdatePortalSetting(importJob.PortalId, exportPortalSetting.SettingName,
                            exportPortalSetting.SettingValue, createdBy, exportPortalSetting.CultureCode);

                    Result.AddLogEntry("Added portal settings", exportPortalSetting.SettingName);
                }
            }
        }
Beispiel #4
0
        public override void ExportData(ExportImportJob exportJob, ExportDto exportDto)
        {
            var fromDate = (exportDto.FromDateUtc ?? Constants.MinDbTime).ToLocalTime();
            var toDate   = exportDto.ToDateUtc.ToLocalTime();

            if (this.CheckCancelled(exportJob))
            {
                return;
            }

            if (this.CheckPoint.Stage > 0)
            {
                return;
            }

            if (this.CheckCancelled(exportJob))
            {
                return;
            }

            var profileProperties = CBO.FillCollection <ExportProfileProperty>(
                DataProvider.Instance()
                .GetPropertyDefinitionsByPortal(
                    exportJob.PortalId,
                    exportDto.IncludeDeletions,
                    toDate,
                    fromDate))
                                    .ToList();

            this.CheckPoint.Progress = 50;

            // Update the total items count in the check points. This should be updated only once.
            this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? profileProperties.Count : this.CheckPoint.TotalItems;
            this.CheckPointStageCallback(this);

            if (this.CheckCancelled(exportJob))
            {
                return;
            }

            this.Repository.CreateItems(profileProperties);
            this.Result.AddSummary("Exported Profile Properties", profileProperties.Count.ToString());
            this.CheckPoint.Progress       = 100;
            this.CheckPoint.ProcessedItems = profileProperties.Count;
            this.CheckPoint.Completed      = true;
            this.CheckPoint.Stage++;
            this.CheckPointStageCallback(this);
        }
Beispiel #5
0
        public override void ExportData(ExportImportJob exportJob, ExportDto exportDto)
        {
            if (this.CheckCancelled(exportJob))
            {
                return;
            }

            var fromDateUtc = exportDto.FromDateUtc;
            var toDateUtc   = exportDto.ToDateUtc;

            var       portalId                      = exportJob.PortalId;
            var       pageIndex                     = 0;
            const int pageSize                      = Constants.DefaultPageSize;
            var       totalUsersExported            = 0;
            var       totalUserRolesExported        = 0;
            var       totalPortalsExported          = 0;
            var       totalProfilesExported         = 0;
            var       totalAuthenticationExported   = 0;
            var       totalAspnetUserExported       = 0;
            var       totalAspnetMembershipExported = 0;
            var       totalUsers                    = DataProvider.Instance().GetUsersCount(portalId, exportDto.IncludeDeletions, toDateUtc, fromDateUtc);

            if (totalUsers == 0)
            {
                this.CheckPoint.Completed = true;
                this.CheckPointStageCallback(this);
                return;
            }

            var totalPages = Util.CalculateTotalPages(totalUsers, pageSize);

            // Skip the export if all the users has been processed already.
            if (this.CheckPoint.Stage >= totalPages)
            {
                return;
            }

            // Check if there is any pending stage or partially processed data.
            if (this.CheckPoint.Stage > 0)
            {
                pageIndex = this.CheckPoint.Stage;
            }

            // Update the total items count in the check points. This should be updated only once.
            this.CheckPoint.TotalItems     = this.CheckPoint.TotalItems <= 0 ? totalUsers : this.CheckPoint.TotalItems;
            this.CheckPoint.ProcessedItems = this.CheckPoint.Stage * pageSize;
            if (this.CheckPointStageCallback(this))
            {
                return;
            }

            var includeProfile = exportDto.IncludeProperfileProperties;

            try
            {
                while (pageIndex < totalPages)
                {
                    if (this.CheckCancelled(exportJob))
                    {
                        return;
                    }

                    var exportUsersList              = new List <ExportUser>();
                    var exportAspnetUserList         = new List <ExportAspnetUser>();
                    var exportAspnetMembershipList   = new List <ExportAspnetMembership>();
                    var exportUserRoleList           = new List <ExportUserRole>();
                    var exportUserPortalList         = new List <ExportUserPortal>();
                    var exportUserAuthenticationList = new List <ExportUserAuthentication>();
                    var exportUserProfileList        = new List <ExportUserProfile>();
                    try
                    {
                        using (var reader = DataProvider.Instance()
                                            .GetAllUsers(portalId, pageIndex, pageSize, exportDto.IncludeDeletions, toDateUtc, fromDateUtc))
                        {
                            CBO.FillCollection(reader, exportUsersList, false);
                            reader.NextResult();

                            CBO.FillCollection(reader, exportUserAuthenticationList, false);
                            reader.NextResult();

                            CBO.FillCollection(reader, exportUserRoleList, false);
                            reader.NextResult();

                            if (includeProfile)
                            {
                                CBO.FillCollection(reader, exportUserProfileList, false);
                            }

                            reader.NextResult();

                            CBO.FillCollection(reader, exportUserPortalList, false);
                            reader.NextResult();

                            CBO.FillCollection(reader, exportAspnetUserList, false);
                            reader.NextResult();

                            CBO.FillCollection(reader, exportAspnetMembershipList, true);
                        }

                        this.Repository.CreateItems(exportUsersList, null);
                        totalUsersExported += exportUsersList.Count;

                        exportUserAuthenticationList.ForEach(
                            x =>
                        {
                            x.ReferenceId = exportUsersList.FirstOrDefault(user => user.UserId == x.UserId)?.Id;
                        });
                        this.Repository.CreateItems(exportUserAuthenticationList, null);
                        totalAuthenticationExported += exportUserAuthenticationList.Count;

                        exportUserRoleList.ForEach(
                            x =>
                        {
                            x.ReferenceId = exportUsersList.FirstOrDefault(user => user.UserId == x.UserId)?.Id;
                        });
                        this.Repository.CreateItems(exportUserRoleList, null);
                        totalUserRolesExported += exportUserRoleList.Count;
                        if (includeProfile)
                        {
                            exportUserProfileList.ForEach(
                                x =>
                            {
                                x.ReferenceId = exportUsersList.FirstOrDefault(user => user.UserId == x.UserId)?.Id;
                            });
                            this.Repository.CreateItems(exportUserProfileList, null);
                            totalProfilesExported += exportUserProfileList.Count;
                        }

                        exportUserPortalList.ForEach(
                            x =>
                        {
                            x.ReferenceId = exportUsersList.FirstOrDefault(user => user.UserId == x.UserId)?.Id;
                        });
                        this.Repository.CreateItems(exportUserPortalList, null);
                        totalPortalsExported += exportUserPortalList.Count;

                        exportAspnetUserList.ForEach(
                            x =>
                        {
                            x.ReferenceId = exportUsersList.FirstOrDefault(user => user.Username == x.UserName)?.Id;
                        });
                        this.Repository.CreateItems(exportAspnetUserList, null);
                        totalAspnetUserExported += exportAspnetUserList.Count;

                        exportAspnetMembershipList.ForEach(
                            x =>
                        {
                            x.ReferenceId = exportAspnetUserList.FirstOrDefault(user => user.UserId == x.UserId)?.Id;
                        });
                        this.Repository.CreateItems(exportAspnetMembershipList, null);
                        totalAspnetMembershipExported += exportAspnetMembershipList.Count;

                        this.CheckPoint.ProcessedItems += exportUsersList.Count;
                    }
                    catch (Exception ex)
                    {
                        this.Result.AddLogEntry($"Exporting Users from {pageIndex * pageSize} to {(pageIndex * pageSize) + pageSize} exception", ex.Message, ReportLevel.Error);
                    }

                    this.CheckPoint.Progress = this.CheckPoint.ProcessedItems * 100.0 / totalUsers;
                    this.CheckPoint.Stage++;
                    if (this.CheckPointStageCallback(this))
                    {
                        return;
                    }

                    // Rebuild the indexes in the exported database.
                    this.Repository.RebuildIndex <ExportUser>(x => x.Id, true);
                    this.Repository.RebuildIndex <ExportUserPortal>(x => x.ReferenceId);
                    this.Repository.RebuildIndex <ExportAspnetUser>(x => x.ReferenceId);
                    this.Repository.RebuildIndex <ExportAspnetMembership>(x => x.ReferenceId);
                    this.Repository.RebuildIndex <ExportUserAuthentication>(x => x.ReferenceId);
                    this.Repository.RebuildIndex <ExportUserRole>(x => x.ReferenceId);
                    if (includeProfile)
                    {
                        this.Repository.RebuildIndex <ExportUserProfile>(x => x.ReferenceId);
                    }

                    pageIndex++;
                }

                this.CheckPoint.Completed = true;
                this.CheckPoint.Progress  = 100;
            }
            finally
            {
                this.CheckPointStageCallback(this);
                this.Result.AddSummary("Exported Users", totalUsersExported.ToString());
                this.Result.AddSummary("Exported User Portals", totalPortalsExported.ToString());
                this.Result.AddSummary("Exported User Roles", totalUserRolesExported.ToString());
                if (includeProfile)
                {
                    this.Result.AddSummary("Exported User Profiles", totalProfilesExported.ToString());
                }

                this.Result.AddSummary("Exported User Authentication", totalAuthenticationExported.ToString());
                this.Result.AddSummary("Exported Aspnet User", totalAspnetUserExported.ToString());
                this.Result.AddSummary("Exported Aspnet Membership", totalAspnetMembershipExported.ToString());
            }
        }
Beispiel #6
0
        public override void ExportData(ExportImportJob exportJob, ExportDto exportDto)
        {
            if (CheckCancelled(exportJob))
            {
                return;
            }
            //Skip the export if all the folders have been processed already.
            if (CheckPoint.Stage >= 1)
            {
                return;
            }

            //Create Zip File to hold files
            var skip                           = GetCurrentSkip();
            var currentIndex                   = skip;
            var totalFolderExported            = 0;
            var totalFolderPermissionsExported = 0;
            var totalFilesExported             = 0;
            var portalId                       = exportJob.PortalId;

            try
            {
                var assetsFile = string.Format(_assetsFolder, exportJob.Directory.TrimEnd('\\').TrimEnd('/'));

                if (CheckPoint.Stage == 0)
                {
                    var fromDate = (exportDto.FromDateUtc ?? Constants.MinDbTime).ToLocalTime();
                    var toDate   = exportDto.ToDateUtc.ToLocalTime();
                    var portal   = PortalController.Instance.GetPortal(portalId);

                    var folders =
                        CBO.FillCollection <ExportFolder>(DataProvider.Instance()
                                                          .GetFolders(portalId, toDate, fromDate)).ToList();
                    var totalFolders = folders.Any() ? folders.Count : 0;
                    folders = folders.Skip(skip).ToList();


                    //Update the total items count in the check points. This should be updated only once.
                    CheckPoint.TotalItems     = CheckPoint.TotalItems <= 0 ? totalFolders : CheckPoint.TotalItems;
                    CheckPoint.ProcessedItems = skip;
                    CheckPoint.Progress       = CheckPoint.TotalItems > 0 ? skip * 100.0 / CheckPoint.TotalItems : 0;
                    if (CheckPointStageCallback(this))
                    {
                        return;
                    }
                    using (var zipArchive = CompressionUtil.OpenCreate(assetsFile))
                    {
                        foreach (var folder in folders)
                        {
                            if (CheckCancelled(exportJob))
                            {
                                break;
                            }
                            var isUserFolder = false;

                            var files =
                                CBO.FillCollection <ExportFile>(
                                    DataProvider.Instance()
                                    .GetFiles(portalId, folder.FolderId, toDate, fromDate)).Where(x => x.Extension != Constants.TemplatesExtension).ToList();
                            int?userId;
                            if (IsUserFolder(folder.FolderPath, out userId))
                            {
                                isUserFolder    = true;
                                folder.UserId   = userId;
                                folder.Username =
                                    UserController.GetUserById(portalId, Convert.ToInt32(userId))?.Username;
                            }
                            if (folder.ParentId != null && folder.ParentId > 0)
                            {
                                //If parent id exists then change the parent folder id to parent id.
                                folder.ParentId =
                                    Repository.GetItem <ExportFolder>(
                                        x => x.FolderId == Convert.ToInt32(folder.ParentId))?.Id;
                            }

                            Repository.CreateItem(folder, null);
                            totalFolderExported++;
                            //Include permissions only if IncludePermissions=true
                            if (exportDto.IncludePermissions)
                            {
                                var permissions =
                                    CBO.FillCollection <ExportFolderPermission>(DataProvider.Instance()
                                                                                .GetFolderPermissionsByPath(portalId, folder.FolderPath, toDate, fromDate));
                                Repository.CreateItems(permissions, folder.Id);
                                totalFolderPermissionsExported += permissions.Count;
                            }
                            Repository.CreateItems(files, folder.Id);
                            totalFilesExported += files.Count;
                            var folderOffset = portal.HomeDirectoryMapPath.Length +
                                               (portal.HomeDirectoryMapPath.EndsWith("\\") ? 0 : 1);

                            if (folder.StorageLocation != (int)FolderController.StorageLocationTypes.DatabaseSecure)
                            {
                                CompressionUtil.AddFilesToArchive(zipArchive, files.Select(file => portal.HomeDirectoryMapPath + folder.FolderPath + GetActualFileName(file)),
                                                                  folderOffset, isUserFolder ? "TempUsers" : null);
                            }
                            CheckPoint.ProcessedItems++;
                            CheckPoint.Progress  = CheckPoint.ProcessedItems * 100.0 / totalFolders;
                            CheckPoint.StageData = null;
                            currentIndex++;
                            //After every 10 items, call the checkpoint stage. This is to avoid too many frequent updates to DB.
                            if (currentIndex % 10 == 0 && CheckPointStageCallback(this))
                            {
                                return;
                            }
                            Repository.RebuildIndex <ExportFolder>(x => x.Id, true);
                            Repository.RebuildIndex <ExportFolder>(x => x.UserId);
                            Repository.RebuildIndex <ExportFile>(x => x.ReferenceId);
                        }
                    }
                    CheckPoint.Completed = true;
                    CheckPoint.Stage++;
                    currentIndex        = 0;
                    CheckPoint.Progress = 100;
                }
            }
            finally
            {
                CheckPoint.StageData = currentIndex > 0 ? JsonConvert.SerializeObject(new { skip = currentIndex }) : null;
                CheckPointStageCallback(this);
                Result.AddSummary("Exported Folders", totalFolderExported.ToString());
                Result.AddSummary("Exported Folder Permissions", totalFolderPermissionsExported.ToString());
                Result.AddSummary("Exported Files", totalFilesExported.ToString());
            }
        }
Beispiel #7
0
        private void ProcessFolderPermission(ExportImportJob importJob, ImportDto importDto,
                                             ExportFolderPermission folderPermission, IEnumerable <ExportFolderPermission> localPermissions)
        {
            var portalId = importJob.PortalId;
            var noRole   = Convert.ToInt32(Globals.glbRoleNothing);

            if (folderPermission == null)
            {
                return;
            }
            var roleId = Util.GetRoleIdByName(portalId, folderPermission.RoleId ?? noRole, folderPermission.RoleName);
            var userId = UserController.GetUserByName(portalId, folderPermission.Username)?.UserID;

            var existingFolderPermission = localPermissions.FirstOrDefault(
                x =>
                (x.FolderPath == folderPermission.FolderPath ||
                 (string.IsNullOrEmpty(x.FolderPath) && string.IsNullOrEmpty(folderPermission.FolderPath))) &&
                x.PermissionCode == folderPermission.PermissionCode && x.PermissionKey == folderPermission.PermissionKey &&
                x.PermissionName.Equals(folderPermission.PermissionName, StringComparison.InvariantCultureIgnoreCase) &&
                x.RoleId == roleId && x.UserId == userId);

            var isUpdate = false;

            if (existingFolderPermission != null)
            {
                switch (importDto.CollisionResolution)
                {
                case CollisionResolution.Overwrite:
                    isUpdate = true;
                    break;

                case CollisionResolution.Ignore:
                    return;

                default:
                    throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                }
            }
            if (isUpdate)
            {
                var modifiedBy = Util.GetUserIdByName(importJob, folderPermission.LastModifiedByUserId,
                                                      folderPermission.LastModifiedByUserName);

                DotNetNuke.Data.DataProvider.Instance()
                .UpdateFolderPermission(existingFolderPermission.FolderPermissionId, folderPermission.FolderId,
                                        existingFolderPermission.PermissionId, existingFolderPermission.RoleId ?? Convert.ToInt32(Globals.glbRoleNothing),
                                        folderPermission.AllowAccess, existingFolderPermission.UserId ?? Null.NullInteger, modifiedBy);

                folderPermission.FolderPermissionId = existingFolderPermission.FolderPermissionId;
            }
            else
            {
                var permissionId = DataProvider.Instance()
                                   .GetPermissionId(folderPermission.PermissionCode, folderPermission.PermissionKey,
                                                    folderPermission.PermissionName);

                if (permissionId != null)
                {
                    folderPermission.PermissionId = Convert.ToInt32(permissionId);
                    if (folderPermission.UserId != null && folderPermission.UserId > 0 && !string.IsNullOrEmpty(folderPermission.Username))
                    {
                        folderPermission.UserId = userId;
                        if (folderPermission.UserId == null)
                        {
                            return;
                        }
                    }
                    if (folderPermission.RoleId != null && folderPermission.RoleId > noRole && !string.IsNullOrEmpty(folderPermission.RoleName))
                    {
                        folderPermission.RoleId = roleId;
                        if (folderPermission.RoleId == null)
                        {
                            return;
                        }
                    }
                    var createdBy = Util.GetUserIdByName(importJob, folderPermission.CreatedByUserId,
                                                         folderPermission.CreatedByUserName);

                    folderPermission.FolderPermissionId = DotNetNuke.Data.DataProvider.Instance()
                                                          .AddFolderPermission(folderPermission.FolderId, folderPermission.PermissionId,
                                                                               folderPermission.RoleId ?? noRole, folderPermission.AllowAccess,
                                                                               folderPermission.UserId ?? Null.NullInteger, createdBy);
                }
            }
            folderPermission.LocalId = folderPermission.FolderPermissionId;
        }
Beispiel #8
0
        public override void ImportData(ExportImportJob importJob, ImportDto importDto)
        {
            if (CheckCancelled(importJob))
            {
                return;
            }
            //Stage 1: Portals files unzipped.
            //Stage 2: All folders and files imported.
            //Stage 3: Synchronization completed.
            //Skip the export if all the folders have been processed already.
            if (CheckPoint.Stage >= 2 || CheckPoint.Completed)
            {
                return;
            }

            var totalFolderImported            = 0;
            var totalFolderPermissionsImported = 0;
            var totalFilesImported             = 0;
            var skip           = GetCurrentSkip();
            var currentIndex   = skip;
            var portalId       = importJob.PortalId;
            var portal         = PortalController.Instance.GetPortal(portalId);
            var assetsFile     = string.Format(_assetsFolder, importJob.Directory.TrimEnd('\\').TrimEnd('/'));
            var userFolderPath = string.Format(UsersAssetsTempFolder, portal.HomeDirectoryMapPath.TrimEnd('\\'));

            if (CheckPoint.Stage == 0)
            {
                if (!File.Exists(assetsFile))
                {
                    Result.AddLogEntry("AssetsFileNotFound", "Assets file not found. Skipping assets import",
                                       ReportLevel.Warn);
                    CheckPoint.Completed = true;
                    CheckPointStageCallback(this);
                }
                else
                {
                    CompressionUtil.UnZipArchive(assetsFile, portal.HomeDirectoryMapPath,
                                                 importDto.CollisionResolution == CollisionResolution.Overwrite);
                    //Stage 1: Once unzipping of portal files is completed.
                    CheckPoint.Stage++;
                    CheckPoint.StageData = null;
                    CheckPoint.Progress  = 10;
                    if (CheckPointStageCallback(this))
                    {
                        return;
                    }
                }
            }

            if (CheckPoint.Stage == 1)
            {
                try
                {
                    //Stage 2 starts
                    var sourceFolders = Repository.GetAllItems <ExportFolder>(x => x.CreatedOnDate, true, skip).ToList();

                    var totalFolders = sourceFolders.Any() ? sourceFolders.Count : 0;
                    //Update the total items count in the check points. This should be updated only once.
                    CheckPoint.TotalItems = CheckPoint.TotalItems <= 0 ? totalFolders : CheckPoint.TotalItems;
                    if (CheckPointStageCallback(this))
                    {
                        return;
                    }

                    foreach (var sourceFolder in sourceFolders)
                    {
                        if (CheckCancelled(importJob))
                        {
                            break;
                        }
                        // PROCESS FOLDERS
                        //Create new or update existing folder
                        if (ProcessFolder(importJob, importDto, sourceFolder))
                        {
                            totalFolderImported++;

                            //Include permissions only if permissions were exported in package.
                            if (importDto.ExportDto.IncludePermissions)
                            {
                                // PROCESS FOLDER PERMISSIONS
                                var sourceFolderPermissions =
                                    Repository.GetRelatedItems <ExportFolderPermission>(sourceFolder.Id).ToList();
                                //Replace folderId for each permission with new one.
                                sourceFolderPermissions.ForEach(x =>
                                {
                                    x.FolderId   = Convert.ToInt32(sourceFolder.FolderId);
                                    x.FolderPath = sourceFolder.FolderPath;
                                });

                                // PROCESS FOLDER PERMISSIONS
                                //File local files in the system related to the folder path.
                                var localPermissions =
                                    CBO.FillCollection <ExportFolderPermission>(DataProvider.Instance()
                                                                                .GetFolderPermissionsByPath(portalId, sourceFolder.FolderPath,
                                                                                                            DateUtils.GetDatabaseUtcTime().AddYears(1), null));

                                foreach (var folderPermission in sourceFolderPermissions)
                                {
                                    ProcessFolderPermission(importJob, importDto, folderPermission,
                                                            localPermissions);
                                }
                                totalFolderPermissionsImported += sourceFolderPermissions.Count;
                            }

                            // PROCESS FILES
                            var sourceFiles =
                                Repository.GetRelatedItems <ExportFile>(sourceFolder.Id).ToList();
                            //Replace folderId for each file with new one.
                            sourceFiles.ForEach(x =>
                            {
                                x.FolderId = Convert.ToInt32(sourceFolder.FolderId);
                                x.Folder   = sourceFolder.FolderPath;
                            });

                            //File local files in the system related to the folder
                            var localFiles =
                                CBO.FillCollection <ExportFile>(DataProvider.Instance()
                                                                .GetFiles(portalId, sourceFolder.FolderId,
                                                                          DateUtils.GetDatabaseUtcTime().AddYears(1), null));

                            foreach (var file in sourceFiles)
                            {
                                ProcessFiles(importJob, importDto, file, localFiles);
                            }
                            totalFilesImported += sourceFiles.Count;
                        }

                        currentIndex++;
                        CheckPoint.ProcessedItems++;
                        CheckPoint.Progress = 10 + CheckPoint.ProcessedItems * 90.0 / totalFolders;
                        //After every 10 items, call the checkpoint stage. This is to avoid too many frequent updates to DB.
                        if (currentIndex % 10 == 0 && CheckPointStageCallback(this))
                        {
                            return;
                        }
                    }
                    currentIndex         = 0;
                    CheckPoint.Completed = true;
                    CheckPoint.Stage++;
                    CheckPoint.Progress = 100;
                }
                finally
                {
                    CheckPoint.StageData = currentIndex > 0
                        ? JsonConvert.SerializeObject(new { skip = currentIndex })
                        : null;
                    CheckPointStageCallback(this);

                    Result.AddSummary("Imported Folders", totalFolderImported.ToString());
                    Result.AddSummary("Imported Folder Permissions", totalFolderPermissionsImported.ToString());
                    Result.AddSummary("Imported Files", totalFilesImported.ToString());

                    if (Directory.Exists(userFolderPath) && currentIndex == 0)
                    {
                        Directory.Delete(userFolderPath, true);
                    }
                }
            }
        }
Beispiel #9
0
        public override void ExportData(ExportImportJob exportJob, ExportDto exportDto)
        {
            if (this.CheckCancelled(exportJob))
            {
                return;
            }

            // Skip the export if all the folders have been processed already.
            if (this.CheckPoint.Stage >= 1)
            {
                return;
            }

            // Create Zip File to hold files
            var skip                   = this.GetCurrentSkip();
            var currentIndex           = skip;
            var totalTemplatesExported = 0;
            var portalId               = exportJob.PortalId;

            try
            {
                var templatesFile = string.Format(this.templatesFolder, exportJob.Directory.TrimEnd('\\').TrimEnd('/'));

                if (this.CheckPoint.Stage == 0)
                {
                    var fromDate = (exportDto.FromDateUtc ?? Constants.MinDbTime).ToLocalTime();
                    var toDate   = exportDto.ToDateUtc.ToLocalTime();
                    var portal   = PortalController.Instance.GetPortal(portalId);

                    var templates =
                        CBO.FillCollection <ExportPageTemplate>(
                            DataProvider.Instance()
                            .GetFiles(portalId, null, toDate, fromDate))
                        .Where(x => x.Extension == Constants.TemplatesExtension)
                        .ToList();
                    var totalTemplates = templates.Count;

                    // Update the total items count in the check points. This should be updated only once.
                    this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? totalTemplates : this.CheckPoint.TotalItems;
                    if (this.CheckPointStageCallback(this))
                    {
                        return;
                    }

                    foreach (var template in templates)
                    {
                        this.Repository.CreateItem(template, null);
                        totalTemplatesExported += 1;
                        var folderOffset = portal.HomeDirectoryMapPath.Length +
                                           (portal.HomeDirectoryMapPath.EndsWith("\\") ? 0 : 1);

                        var folder = FolderManager.Instance.GetFolder(template.FolderId);
                        CompressionUtil.AddFileToArchive(
                            portal.HomeDirectoryMapPath + folder.FolderPath + this.GetActualFileName(template),
                            templatesFile,
                            folderOffset);

                        this.CheckPoint.ProcessedItems++;
                        this.CheckPoint.Progress = this.CheckPoint.ProcessedItems * 100.0 / totalTemplates;
                        currentIndex++;

                        // After every 10 items, call the checkpoint stage. This is to avoid too many frequent updates to DB.
                        if (currentIndex % 10 == 0 && this.CheckPointStageCallback(this))
                        {
                            return;
                        }
                    }

                    this.CheckPoint.Stage++;
                    currentIndex = 0;
                    this.CheckPoint.Completed = true;
                    this.CheckPoint.Progress  = 100;
                }
            }
            finally
            {
                this.CheckPoint.StageData = currentIndex > 0 ? JsonConvert.SerializeObject(new { skip = currentIndex }) : null;
                this.CheckPointStageCallback(this);
                this.Result.AddSummary("Exported Templates", totalTemplatesExported.ToString());
            }
        }