public function setContentState($contentId, $groupId, $stateId)
{
// First find out if $contentId is related to existing states in $groupId
$query = $this->dbHandler->createSelectQuery();
$query->select($this->dbHandler->aliasedColumn($query, 'id', 'ezcobj_state'))->from($this->dbHandler->quoteTable('ezcobj_state'))->innerJoin($this->dbHandler->quoteTable('ezcobj_state_link'), $query->expr->eq($this->dbHandler->quoteColumn('id', 'ezcobj_state'), $this->dbHandler->quoteColumn('contentobject_state_id', 'ezcobj_state_link')))->where($query->expr->lAnd($query->expr->eq($this->dbHandler->quoteColumn('group_id', 'ezcobj_state'), $query->bindValue($groupId, null, \PDO::PARAM_INT)), $query->expr->eq($this->dbHandler->quoteColumn('contentobject_id', 'ezcobj_state_link'), $query->bindValue($contentId, null, \PDO::PARAM_INT))));
$statement = $query->prepare();
$statement->execute();
$rows = $statement->fetchAll(\PDO::FETCH_ASSOC);
if (!empty($rows)) {
// We already have a state assigned to $contentId, update to new one
$query = $this->dbHandler->createUpdateQuery();
$query->update($this->dbHandler->quoteTable('ezcobj_state_link'))->set($this->dbHandler->quoteColumn('contentobject_state_id'), $query->bindValue($stateId, null, \PDO::PARAM_INT))->where($query->expr->lAnd($query->expr->eq($this->dbHandler->quoteColumn('contentobject_id'), $query->bindValue($contentId, null, \PDO::PARAM_INT)), $query->expr->eq($this->dbHandler->quoteColumn('contentobject_state_id'), $query->bindValue($rows[0]['ezcobj_state_id'], null, \PDO::PARAM_INT))));
$query->prepare()->execute();
} else {
// No state assigned to $contentId from specified group, create assignment
$query = $this->dbHandler->createInsertQuery();
$query->insertInto($this->dbHandler->quoteTable('ezcobj_state_link'))->set($this->dbHandler->quoteColumn('contentobject_id'), $query->bindValue($contentId, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('contentobject_state_id'), $query->bindValue($stateId, null, \PDO::PARAM_INT));
$query->prepare()->execute();
}
}