public string Export(IEnumerable<string> contentTypes, IEnumerable<ContentItem> contentItems, ExportOptions exportOptions) {
            var exportDocument = CreateExportRoot();

            var context = new ExportContext {
                Document = exportDocument,
                ContentTypes = contentTypes,
                ExportOptions = exportOptions
            };

            _exportEventHandlers.Invoke(x => x.Exporting(context), Logger);

            if (exportOptions.ExportMetadata && (!exportOptions.ExportData || contentItems.Any())) {
                exportDocument.Element("Orchard").Add(ExportMetadata(contentTypes));
            }

            if (exportOptions.ExportSiteSettings) {
                exportDocument.Element("Orchard").Add(ExportSiteSettings());
            }

            if (exportOptions.ExportData && contentItems.Any()) {
                exportDocument.Element("Orchard").Add(ExportData(contentTypes, contentItems, exportOptions.ImportBatchSize));
            }

            _exportEventHandlers.Invoke(x => x.Exported(context), Logger);

            return WriteExportFile(exportDocument.ToString());
        }
        public string Export(IEnumerable<string> contentTypes, ExportOptions exportOptions) {
            //items need to be retrieved
            IEnumerable<ContentItem> contentItems = null;
            if (exportOptions.ExportData) {
                contentItems = _orchardServices.ContentManager.Query(GetContentExportVersionOptions(exportOptions.VersionHistoryOptions), contentTypes.ToArray()).List();
            }

            return Export(contentTypes, contentItems, exportOptions);
        }
Beispiel #3
0
        public ActionResult ExportPOST() {
            if (!Services.Authorizer.Authorize(Permissions.Export, T("Not allowed to export.")))
                return new HttpUnauthorizedResult();

            var viewModel = new ExportViewModel { ContentTypes = new List<ContentTypeEntry>() };

            UpdateModel(viewModel);
            var contentTypesToExport = viewModel.ContentTypes.Where(c => c.IsChecked).Select(c => c.ContentTypeName);
            var exportOptions = new ExportOptions { ExportMetadata = viewModel.Metadata, ExportSiteSettings = viewModel.SiteSettings };
            if (viewModel.Data) {
                exportOptions.ExportData = true;
                exportOptions.VersionHistoryOptions = (VersionHistoryOptions)Enum.Parse(typeof(VersionHistoryOptions), viewModel.DataImportChoice, true);
            }
            var exportFilePath = _importExportService.Export(contentTypesToExport, exportOptions);
            return File(exportFilePath, "text/xml", "export.xml");
        }
        public string Export(IEnumerable<string> contentTypes, ExportOptions exportOptions) {
            var exportDocument = CreateExportRoot();

            if (exportOptions.ExportMetadata) {
                exportDocument.Element("Orchard").Add(ExportMetadata(contentTypes));
            }

            if (exportOptions.ExportSiteSettings) {
                exportDocument.Element("Orchard").Add(ExportSiteSettings());
            }

            if (exportOptions.ExportData) {
                exportDocument.Element("Orchard").Add(ExportData(contentTypes, exportOptions.VersionHistoryOptions));
            }

            return WriteExportFile(exportDocument.ToString());
        }
        public void ExportFile() {
            // impersonate the Site owner
            var superUser = _siteService.GetSiteSettings().SuperUser;
            var owner = _membershipService.GetUser(superUser);
            _authenticationService.SetAuthenticatedUserForRequest(owner);

            var versionOption = VersionHistoryOptions.Published;

            if (!String.IsNullOrEmpty(Version) && !Enum.TryParse(Version, out versionOption)) {
                Context.Output.WriteLine(T("Invalid version option"));
                return;
            }

            var enteredTypes = (Types ?? String.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            var exportTypes = _contentDefinitionManager.ListTypeDefinitions()
                                                       .Where(contentType => enteredTypes.Contains(contentType.Name))
                                                       .Select(contentType => contentType.Name);

            var enteredSteps = (Steps ?? String.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            var exportOptions = new ExportOptions {
                ExportMetadata = Metadata,
                ExportData = Data,
                VersionHistoryOptions = versionOption,
                ExportSiteSettings = SiteSettings,
                CustomSteps = enteredSteps
            };

            Context.Output.WriteLine(T("Export starting..."));

            var exportFilePath = _importExportService.Export(exportTypes, exportOptions);

            Context.Output.WriteLine(T("Export completed at {0}", exportFilePath));
        }