DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 968,547 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Paul McGann
Paul McGann

Posted on

Working with Optimizely Projects

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);

Enter fullscreen mode Exit fullscreen mode

I just wanted to share this piece of code with anyone who was trying to achieve something similiar.

Top comments (1)

Collapse
 
danielisaacs profile image
Daniel Isaacs

Just FYI, authors can multi-select items within a project (using shift-click or ctrl-click) and change their status all at once.

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›