Skip to content

New feature "Orchard.MediaLibrary.LocalizationExtensions"#7935

Merged
sebastienros merged 7 commits into
OrchardCMS:devfrom
LaserSrl:issue/7843_media_localization_extensions
Jan 18, 2018
Merged

New feature "Orchard.MediaLibrary.LocalizationExtensions"#7935
sebastienros merged 7 commits into
OrchardCMS:devfrom
LaserSrl:issue/7843_media_localization_extensions

Conversation

@HermesSbicego-Laser

Copy link
Copy Markdown
Contributor

Implements what opened with #7843

"Orchard.MediaLibrary.LocalizationExtensions" feature:

  • MediaLocalizationMigrations: Adds LocalizationPart to all Media stereotyped types
  • MediaLibraryPickerFieldLocalizationExtensionHandler: Updates the media items within the field according to field settings
  • Settings for translation behaviours for MediaLibraryPickerField
  • Adds warning on localizing media items
  • form filter media by culture

"MediaLibrary" feature:

  • Implemented Cloning methods of all medias PartDrivers
  • MediaPartHandler: Adds a check to prevent file system media deletion when the file is referenced by other medias
  • ClientStorageController: Adds a check to prevent file system media deletion when the file is referenced by other medias

"Localization" feature:

  • Adds a logic to propagate returnurl parameter to the redirection url
  • ILocalizationService: Adds a new method to set the culture of a content and at the same time the master content of it
  • Propagate returnurl parameter if necessary

"Search" feature:

  • updated json of media items called via ajax

- MediaLocalizationMigrations: Adds LocalizationPart to all Media stereotyped types
- MediaLibraryPickerFieldLocalizationExtensionHandler: Updates the media items within the field according to field settings
- Settings for translation behaviours for MediaLibraryPickerField
- Adds warning on localizing media items
- form filter media by culture

"MediaLibrary" feature:
- Implemented Cloning methods of all medias PartDrivers
- MediaPartHandler: Adds a check to prevent file system media deletion when the file is referenced by other medias
- ClientStorageController: Adds a check to prevent file system media deletion when the file is referenced by other medias

"Localization" feature:
- Adds a logic to propagate returnurl parameter to the redirection url
- ILocalizationService: Adds a new method to set the culture of a content and at the same time the master content of it
- Propagate returnurl parameter if necessary

"Search" feature:
- updated json of media items called via ajax
}
}
if (mediaIds.Count > 0) {
field.Ids = mediaIds.Distinct().ToArray();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastienros I don't know if we should do distinct() here. Should we allow duplicated media items in the field? I added the distinct here because of #7934, but I can remove it.

}
foreach (var key in Request.QueryString.AllKeys.Where(x => !x.StartsWith("__") && !editorRouteValues.Keys.Contains(x))) {
editorRouteValues.Add(key, Request.QueryString[key]);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In media library the edit button adds a "ReturnUrl" QueryString in order to have a redirection to the caller page when saving/cancelling operation.
The translate link has the prop "Unsafe", so it transforms the request from get + querystring in post + body . So I propagate those parameters through redirection translate (which clone) > edit content, in order to be able to manage the right returnurl (and other parameters if they are there). To restrict the logic to only the "redirecturl" parameter, could be less flexible but more safe. @sebastienros what do you prefer?

FolderPath = folderPath
};
return View(viewModel);
}

@HermesSbicego-Laser HermesSbicego-Laser Jan 11, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have replicated the logic within Orchard.Search, even if I don't like so much the results because filters from different features can't works together. Basically I have not introduced anything worse than it already was, so i ask you if you can merge it anyway.
But we should consider to change the current approach; I don't know if it is possible but:

  • the responsible of acting the filter should be the medialibrary module
  • other modules can partecipate in building the where clause of the query (as per projections)
  • every change in the filters form/folders navigation fires a medialibrary controller responsible of combining the queries and then exposing the result.
    @sebastienros if you agree I will file a new issue describing the problem and proposing the above solution.

@sebastienros

Copy link
Copy Markdown
Member

Looks good, waiting for a demo.
And hopefully someone else will try it.

if (!string.IsNullOrEmpty(part.FileName)) {
_mediaLibraryService.DeleteFile(part.FolderPath, part.FileName);
var mediaItemsUsingTheFile = _contentManager.Query<MediaPart, MediaPartRecord>()
.ForVersion(VersionOptions.Latest)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about your @sebastienros comment to query latest and published version here...
As I Know Medias are not draftable, so querying latest should be enough. The only case in which a Media can be in draft, right now, is after a clone/translation and it has not a published version. In all the other cases if a media is published it's the Latest also. If you agree I will keep this code as is.

.ForVersion(VersionOptions.Latest)
.Where(x => x.FolderPath == replaceMedia.FolderPath && x.FileName == replaceMedia.FileName)
.Count();
if (mediaItemsUsingTheFile == 1) { // if the file is referenced only by the deleted media content, the file too can be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastienros Same here, Latest should be enough

@HermesSbicego-Laser

HermesSbicego-Laser commented Jan 17, 2018

Copy link
Copy Markdown
Contributor Author

@sebastienros , After yesterday demo, consider to merge it in dev. We will cherry pick and deliver it in our production env.

@sebastienros
sebastienros merged commit 28c53ef into OrchardCMS:dev Jan 18, 2018
HermesSbicego-Laser added a commit to LaserSrl/Orchard that referenced this pull request Jan 19, 2018
…#7935)

* New feature "Orchard.MediaLibrary.LocalizationExtensions":
- MediaLocalizationMigrations: Adds LocalizationPart to all Media stereotyped types
- MediaLibraryPickerFieldLocalizationExtensionHandler: Updates the media items within the field according to field settings
- Settings for translation behaviours for MediaLibraryPickerField
- Adds warning on localizing media items
- form filter media by culture

"MediaLibrary" feature:
- Implemented Cloning methods of all medias PartDrivers
- MediaPartHandler: Adds a check to prevent file system media deletion when the file is referenced by other medias
- ClientStorageController: Adds a check to prevent file system media deletion when the file is referenced by other medias

"Localization" feature:
- Adds a logic to propagate returnurl parameter to the redirection url
- ILocalizationService: Adds a new method to set the culture of a content and at the same time the master content of it
- Propagate returnurl parameter if necessary

"Search" feature:
- updated json of media items called via ajax

# Conflicts:
#	src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs
#	src/Orchard.Web/Modules/Orchard.MediaLibrary/Drivers/MediaPartDriver.cs
#	src/Orchard.Web/Modules/Orchard.MediaLibrary/Drivers/OEmbedPartDriver.cs
#	src/Orchard.Web/Modules/Orchard.MediaLibrary/Orchard.MediaLibrary.csproj
@HermesSbicego-Laser
HermesSbicego-Laser deleted the issue/7843_media_localization_extensions branch May 14, 2019 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants