Project

General

Profile

Patch #29649 » 0001-Add-a-rake-task-to-dump-whole-wikis.patch

Lorenz Schori, 2018-09-20 13:00

View differences:

lib/tasks/wikidump.rake
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU 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.
namespace :redmine do
namespace :wikidump do
def export_wiki(project, template, path)
pages = project.wiki.pages.
order('title').
includes([:content, {:attachments => :author}]).
to_a
assigns = {
:wiki => project.wiki,
:project => project,
:pages => pages,
}
view = ActionView::Base.new(ActionController::Base.view_paths, assigns, ActionController::Base.new)
view.class_eval do
include Rails.application.routes.url_helpers
include ApplicationHelper
include WikiHelper
def url_options
{host: Setting.host_name.split('/')[0]}
end
end
File.open(path, "wb") do |f|
f.write(view.render(:template => template))
end
end
desc <<-END_DESC
Dump the wiki of a project to a PDF file.
Available options:
* project => id or identifier of project (defaults to first projects)
* directory => output directory (defaults to rails temporary directory)
Example:
rake redmine:wikidump:pdf project=my-project-identifier directory=/tmp RAILS_ENV="production"
END_DESC
task :pdf => :environment do
project = ENV['project'] ? Project.find(ENV['project']) : Project.first
directory = ENV['directory'] || "#{Rails.root}/tmp"
path = File.join(directory, "#{project.identifier}.pdf")
export_wiki(project, 'wiki/export.pdf', path)
end
desc <<-END_DESC
Dump the wiki of a project to a HTML file.
Available options:
* project => id or identifier of project (defaults to first projects)
* directory => output directory (defaults to rails temporary directory)
Example:
rake redmine:wikidump:html project=my-project-identifier directory=/tmp RAILS_ENV="production"
END_DESC
task :html => :environment do
project = ENV['project'] ? Project.find(ENV['project']) : Project.first
directory = ENV['directory'] || "#{Rails.root}/tmp"
path = File.join(directory, "#{project.identifier}.html")
export_wiki(project, 'wiki/export_multiple.html', path)
end
end
end
(1-1/3)