/// <summary> /// To avoid completely re-scanning the whole media library after a change, we could simply update the current JSON storage /// with the items that were cleaned up by our module. But take in mind that external changes are still being ignored by this module. /// So for an accurate rendition of the media library data usage, a re-scan is necessary once in a while. /// </summary> /// <remarks> /// The backlog of this module contains an idea to create a pipeline processor for the onSave handler of all items, /// so the JSON storage could be updated continuously, never requiring a re-scan after the initial media library scan! /// </remarks> /// <param name="itemIDs">A list of Sitecore item ID strings of the items to update in the JSON storage.</param> /// <param name="actionType">An ActionType enum object to indicate whether to delete the items in the list, or to remove the old versions from them.</param> private void UpdateStorageAfterCleanUp(List <string> itemIDs, ActionType actionType) { MediaItemReport mediaItemRoot = null; JsonStorage mediaItemReportStorage = null; // read the media item report object from the JSON storage var mediaItemPath = Settings.GetSetting("Shrink.MediaItemReportPath"); if (!string.IsNullOrEmpty(mediaItemPath)) { mediaItemReportStorage = new JsonStorage(mediaItemPath); mediaItemRoot = mediaItemReportStorage.Deserialize <MediaItemReport>(); } if (mediaItemRoot != null) { // remove any children as supplied in the list of Sitecore item IDs this.RemoveChildren(mediaItemRoot, itemIDs, actionType); // write the updated JSON file to disk mediaItemReportStorage.Serialize(mediaItemRoot); // update the corresponding media library report JSON storage file with the updated info var libraryReportPath = Settings.GetSetting("Shrink.MediaLibraryReportPath"); if (!string.IsNullOrEmpty(libraryReportPath)) { var json = new JsonStorage(libraryReportPath); json.Serialize(new MediaLibraryReport(mediaItemRoot)); } } }
/// <summary> /// Writes the resulting report data to the configured JSON files. /// </summary> private void WriteReportsToDataStorage() { var mediaItemPath = Settings.GetSetting("Shrink.MediaItemReportPath"); if (!string.IsNullOrEmpty(mediaItemPath)) { var json = new JsonStorage(mediaItemPath); json.Serialize(this.MediaItemRoot); } var libraryReportPath = Settings.GetSetting("Shrink.MediaLibraryReportPath"); if (!string.IsNullOrEmpty(libraryReportPath)) { var json = new JsonStorage(libraryReportPath); json.Serialize(new MediaLibraryReport(this.MediaItemRoot)); } }