Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

redmine.rake 6.2KB

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