diff --git a/cps.module b/cps.module index 41e5f2490e..d662622de7 100644 --- a/cps.module +++ b/cps.module @@ -1021,7 +1021,7 @@ function _cps_purge_changeset_entity_revisions($entity_type, $entity_id, $change */ function cps_is_entity_in_changeset($entity_type, $entity, $changeset_id) { list($id) = entity_extract_ids($entity_type, $entity); - $tracked = cps_get_tracked_entities($changeset_id); + $tracked = cps_get_tracked_entities($changeset_id, FALSE); return isset($tracked[$entity_type][$id]); } @@ -1073,22 +1073,28 @@ function cps_can_entity_be_tracked($entity_type, $entity) { * * @param $changeset_id * A changeset ID. + * @param bool $unpublished_only + * Return only unpublished entities. * * @return * A nested array. First keyed by entity type, then by entity ID, with * revision IDs as values. * type. */ -function cps_get_tracked_entities($changeset_id) { +function cps_get_tracked_entities($changeset_id, $unpublished_only = TRUE) { $cache = &drupal_static(__FUNCTION__, array()); - if (!isset($cache[$changeset_id])) { + if (!isset($cache[$changeset_id][$unpublished_only])) { $cache[$changeset_id] = array(); - $result = db_query('SELECT entity_type, entity_id, revision_id FROM {cps_entity} WHERE changeset_id = :changeset_id AND published = 0', array(':changeset_id' => $changeset_id)); + $sql = 'SELECT entity_type, entity_id, revision_id FROM {cps_entity} WHERE changeset_id = :changeset_id'; + if ($unpublished_only) { + $sql .= ' AND published=0'; + } + $result = db_query($sql, array(':changeset_id' => $changeset_id)); foreach ($result as $record) { - $cache[$changeset_id][$record->entity_type][$record->entity_id] = $record->revision_id; + $cache[$changeset_id][$unpublished_only][$record->entity_type][$record->entity_id] = $record->revision_id; } } - return $cache[$changeset_id]; + return $cache[$changeset_id][$unpublished_only]; } /** @@ -2376,11 +2382,11 @@ function cps_entity_in_unpublished_changeset($entity_type, $entity, $exclude_cur * Either 'move' or 'copy'. 'copy' is the default if not known. */ function cps_move_changeset($changeset_from, $changeset_to, $entity_type, $entity, $move_type) { - module_invoke_all('cps_move_changeset', $changeset_from, $changeset_to, $entity_type, $entity, $move_type); - list($entity_id, $revision_id) = entity_extract_ids($entity_type, $entity); - $transaction = db_transaction(); try { + module_invoke_all('cps_move_changeset', $changeset_from, $changeset_to, $entity_type, $entity, $move_type); + list($entity_id, $revision_id) = entity_extract_ids($entity_type, $entity); + // When moving just update the record for the old changeset to point to // the new one. if ($move_type == 'move') {