# Content lifecycle

## Overview

When working with the content modules in Sitefinity CMS, you can either directly publish items that you create, or save them as drafts. These operations create some different versions of the same content behind the scenes. The versions adhere to a strictly defined content lifecycle. This article demonstrates how content lifecycle works, how to use the API to perform these operations, and how to do the same through the user interface.

## What is Content Lifecycle?

Content lifecycle governs whether an item is visible on the frontend or whether it is being edited in the backend. There are four lifecycle states of an item:

* `master`
* `temp`
* `live`
* `deleted`

When persisting items in the database, Sitefinity CMS creates one row for each state. You can think of lifecycle states as separate versions of an item. An important characteristic of the lifecycle is that an item can be in more than one state at a time - can have several versions. The meaning of each state (item version) is defined in the following table:

<table cellspacing="0" cellpadding="2" border="0"><colgroup><col><col></colgroup>
<tbody><tr><td valign="top" width="96">

<em>Master</em>

</td><td valign="top" width="499"><p>The default state of an item. </p><p>Items are always created in 

<em>Master</em>
state first - they always have a master version. Master versions are not visible in the frontend.</p></td></tr><tr><td valign="top" width="100">

<em>Live</em>

</td><td valign="top" width="496">

<p>An item, which is visible in the frontend. </p><p>Once an item is published, Sitefinity CMS creates a live version by copying the item from the master version (the master version continues to exist).</p>
</td></tr><tr><td valign="top" width="103">

<em>Temp</em>

</td><td valign="top" width="493"><p>An item that is being edited by a CMS user. </p><p>When you open an item for editing, a temp version of the item is created by copying the <em>Master</em> version.</p>
<ul>
<li>Save as <em>Draft</em> copies the changes from the Temp version to the Master version </li>
<li><em>Publish</em> copies the changes from the <em>Temp</em> version to the <em>Master</em> version, and then creates a <em>Live</em> version.</li></ul>
</td></tr>
<tr><td valign="top" width="103">

<em>Deleted</em>

</td><td>When the <em>Recycle bin</em>module is active, if you delete an item of a type that supports recycling, Sitefinity CMS keeps the items persisted, but marks it as deleted.

<ul>
<li>If the item has a <em>Temp</em> version, the <em>Temp</em> item is deleted.</li>
<li>If the item has a <em>Live</em> version, the item's visibility setting is set to <em>False</em>. Thus, the item is not available on the frontend (similar to being unpublished).</li>
<li>The lifecycle state of the <em>Master</em> version of the item is changed to <em>Deleted</em>
.</li>
</ul>

Therefore, the item does not appear in the frontend, or in the backend, but is available for restoration in the <em>Recycle bin</em>.
<br>For more information see <a href="/for-developers-recycle-bin-module" data-sf-ec-immutable="">Recycle bin module</a>.</td></tr></tbody></table>

## Information flow

![](https://www.progress.com/documentation/sitefinity-cms/assets/9bb6a127fc8b3746bbdd83b605e84912/contentlifecycletransitions.png "ContentLifecycleTransitions")

The diagram shows a simplified view of how the information flows between the different lifecycle states of an item. The circles represent the states, and the arrows represent operations on the item. Each operation, triggered by the user interface or the API, moves an item between the states. These states are different versions of an item.

The following process illustrates the state of the database and the user interface after each operation. It uses the *News* module as an example.

1. **Create a News item**    When you click the *Create* button, the screen for creating an item appears, but there is nothing persisted yet. The table in the database is empty.   /documentation/sitefinity-cms/sf-images/default-source/developers-guide/createnewsitemui.png?sfvrsn=6e849345_0 [![Create a News Item UI](https://www.progress.com/documentation/sitefinity-cms/assets/661eaf6d09cb67b8577c79064bdfa169/create-a-news-item-ui.jpg "Create a News Item UI")](https://www.progress.com/documentation/sitefinity-cms/assets/661eaf6d09cb67b8577c79064bdfa169/create-a-news-item-ui.jpg)/documentation/sitefinity-cms/sf-images/default-source/developers-guide/createnewsitemdb.png?sfvrsn=8635f849_4[![No results in the DB](https://www.progress.com/documentation/sitefinity-cms/assets/680f8822aa2b812853b7991b870ac7ed/picture3.png "No results in the DB")](https://www.progress.com/documentation/sitefinity-cms/assets/680f8822aa2b812853b7991b870ac7ed/picture3.png)
2. **Save the item as draft**    When you click the *Save as Draft* button, the item is persisted in the database. Its state in the UI is *Draft*. There are two records in the database: the *Master* with a status of 0, and the *Temp* with status 1.    [![Save as Draft DB state](https://www.progress.com/documentation/sitefinity-cms/assets/f4d0af8b4fdbe4b877607d8af6f621f9/picture4.png "Save as Draft DB state")](https://www.progress.com/documentation/sitefinity-cms/assets/f4d0af8b4fdbe4b877607d8af6f621f9/picture4.png)    Because you are not publishing the item, you only need to call the `SaveChanges()` method of the manager to persist the draft in the database.
3. **Publish the item**    Next, publish the item you just created. This marks it as *Published* in the UI and creates another entry in the database table, to represent the *Live* version of the item. The value 2 in the status column corresponds to the *Live* state. The *Master* and the *Temp* values continue to exist in the database.   [![Publish item DB state](https://www.progress.com/documentation/sitefinity-cms/assets/0985cb89eb828794882686d90c3afa13/picture6.png "Publish item DB state")](https://www.progress.com/documentation/sitefinity-cms/assets/0985cb89eb828794882686d90c3afa13/picture6.png)   To make the item visible in the frontend and create a *Live* version, you explicitly publish the item through the API.
4. **Edit the item**    If you want to make more changes to the same *News* item, edit it. Other users see the item as locked. The entry in the database, representing the *Temp* version of the item with status 1, holds the changed information from your edit.          [![Publish item DB state](https://www.progress.com/documentation/sitefinity-cms/assets/0985cb89eb828794882686d90c3afa13/picture6.png "Publish item DB state")](https://www.progress.com/documentation/sitefinity-cms/assets/0985cb89eb828794882686d90c3afa13/picture6.png)  When you want to edit an item that was created using the API, you need to explicitly get its *Master* version. To create a *Temp* version from it, you call the` CheckOut()` method of the **Lifecycle**   decorator, and once you made the changes, you call `CheckIn()` to copy the *Temp* version to the *Master* again.
5. **Publish the item again**    Publishing the item again goes back to the state from *Step 3*, but now the item’s content has been updated. The UI shows the item as *Published* again.    [![Publish item DB state](https://www.progress.com/documentation/sitefinity-cms/assets/0985cb89eb828794882686d90c3afa13/picture6.png "Publish item DB state")](https://www.progress.com/documentation/sitefinity-cms/assets/0985cb89eb828794882686d90c3afa13/picture6.png)    To publishing the item again, call the publish method of the `Lifecycle` decorator and saving the changes.

In the steps above, you explicitly save the item as draft to illustrate the lifecycle. You can also directly publish the item through the UI, and Sitefinity CMS performs the two operations together in the same order. There will be no difference in the state transitions between those two cases.

Understanding the concept of content lifecycle is important when working with items through the API.

> info **RECOMMENDATION**: The content lifecycle API is a low level API and does not support all possible scenarios. We recommend using the Web services API instead.

Following is a code sample that demonstrates the above operations:
