annotate lib/tasks/redmine.rake @ 1533:59e13100ea95 cannam

Fix to user lookup
author Chris Cannam
date Wed, 11 Feb 2015 14:17:38 +0000
parents dffacf8a6908
children
rev   line source
Chris@1115 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1115 3 #
Chris@1115 4 # This program is free software; you can redistribute it and/or
Chris@1115 5 # modify it under the terms of the GNU General Public License
Chris@1115 6 # as published by the Free Software Foundation; either version 2
Chris@1115 7 # of the License, or (at your option) any later version.
Chris@1115 8 #
Chris@1115 9 # This program is distributed in the hope that it will be useful,
Chris@1115 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1115 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1115 12 # GNU General Public License for more details.
Chris@1115 13 #
Chris@1115 14 # You should have received a copy of the GNU General Public License
Chris@1115 15 # along with this program; if not, write to the Free Software
Chris@1115 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1115 17
Chris@1115 18 namespace :redmine do
Chris@1115 19 namespace :attachments do
Chris@1115 20 desc 'Removes uploaded files left unattached after one day.'
Chris@1115 21 task :prune => :environment do
Chris@1115 22 Attachment.prune
Chris@1115 23 end
Chris@1464 24
Chris@1464 25 desc 'Moves attachments stored at the root of the file directory (ie. created before Redmine 2.3) to their subdirectories'
Chris@1464 26 task :move_to_subdirectories => :environment do
Chris@1464 27 Attachment.move_from_root_to_target_directory
Chris@1464 28 end
Chris@1115 29 end
Chris@1115 30
Chris@1115 31 namespace :tokens do
Chris@1115 32 desc 'Removes expired tokens.'
Chris@1115 33 task :prune => :environment do
Chris@1115 34 Token.destroy_expired
Chris@1115 35 end
Chris@1115 36 end
Chris@1115 37
Chris@1115 38 namespace :watchers do
Chris@1115 39 desc 'Removes watchers from what they can no longer view.'
Chris@1115 40 task :prune => :environment do
Chris@1115 41 Watcher.prune
Chris@1115 42 end
Chris@1115 43 end
Chris@1115 44
Chris@1115 45 desc 'Fetch changesets from the repositories'
Chris@1115 46 task :fetch_changesets => :environment do
Chris@1115 47 Repository.fetch_changesets
Chris@1115 48 end
Chris@1115 49
Chris@1115 50 desc 'Migrates and copies plugins assets.'
Chris@1115 51 task :plugins do
Chris@1115 52 Rake::Task["redmine:plugins:migrate"].invoke
Chris@1115 53 Rake::Task["redmine:plugins:assets"].invoke
Chris@1115 54 end
Chris@1115 55
Chris@1517 56 desc <<-DESC
Chris@1517 57 FOR EXPERIMENTAL USE ONLY, Moves Redmine data from production database to the development database.
Chris@1517 58 This task should only be used when you need to move data from one DBMS to a different one (eg. MySQL to PostgreSQL).
Chris@1517 59 WARNING: All data in the development database is deleted.
Chris@1517 60 DESC
Chris@1517 61
Chris@1517 62 task :migrate_dbms => :environment do
Chris@1517 63 ActiveRecord::Base.establish_connection :development
Chris@1517 64 target_tables = ActiveRecord::Base.connection.tables
Chris@1517 65 ActiveRecord::Base.remove_connection
Chris@1517 66
Chris@1517 67 ActiveRecord::Base.establish_connection :production
Chris@1517 68 tables = ActiveRecord::Base.connection.tables.sort - %w(schema_migrations plugin_schema_info)
Chris@1517 69
Chris@1517 70 if (tables - target_tables).any?
Chris@1517 71 abort "The following table(s) are missing from the target database: #{(tables - target_tables).join(', ')}"
Chris@1517 72 end
Chris@1517 73
Chris@1517 74 tables.each do |table_name|
Chris@1517 75 Source = Class.new(ActiveRecord::Base)
Chris@1517 76 Target = Class.new(ActiveRecord::Base)
Chris@1517 77 Target.establish_connection(:development)
Chris@1517 78
Chris@1517 79 [Source, Target].each do |klass|
Chris@1517 80 klass.table_name = table_name
Chris@1517 81 klass.reset_column_information
Chris@1517 82 klass.inheritance_column = "foo"
Chris@1517 83 klass.record_timestamps = false
Chris@1517 84 end
Chris@1517 85 Target.primary_key = (Target.column_names.include?("id") ? "id" : nil)
Chris@1517 86
Chris@1517 87 source_count = Source.count
Chris@1517 88 puts "Migrating %6d records from #{table_name}..." % source_count
Chris@1517 89
Chris@1517 90 Target.delete_all
Chris@1517 91 offset = 0
Chris@1517 92 while (objects = Source.offset(offset).limit(5000).order("1,2").to_a) && objects.any?
Chris@1517 93 offset += objects.size
Chris@1517 94 Target.transaction do
Chris@1517 95 objects.each do |object|
Chris@1517 96 new_object = Target.new(object.attributes)
Chris@1517 97 new_object.id = object.id if Target.primary_key
Chris@1517 98 new_object.save(:validate => false)
Chris@1517 99 end
Chris@1517 100 end
Chris@1517 101 end
Chris@1517 102 Target.connection.reset_pk_sequence!(table_name) if Target.primary_key
Chris@1517 103 target_count = Target.count
Chris@1517 104 abort "Some records were not migrated" unless source_count == target_count
Chris@1517 105 end
Chris@1517 106 end
Chris@1517 107
Chris@1115 108 namespace :plugins do
Chris@1115 109 desc 'Migrates installed plugins.'
Chris@1115 110 task :migrate => :environment do
Chris@1115 111 name = ENV['NAME']
Chris@1115 112 version = nil
Chris@1115 113 version_string = ENV['VERSION']
Chris@1115 114 if version_string
Chris@1115 115 if version_string =~ /^\d+$/
Chris@1115 116 version = version_string.to_i
Chris@1115 117 if name.nil?
Chris@1115 118 abort "The VERSION argument requires a plugin NAME."
Chris@1115 119 end
Chris@1115 120 else
Chris@1115 121 abort "Invalid VERSION #{version_string} given."
Chris@1115 122 end
Chris@1115 123 end
Chris@1115 124
Chris@1115 125 begin
Chris@1115 126 Redmine::Plugin.migrate(name, version)
Chris@1115 127 rescue Redmine::PluginNotFound
Chris@1115 128 abort "Plugin #{name} was not found."
Chris@1115 129 end
Chris@1115 130
Chris@1115 131 Rake::Task["db:schema:dump"].invoke
Chris@1115 132 end
Chris@1115 133
Chris@1115 134 desc 'Copies plugins assets into the public directory.'
Chris@1115 135 task :assets => :environment do
Chris@1115 136 name = ENV['NAME']
Chris@1115 137
Chris@1115 138 begin
Chris@1115 139 Redmine::Plugin.mirror_assets(name)
Chris@1115 140 rescue Redmine::PluginNotFound
Chris@1115 141 abort "Plugin #{name} was not found."
Chris@1115 142 end
Chris@1115 143 end
Chris@1115 144
Chris@1115 145 desc 'Runs the plugins tests.'
Chris@1115 146 task :test do
Chris@1115 147 Rake::Task["redmine:plugins:test:units"].invoke
Chris@1115 148 Rake::Task["redmine:plugins:test:functionals"].invoke
Chris@1115 149 Rake::Task["redmine:plugins:test:integration"].invoke
Chris@1115 150 end
Chris@1115 151
Chris@1115 152 namespace :test do
Chris@1115 153 desc 'Runs the plugins unit tests.'
Chris@1115 154 Rake::TestTask.new :units => "db:test:prepare" do |t|
Chris@1115 155 t.libs << "test"
Chris@1115 156 t.verbose = true
Chris@1115 157 t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/unit/**/*_test.rb"
Chris@1115 158 end
Chris@1115 159
Chris@1115 160 desc 'Runs the plugins functional tests.'
Chris@1115 161 Rake::TestTask.new :functionals => "db:test:prepare" do |t|
Chris@1115 162 t.libs << "test"
Chris@1115 163 t.verbose = true
Chris@1115 164 t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/functional/**/*_test.rb"
Chris@1115 165 end
Chris@1115 166
Chris@1115 167 desc 'Runs the plugins integration tests.'
Chris@1115 168 Rake::TestTask.new :integration => "db:test:prepare" do |t|
Chris@1115 169 t.libs << "test"
Chris@1115 170 t.verbose = true
Chris@1115 171 t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/integration/**/*_test.rb"
Chris@1115 172 end
Chris@1115 173 end
Chris@1115 174 end
Chris@1115 175 end
Chris@1115 176
Chris@1115 177 # Load plugins' rake tasks
Chris@1115 178 Dir[File.join(Rails.root, "plugins/*/lib/tasks/**/*.rake")].sort.each { |ext| load ext }