2
Vote

It could be a bug in Orchard.Localization, everytime we forget something when translating a content

description

In the Admin controller, it seems that the AutoroutePart is modified without cancelling the transaction when a error is detected in the input , so the modifications are saved ?
The cancel appears too early.
 public ActionResult TranslatePOST(int id, Action<ContentItem> conditionallyPublish) {
            var contentItem = _contentManager.Get(id, VersionOptions.Latest);

            if (contentItem == null)
                return HttpNotFound();

            var model = new AddLocalizationViewModel();
            TryUpdateModel(model);

            ContentItem contentItemTranslation;
            var existingTranslation = _localizationService.GetLocalizedContentItem(contentItem, model.SelectedCulture);
            if (existingTranslation != null) {
                // edit existing
                contentItemTranslation = _contentManager.Get(existingTranslation.ContentItem.Id, VersionOptions.DraftRequired);
            } else {
                // create
                contentItemTranslation = _contentManager.New(contentItem.ContentType);
                if (contentItemTranslation.Has<ICommonPart>() && contentItem.Has<ICommonPart>()) {
                    contentItemTranslation.As<ICommonPart>().Container = contentItem.As<ICommonPart>().Container;
                }

                _contentManager.Create(contentItemTranslation, VersionOptions.Draft);
            }

            model.Content = _contentManager.UpdateEditor(contentItemTranslation, this);

            if (!ModelState.IsValid) {
                // CS Modif, this line shoud be after the culture change :Services.TransactionManager.Cancel();
                model.SiteCultures = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem) && s != _cultureManager.GetSiteCulture());
                var culture = contentItem.As<LocalizationPart>().Culture;
                if (culture != null) {
                    culture.Culture = null;
                }
                model.Content = _contentManager.BuildEditor(contentItem);
                // CS modif new position for  previous line
                Services.TransactionManager.Cancel();
                return View(model);
            }

            if (existingTranslation != null) {
                Services.Notifier.Information(T("Edited content item translation."));
            }
            else {
                LocalizationPart localized = contentItemTranslation.As<LocalizationPart>();
                localized.MasterContentItem = contentItem;
                if (!string.IsNullOrWhiteSpace(model.SelectedCulture)) {
                    localized.Culture = _cultureManager.GetCultureByName(model.SelectedCulture);
                }

                conditionallyPublish(contentItemTranslation);

                Services.Notifier.Information(T("Created content item translation."));
            }

            var metadata = _contentManager.GetItemMetadata(model.Content.ContentItem);

            //todo: (heskew) if null, redirect to somewhere better than nowhere
            return metadata.EditorRouteValues == null ? null : RedirectToRoute(metadata.EditorRouteValues);
        }

comments

CSADNT wrote Jul 22 at 7:07 AM

Dup of (but created before :) )
https://orchard.codeplex.com/workitem/20708