/** * * * @param array $idList */ public function removeStatesByID($idList) { $newDefaultStateID = null; $removeIDList = array(); $db = eZDB::instance(); $db->begin(); $states = $this->states(); foreach ($states as $state) { $stateID = $state->attribute('id'); if (in_array($stateID, $idList)) { $removeIDList[] = $stateID; } else { if ($newDefaultStateID === null) { $newDefaultStateID = $stateID; } } } $removeIDListCount = count($removeIDList); if ($removeIDListCount > 0) { if ($newDefaultStateID) { $contentObjectStateIDCondition = $removeIDListCount > 1 ? $db->generateSQLINStatement($removeIDList, 'contentobject_state_id') : "contentobject_state_id={$removeIDList['0']}"; $db->query("UPDATE ezcobj_state_link\n SET contentobject_state_id={$newDefaultStateID}\n WHERE {$contentObjectStateIDCondition}"); eZContentObjectState::cleanDefaultsCache(); } foreach ($removeIDList as $id) { eZContentObjectState::removeByID($id); } // re-order remaining states in the same group $states = $this->states(true); $i = 0; foreach ($states as $state) { $state->setAttribute('priority', $i); $state->sync(array('priority')); $i++; } } $db->commit(); }