aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/gettext.rake42
-rw-r--r--lib/tasks/stats.rake26
-rw-r--r--lib/tasks/submodules.rake28
-rw-r--r--lib/tasks/temp.rake55
4 files changed, 123 insertions, 28 deletions
diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake
index ace7205ae..366dfbe88 100644
--- a/lib/tasks/gettext.rake
+++ b/lib/tasks/gettext.rake
@@ -9,27 +9,31 @@ namespace :gettext do
end
end
- desc "Update pot file only, without fuzzy guesses (these are done by Transifex)"
- task :findpot => :environment do
+ desc "Update pot/po files for a theme."
+ task :find_theme => :environment do
+ theme = ENV['THEME']
+ unless theme
+ puts "Usage: Specify an Alaveteli-theme with THEME=[theme directory name]"
+ exit(0)
+ end
load_gettext
- $LOAD_PATH << File.join(File.dirname(__FILE__),'..','..','lib')
- require 'gettext_i18n_rails/haml_parser'
- files = files_to_translate
+ msgmerge = Rails.application.config.gettext_i18n_rails.msgmerge
+ msgmerge ||= %w[--sort-output --no-location --no-wrap]
+ GetText.update_pofiles_org(
+ text_domain,
+ theme_files_to_translate(theme),
+ "version 0.0.1",
+ :po_root => theme_locale_path(theme),
+ :msgmerge => msgmerge
+ )
+ end
- #write found messages to tmp.pot
- temp_pot = "tmp.pot"
- GetText::rgettext(files, temp_pot)
+ def theme_files_to_translate(theme)
+ Dir.glob("{vendor/plugins/#{theme}/lib}/**/*.{rb,erb}")
+ end
- #merge tmp.pot and existing pot
- FileUtils.mkdir_p('locale')
- GetText::msgmerge("locale/app.pot", temp_pot, "alaveteli", :po_root => 'locale', :msgmerge=>[ :no_wrap, :sort_output ])
- Dir.glob("locale/*/app.po") do |po_file|
- GetText::msgmerge(po_file, temp_pot, "alaveteli", :po_root => 'locale', :msgmerge=>[ :no_wrap, :sort_output ])
- end
- File.delete(temp_pot)
- end
+ def theme_locale_path(theme)
+ File.join(Rails.root, "vendor", "plugins", theme, "locale-theme")
+ end
- def files_to_translate
- Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml,rhtml}")
- end
end
diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake
index 9d7d70540..4eda27289 100644
--- a/lib/tasks/stats.rake
+++ b/lib/tasks/stats.rake
@@ -91,4 +91,30 @@ namespace :stats do
end
end
+ desc 'Update statistics in the public_bodies table'
+ task :update_public_bodies_stats => :environment do
+ verbose = ENV['VERBOSE'] == '1'
+ PublicBody.all.each do |public_body|
+ puts "Counting overdue requests for #{public_body.name}" if verbose
+
+ # Look for values of 'waiting_response_overdue' and
+ # 'waiting_response_very_overdue' which aren't directly in the
+ # described_state column, and instead need to be calculated:
+ overdue_count = 0
+ very_overdue_count = 0
+ InfoRequest.find_each(:conditions => {:public_body_id => public_body.id}) do |ir|
+ case ir.calculate_status
+ when 'waiting_response_very_overdue'
+ very_overdue_count += 1
+ when 'waiting_response_overdue'
+ overdue_count += 1
+ end
+ end
+ public_body.info_requests_overdue_count = overdue_count + very_overdue_count
+ public_body.no_xapian_reindex = true
+ public_body.without_revision do
+ public_body.save!
+ end
+ end
+ end
end
diff --git a/lib/tasks/submodules.rake b/lib/tasks/submodules.rake
new file mode 100644
index 000000000..426192713
--- /dev/null
+++ b/lib/tasks/submodules.rake
@@ -0,0 +1,28 @@
+
+namespace :submodules do
+
+ desc "Check the status of the project's submodules"
+ task :check => :environment do
+ commit_info = `git submodule status commonlib`
+ case commit_info[0,1]
+ when '+'
+ $stderr.puts "Error: Currently checked out submodule commit for commonlib"
+ $stderr.puts "does not match the commit expected by this version of Alaveteli."
+ $stderr.puts "You can update it with 'git submodule update'."
+ exit(1)
+ when '-'
+ $stderr.puts "Error: Submodule commonlib needs to be initialized."
+ $stderr.puts "You can do this by running 'git submodule update --init'."
+ exit(1)
+ when 'U'
+ $stderr.puts "Error: Submodule commonlib has merge conflicts."
+ $stderr.puts "You'll need to resolve these to run Alaveteli."
+ exit(1)
+ when ' '
+ exit(0)
+ else
+ raise "Unexpected status character in response to 'git submodule status commonlib': #{commit_info[0,1]}"
+ end
+ end
+
+end
diff --git a/lib/tasks/temp.rake b/lib/tasks/temp.rake
index fcabb23de..d371ad0dc 100644
--- a/lib/tasks/temp.rake
+++ b/lib/tasks/temp.rake
@@ -1,5 +1,36 @@
namespace :temp do
+ desc "Fix the history of requests where the described state doesn't match the latest status value
+ used by search, by adding an edit event that will correct the latest status"
+ task :fix_bad_request_states => :environment do
+ dryrun = ENV['DRYRUN'] != '0'
+ if dryrun
+ puts "This is a dryrun"
+ end
+
+ InfoRequest.find_each() do |info_request|
+ next if info_request.url_title == 'holding_pen'
+ last_info_request_event = info_request.info_request_events[-1]
+ if last_info_request_event.latest_status != info_request.described_state
+ puts "#{info_request.id} #{info_request.url_title} #{last_info_request_event.latest_status} #{info_request.described_state}"
+ params = { :script => 'rake temp:fix_bad_request_states',
+ :user_id => nil,
+ :old_described_state => info_request.described_state,
+ :described_state => info_request.described_state
+ }
+ if ! dryrun
+ info_request.info_request_events.create!(:last_described_at => last_info_request_event.described_at + 1.second,
+ :event_type => 'status_update',
+ :described_state => info_request.described_state,
+ :calculated_state => info_request.described_state,
+ :params => params)
+ info_request.info_request_events.each{ |event| event.xapian_mark_needs_index }
+ end
+ end
+
+ end
+ end
+
def disable_duplicate_account(user, count, dryrun)
dupe_email = "duplicateemail#{count}@example.com"
puts "Updating #{user.email} to #{dupe_email} for user #{user.id}"
@@ -13,15 +44,21 @@ namespace :temp do
total_messages = 0
messages_to_reparse = 0
IncomingMessage.find_each :include => :foi_attachments do |im|
- reparse = im.foi_attachments.any? { |fa| ! File.exists? fa.filepath }
- total_messages += 1
- messages_to_reparse += 1 if reparse
- if total_messages % 1000 == 0
- puts "Considered #{total_messages} received emails."
- end
- unless dry_run
- im.parse_raw_email! true if reparse
- sleep 2
+ begin
+ reparse = im.foi_attachments.any? { |fa| ! File.exists? fa.filepath }
+ total_messages += 1
+ messages_to_reparse += 1 if reparse
+ if total_messages % 1000 == 0
+ puts "Considered #{total_messages} received emails."
+ end
+ unless dry_run
+ im.parse_raw_email! true if reparse
+ sleep 2
+ end
+ rescue StandardError => e
+ puts "There was a #{e.class} exception reparsing IncomingMessage with ID #{im.id}"
+ puts e.backtrace
+ puts e.message
end
end
message = dry_run ? "Would reparse" : "Reparsed"