lib/caramelize/wiki/redmine_wiki.rb in caramelize-0.1.2 vs lib/caramelize/wiki/redmine_wiki.rb in caramelize-0.2.0
- old
+ new
@@ -1,23 +1,59 @@
#Encoding: UTF-8
module Caramelize
autoload :DatabaseConnector, 'caramelize/database_connector'
+ autoload :SwapWikiLinks, 'caramelize/filters/swap_wiki_links'
class RedmineWiki < Wiki
include DatabaseConnector
+ def initialize options={}
+ super(options)
+ @options[:markup] = :textile
+ @options[:create_namespace_home] = true unless @options[:create_namespace_home]
+ @options[:swap_interwiki_links] = true
+ @options[:filters] << Caramelize::SwapWikiLinks.new
+ end
# after calling this action, I expect the @titles and @revisions to be filled
def read_pages
- sql = "SELECT id, title FROM wiki_pages;"
@revisions = []
@titles = []
@latest_revisions = {}
- results_pages = database.query(sql)
+
+ # get all projects
+ results_projects = database.query("SELECT id, identifier, name FROM projects;")
+ results_projects.each do |row_project|
+ #collect all namespaces
+ @namespaces << {:identifier => row_project["identifier"], :name => row_project["name"]}
+ end
+
+ # get all wikis
+ results_wikis = database.query("SELECT id, project_id FROM wikis;")
+
+ # get all lemmas
+ results_pages = database.query("SELECT id, title, wiki_id FROM wiki_pages;")
results_pages.each do |row_page|
results_contents = database.query("SELECT * FROM wiki_content_versions WHERE page_id='#{row_page["id"]}' ORDER BY updated_on;")
- title = row_page["title"]
+
+ # get wiki for page
+ wiki_row = nil
+ project_row = nil
+ results_wikis.each do |wiki|
+ wiki_row = wiki if wiki["id"] == row_page["wiki_id"]
+ end
+
+ if wiki_row
+ # get project from wiki-id
+ results_projects.each do |project|
+ project_row = project if project["id"] == wiki_row["project_id"]
+ end
+ end
+
+ project_identifier = project_row ? project_row["identifier"] + '/' : ""
+
+ title = project_identifier + row_page["title"]
@titles << title
results_contents.each do |row_content|
author = @authors[row_content["author_id"]] ? @authors[row_content["author_id"]] : nil
page = Page.new({:id => row_content["id"],
@@ -34,12 +70,11 @@
end
end
@titles.uniq!
@latest_revisions.each { |rev| rev[1].set_latest }
@revisions.sort! { |a,b| a.time <=> b.time }
-
-
+
# TODO find latest revision for each limit
@revisions
end
@@ -54,7 +89,7 @@
author.email = row["mail"]
@authors[author.id] = author
end
@authors
end
- end
+ end
end
\ No newline at end of file