private function setState($state)
{
if (!in_array($state, $this->available_states)) {
throw new RepositoryException("Invalid state [{$state}]");
}
$this->state = $state;
// -------------------------------------------------------------------------------------
// see the phpdoc of rollbackTransaction()
//
// In the cases 6 and 7, when the state is CLEAN before the TRX and CLEAN at the end of
// the TRX, the final state will be different if the item has been modified during
// the TRX or not.
//
// The following test covers that special case, if the item is modified during the TRX,
// we set the saved state to MODIFIED so that it can be restored as it is when the TRX
// is rolled back.
if (self::STATE_MODIFIED === $state && self::STATE_CLEAN === $this->savedState) {
$this->savedState = self::STATE_MODIFIED;
}
}