From 5a790391e41fd7c68c14c23db4e66985cf7a2c26 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 19 Jun 2013 18:21:49 +0200 Subject: [PATCH] SONAR-3879 Template rules status should not updated to their parent status --- .../main/java/org/sonar/server/startup/RegisterRules.java | 5 +++-- .../webapp/WEB-INF/db/migrate/381_update_rules_status.rb | 2 +- .../java/org/sonar/server/startup/RegisterRulesTest.java | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) 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 5a06588e1b9..79a340d316b 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 @@ -121,7 +121,7 @@ public final class RegisterRules { } /** - * Template rules do not exists in the rule repository, only in database, but have to be updated from their parent rule. + * Template rules do not exists in rule repositories, only in database, they have to be updated from their parent. */ private List registerTemplateRules(List registeredRules, RulesByRepository existingRules, DatabaseSession session) { List templateRules = newArrayList(); @@ -130,7 +130,8 @@ public final class RegisterRules { if (parent != null && registeredRules.contains(parent)) { persistedRule.setRepositoryKey(parent.getRepositoryKey()); persistedRule.setLanguage(parent.getLanguage()); - persistedRule.setStatus(parent.getStatus()); + persistedRule.setStatus(Objects.firstNonNull(persistedRule.getStatus(), Rule.STATUS_READY)); + persistedRule.setCreatedAt(Objects.firstNonNull(persistedRule.getCreatedAt(), new Date())); persistedRule.setUpdatedAt(new Date()); session.saveWithoutFlush(persistedRule); diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/381_update_rules_status.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/381_update_rules_status.rb index 909af4ce701..a159accc66b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/381_update_rules_status.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/381_update_rules_status.rb @@ -29,7 +29,7 @@ class UpdateRulesStatus < ActiveRecord::Migration def self.up Rule.reset_column_information Rule.update_all({:status => 'READY', :created_at => Time.now}, ['enabled=?', true]) - Rule.update_all({:status => 'REMOVED', :updated_at => Time.now}, ['enabled=?', false]) + Rule.update_all({:status => 'REMOVED', :created_at => Time.now, :updated_at => Time.now}, ['enabled=?', false]) end end 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 ff1b6f4f10b..abadc622f82 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 @@ -83,8 +83,8 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { rule = getSession().getSingleResult(Rule.class, "id", 4); assertThat(rule.getRepositoryKey(), is("fake")); assertThat(rule.getLanguage(), is("java")); - // Status was READY in db, but parent status is now DEPRECATED - assertThat(rule.getStatus(), is(Rule.STATUS_DEPRECATED)); + // parent status is now DEPRECATED but template should not be changed + assertThat(rule.getStatus(), is(Rule.STATUS_READY)); } @Test @@ -121,12 +121,12 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { } @Test - public void should_reactivate_disabled_template_rules() { + public void should_not_reactivate_disabled_template_rules() { setupData("should_reactivate_disabled_template_rules"); task.start(); Rule rule = getSession().getSingleResult(Rule.class, "id", 2); - assertThat(rule.getStatus(), is(Rule.STATUS_READY)); + assertThat(rule.getStatus(), is(Rule.STATUS_REMOVED)); assertThat(rule.getUpdatedAt(), notNullValue()); } -- 2.39.5