aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-02-04 17:18:05 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-02-04 17:58:21 +0100
commit070c3e240aec5697ef7e715fc18bacdb14fce9ef (patch)
treefb5ab1f7c13f1d90a5acb1fc0996cae7c7bed34a /server/sonar-web/src
parent67d215ac9c43b048885d072e12de759855e4b80a (diff)
downloadsonarqube-070c3e240aec5697ef7e715fc18bacdb14fce9ef.tar.gz
sonarqube-070c3e240aec5697ef7e715fc18bacdb14fce9ef.zip
SONAR-5183 - analysis unsensitive to timezones - snapshots table
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb2
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb2
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb35
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/db/migrate/775_add_snapshots_long_dates.rb34
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/db/migrate/776_feed_snapshots_long_dates.rb29
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/db/migrate/777_rename_snapshots_long_dates.rb42
6 files changed, 141 insertions, 3 deletions
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb
index bb6189a6fad..ebf29970d09 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb
@@ -130,7 +130,7 @@ class Api::EventsController < Api::ApiController
if (params[:dateTime])
# try to find a snapshot on that day
date = parse_datetime(params[:dateTime], true)
- root_snapshot = Snapshot.find(:last, :conditions => ["project_id = ? AND created_at >= ? AND created_at <= ?", @resource.id, date, date + 1.day], :order => :created_at)
+ root_snapshot = Snapshot.find(:last, :conditions => ["project_id = ? AND created_at >= ? AND created_at <= ?", @resource.id, date.to_i*1000, (date + 1.day).to_i*1000], :order => :created_at)
raise "No snapshot exists for given date" unless root_snapshot
else
root_snapshot = Snapshot.find(:last, :conditions => ["project_id = ?", @resource.id], :order => :created_at)
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
index ec55ef12904..5bcc25b9c4e 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
@@ -324,7 +324,7 @@ class ProjectController < ApplicationController
access_denied unless is_admin?(parent_snapshot)
# We update all the related snapshots to have the same version as the next snapshot
- next_snapshot = Snapshot.find(:first, :conditions => ['created_at>? and project_id=?', parent_snapshot.created_at, parent_snapshot.project_id], :order => 'created_at asc')
+ next_snapshot = Snapshot.find(:first, :conditions => ['created_at>? and project_id=?', parent_snapshot.created_at.to_i*1000, parent_snapshot.project_id], :order => 'created_at asc')
snapshots = find_project_snapshots(parent_snapshot.id)
snapshots.each do |snapshot|
snapshot.version = next_snapshot.version
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb
index 52192c35289..3e43cf885f2 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb
@@ -36,6 +36,39 @@ class Snapshot < ActiveRecord::Base
STATUS_UNPROCESSED = 'U'
STATUS_PROCESSED = 'P'
+
+ def created_at
+ long_to_date(:created_at)
+ end
+
+ def build_date
+ long_to_date(:build_date)
+ end
+
+ def period1_date
+ long_to_date(:period1_date)
+ end
+
+ def period2_date
+ long_to_date(:period2_date)
+ end
+
+ def period3_date
+ long_to_date(:period3_date)
+ end
+
+ def period4_date
+ long_to_date(:period4_date)
+ end
+
+ def period5_date
+ long_to_date(:period5_date)
+ end
+
+ def long_to_date(attribute)
+ date_in_long = read_attribute(attribute)
+ Time.at(date_in_long/1000) if date_in_long
+ end
def self.for_timemachine_matrix(resource)
# http://jira.codehaus.org/browse/SONAR-1850
@@ -185,7 +218,7 @@ class Snapshot < ActiveRecord::Base
def self.snapshot_by_date(resource_id, date)
if resource_id && date
- Snapshot.find(:first, :conditions => ['created_at>=? and created_at<? and project_id=?', date.beginning_of_day, date.end_of_day, resource_id], :order => 'created_at desc')
+ Snapshot.find(:first, :conditions => ['created_at>=? and created_at<? and project_id=?', date.beginning_of_day.to_i*1000, date.end_of_day.to_i*1000, resource_id], :order => 'created_at desc')
else
nil
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/775_add_snapshots_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/775_add_snapshots_long_dates.rb
new file mode 100644
index 00000000000..389046ff1a8
--- /dev/null
+++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/775_add_snapshots_long_dates.rb
@@ -0,0 +1,34 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+#
+# SonarQube 5.1
+#
+class AddSnapshotsLongDates < ActiveRecord::Migration
+ def self.up
+ add_column 'snapshots', :created_at_ms, :big_integer, :null => true
+ add_column 'snapshots', :build_date_ms, :big_integer, :null => true
+ add_column 'snapshots', :period1_date_ms, :big_integer, :null => true
+ add_column 'snapshots', :period2_date_ms, :big_integer, :null => true
+ add_column 'snapshots', :period3_date_ms, :big_integer, :null => true
+ add_column 'snapshots', :period4_date_ms, :big_integer, :null => true
+ add_column 'snapshots', :period5_date_ms, :big_integer, :null => true
+ end
+end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/776_feed_snapshots_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/776_feed_snapshots_long_dates.rb
new file mode 100644
index 00000000000..42e272f7e42
--- /dev/null
+++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/776_feed_snapshots_long_dates.rb
@@ -0,0 +1,29 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+#
+# SonarQube 5.1
+#
+class FeedSnapshotsLongDates < ActiveRecord::Migration
+ def self.up
+ execute_java_migration('org.sonar.server.db.migrations.v51.FeedSnapshotsLongDates')
+ end
+end
+
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/777_rename_snapshots_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/777_rename_snapshots_long_dates.rb
new file mode 100644
index 00000000000..9f35dd50c42
--- /dev/null
+++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/777_rename_snapshots_long_dates.rb
@@ -0,0 +1,42 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+#
+# SonarQube 5.1
+#
+class RenameSnapshotsLongDates < ActiveRecord::Migration
+ def self.up
+ remove_column 'snapshots', 'created_at'
+ remove_column 'snapshots', 'build_date'
+ remove_column 'snapshots', 'period1_date'
+ remove_column 'snapshots', 'period2_date'
+ remove_column 'snapshots', 'period3_date'
+ remove_column 'snapshots', 'period4_date'
+ remove_column 'snapshots', 'period5_date'
+ rename_column 'snapshots', 'created_at_ms', 'created_at'
+ rename_column 'snapshots', 'build_date_ms', 'build_date'
+ rename_column 'snapshots', 'period1_date_ms', 'period1_date'
+ rename_column 'snapshots', 'period2_date_ms', 'period2_date'
+ rename_column 'snapshots', 'period3_date_ms', 'period3_date'
+ rename_column 'snapshots', 'period4_date_ms', 'period4_date'
+ rename_column 'snapshots', 'period5_date_ms', 'period5_date'
+ end
+end
+