There are some quite useful seemingly undocumented services all over the place you can use.
With the following constructor
public class MigrationProjectType : DataMigrationImpl
{
private readonly IMenuService _menuService;
private readonly IContentManager _contentManager;
private readonly IQueryService _queryService;
private readonly IWidgetsService _widgetsService;
public MigrationProjectType(IMenuService menuService, IContentManager contentManager, IQueryService queryService, IWidgetsService widgetsService)
{
_menuService = menuService;
_contentManager = contentManager;
_queryService = queryService;
_widgetsService = widgetsService;
}
...
}
Auto fac will take care of instantiating the services
then
public int UpdateFrom2()
{
// create a project menu
var projectMenu = _menuService.Create("Projects Menu");
// assign the project items to all current menu items
foreach (var menuItem in _menuService.Get().Where(x => x.ContentItem.ContentType == "Project"))
{
// if they don't have a position or a text, then they are not displayed
if (string.IsNullOrWhiteSpace(menuItem.MenuPosition) || string.IsNullOrEmpty(menuItem.MenuText))
{
continue;
}
menuItem.Menu = projectMenu.ContentItem;
}
// create layer part
_widgetsService.CreateLayer("SideBar", "desc", "url(\"~\")");
var defaultLayer = _widgetsService.GetLayers().First(x => x.Name == "Default");
var widget = _widgetsService.CreateWidget(defaultLayer.Id, "MenuWidget", "Projects Menu", "2", "Navigation");
var menuWidget = widget.As<MenuWidgetPart>();
menuWidget.Record.Menu = projectMenu.ContentItem.Record;
_contentManager.Publish(menuWidget.ContentItem);
return 3;
}
there is a similar service for Queries, but I'm stil not sure how to add filters to queries, for projections...
UPDATE
heres how you can add a query and filter
public int UpdateFrom7()
{
// create a project menu
var projectMenu = _queryService.CreateQuery("My projects 3");
var form = new Form { ContentTypes = "Project" };
var xmlSerializer = new XmlSerializer(form.GetType());
StringWriter sww = new StringWriter();
XmlWriter writer = XmlWriter.Create(sww);
xmlSerializer.Serialize(writer, form);
var state = sww.ToString();
projectMenu.FilterGroups[0].Filters.Add(new FilterRecord
{
Category = "Content",
Description = "My filter",
Position = 0,
State = state,
Type = "ContentTypes"
});
_contentManager.Publish(projectMenu.ContentItem);
return 8;
}
[Serializable]
public class Form
{
public string Description { get; set; }
public string ContentTypes { get; set; }
}