Optimizely has a featured called 'Projects', which allows editors to collaborate on content before scheduling to publish.
Problem
While work on a project that imports hundreds, of pieces of content. These pieces of content are added to a project for the team to review and mark the items as ready to publish.
You can see the problem here in that with hundreds of pieces of content to review, marking each content piece as ready to publish could take some time.
Solution
To over come the problem we decided to create a scheduled job that would loop over all items in a project and mark them as ready to publish.
To retrieve the projects and their project items we can get an instance of the 'ProjectRepository' into our scheduled job.
Once we have the project and its items we can then loop over the project items and use the 'IContentChangeManager' interface to update the status of the content items.
var projects = _projectRepository.List();
foreach (var project in projects)
{
var projectItemIds = _projectRepository.ListItems(project.ID).Select(x => x.ID);
foreach (int projectItemId in projectItemIds)
{
ProjectItem projectItem = GetProjectItem(projectItemId);
if (projectItem != null)
{
CommitResult commitResult = _contentChangeManager.Commit(projectItem.ContentLink, SaveAction.CheckIn);
}
}
}
public ProjectItem GetProjectItem(int projectItemId) => _projectRepository.GetItem(projectItemId);
I just wanted to share this piece of code with anyone who was trying to achieve something similiar.
Top comments (1)
Just FYI, authors can multi-select items within a project (using shift-click or ctrl-click) and change their status all at once.