Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
Fix: errata IDs must be unique
Browse files Browse the repository at this point in the history
Errata IDs must be unique when cloning channel erratas. This patch
make sure that errata ID will not be duplicated before inserting them
into the database.

Fix for:
* [Bug 1539095](https://bugzilla.redhat.com/show_bug.cgi?id=1539095) - spacecmd softwarechannel_clonetree aborts with duplicate key value violates unique constraint "rhn_ce_ce_uq"
  • Loading branch information
mbologna authored and tkasparek committed Jul 31, 2018
1 parent 2531b1e commit d4b4704
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
Expand Down Expand Up @@ -1151,7 +1152,7 @@ public static void lock(Channel c) {
* @param eids List of eids to add mappings for
* @param cid channel id we're cloning into
*/
public static void addClonedErrataToChannel(List<Long> eids, Long cid) {
public static void addClonedErrataToChannel(Set<Long> eids, Long cid) {
WriteMode m = ModeFactory.getWriteMode("Channel_queries",
"add_cloned_erratum_to_channel");
Map<String, Object> params = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ActionForward execute(ActionMapping mapping,
//ErrataManager.publishErrataToChannelAsync(currentChan, errataIds, user);
List<ErrataOverview> errata = ErrataManager.errataInSet(user,
RhnSetDecl.setForChannelErrata(currentChan).get(user).getLabel());
List<Long> eids = ErrataManager.cloneChannelErrata(errata, currentChan.getId(),
Set<Long> eids = ErrataManager.cloneChannelErrata(errata, currentChan.getId(),
user);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1476,11 +1476,11 @@ public static void cloneChannelErrata(Long fromCid, Long toCid, User user) {
* @param user the requesting user
* @return list of errata ids that were published into channel
*/
public static List<Long> cloneChannelErrata(List<ErrataOverview> toClone, Long toCid,
public static Set<Long> cloneChannelErrata(List<ErrataOverview> toClone, Long toCid,
User user) {
List<OwnedErrata> owned = ErrataFactory
.listPublishedOwnedUnmodifiedClonedErrata(user.getOrg().getId());
List<Long> eids = new ArrayList<Long>();
Set<Long> eids = new HashSet<Long>();

// add published, cloned, owned errata to mapping. we want the oldest owned
// clone to reuse. listPublishedOwnedUnmodifiedClonedErrata orders by created,
Expand Down

0 comments on commit d4b4704

Please sign in to comment.