Question

If you customize an autoroute part you have the option to recreate the url on each save.

The help text under this option says:

"Automatically regenerate when editing content This option will cause the Url to automatically be regenerated when you edit existing content and publish it again, otherwise it will always keep the old route, or you have to perform bulk update in the Autoroute admin."

I have digged all around but I cannot find anywhere an "Autoroute admin".

Is it really there?

It was a proposed feature never implemented?

Any idea to do a bulk update even without an Admin page?

Thanks

EDIT after @joshb suggestion...

I have tried to implement a bulk operation in my controller.

  var MyContents = _contentManager.Query<MyContentPart, MyContentPartRecord>().List().ToList();

  foreach (var MyContent in MyContents) {
        var autoroutePart = recipe.ContentItem.As<AutoroutePart>();
        autoroutePart.UseCustomPattern = false;
        autoroutePart.DisplayAlias = _autorouteService.GenerateAlias(autoroutePart);
        _contentManager.Publish(autoroutePart.ContentItem);
  }

In this way it recreates all aliases for the types that contain the given part MyContentPart. With some more work this code can be encapsulated in a command or in a new tab in Alias UI. After finished the current project I'm doing I will try that...

Was it helpful?

Solution

You could create a module and implement a command that does a bulk update. Shouldn't be too much work if you're comfortable creating modules. You'll need to implement DefaultOrchardCommandHandler and inject IContentManager to get all the parts you're interested in.

OTHER TIPS

Enable Alias UI in the modules section will give you the admin section for managing routes, however I'm not sure what kind of bulk updates it offers

Publishing the ContentItem will do nothing if it is already Published (as it was in my case).

Instead, one could call the PublishAlias method on the AutorouteService. I ended up with a Controller, something like this:

using Orchard;
using Orchard.Autoroute.Models;
using Orchard.Autoroute.Services;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Security;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace MyNamespace.MyModule.Controllers {

    public class AutorouteBulkUpdateController : Controller {

        private readonly IOrchardServices _orchardServices;
        private readonly IAutorouteService _autorouteService;
        private Localizer T { get; set; }

        public AutorouteBulkUpdateController(IOrchardServices orchardServices, IAutorouteService autorouteService) {
            _orchardServices = orchardServices;
            _autorouteService = autorouteService;
            T = NullLocalizer.Instance;
        }

        public ActionResult Index() {

            if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage settings"))) {
                return new HttpUnauthorizedResult();
            }

            int count = 0;
            IEnumerable<AutoroutePart> contents;

            do {
                //contents = _orchardServices.ContentManager.Query<AutoroutePart>(VersionOptions.Latest, new string[] { "Page" }).Slice(count * 100, 100).ToList();
                contents = _orchardServices.ContentManager.Query<AutoroutePart>(VersionOptions.Latest).Slice(count * 100, 100).ToList();

                foreach (var autoroutePart in contents) {

                    var alias = _autorouteService.GenerateAlias(autoroutePart);

                    if (autoroutePart.DisplayAlias != alias) {
                        autoroutePart.UseCustomPattern = false;
                        autoroutePart.DisplayAlias = alias;
                        _autorouteService.PublishAlias(autoroutePart);
                    }
                }

                _orchardServices.TransactionManager.RequireNew();
                _orchardServices.ContentManager.Clear();

                count += 1;

            } while (contents.Any());

            return null;
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top