diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-03-21 09:30:53 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-03-21 09:30:53 +0100 |
commit | 884150008f92a229bef6666b27b359a690995616 (patch) | |
tree | 7f265b99a6cb9e4c7e8fb8e91103532920b5af5f | |
parent | 55adf33f94ec33c30f127f664248a3e84c9ea161 (diff) | |
download | sonarqube-884150008f92a229bef6666b27b359a690995616.tar.gz sonarqube-884150008f92a229bef6666b27b359a690995616.zip |
SONAR-4206 Fix transaction issue
3 files changed, 17 insertions, 3 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java index afe4428ce26..b0daecf6314 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java @@ -102,6 +102,7 @@ public class ProfilesManager extends BaseDao { * @param ruleId */ public void removeActivatedRules(int ruleId) { + String user = "System"; Rule rule = getSession().getEntity(Rule.class, ruleId); List<RulesProfile> profiles = getSession().createQuery("FROM " + RulesProfile.class.getSimpleName()).getResultList(); for (RulesProfile profile : profiles) { @@ -109,7 +110,10 @@ public class ProfilesManager extends BaseDao { for (ActiveRule activeRule : profile.getActiveRules(true)) { if (activeRule.getRule().equals(rule) && !activeRule.isInherited()) { incrementProfileVersionIfNeeded(profile); - deactivated(profile.getId(), activeRule.getId(), "System"); + ruleDisabled(profile, activeRule, user); + for (RulesProfile child : getChildren(profile.getId())) { + deactivate(child, activeRule.getRule(), user); + } activeRulesToRemove.add(activeRule); } } diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java index c594751c66e..ca89fe12818 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java @@ -82,9 +82,9 @@ public final class RegisterRules { disableDeprecatedRepositories(existingRules, session); disableDeprecatedUserRules(profiler, existingRules, session); - notifyForRemovedRules(existingRules); - session.commit(); + + notifyForRemovedRules(existingRules); } private List<Rule> findAllRules(DatabaseSession session) { diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java index 1f8be4443e4..283e662813c 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java @@ -50,8 +50,10 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; public class RegisterRulesTest extends AbstractDbUnitTestCase { @@ -99,6 +101,14 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { } @Test + public void should_notify_for_removed_rules() { + setupData("shared"); + task.start(); + + verify(profilesManager).removeActivatedRules(anyInt()); + } + + @Test public void should_reactivate_disabled_rules() { setupData("reactivateDisabledRules"); task.start(); |