| Class | Wiki |
| In: |
app/models/wiki.rb
|
| Parent: | Site |
| DEFAULT_CSS | = | 'css/default.css' | HTML Editors remove the nowrap attribute, so we add it to the CSS-file, see Wiki.enhance_files |
| contributors | [RW] | Used only for Notifier.report TODO a better solution |
# File app/models/wiki.rb, line 42
42: def status
43: logger.debug("Determining status of wiki #{self.title}")
44: s = 'Ready'
45: if self.updates.count == 0
46: logger.debug("Wiki #{self.title} does not have any update records")
47: s = 'Pending'
48: elsif self.updates_todo.count > 0
49: logger.debug("Wiki #{self.title} has #{self.updates_todo.count.to_s} updates to do")
50: s = 'Scheduled'
51: self.updates_todo.each do |u|
52: logger.debug("Update todo #{u.baseline_process.title} is started on #{u.started_on}")
53: s = 'UpdateInProgress' if !u.started_on.nil?
54: end
55: end
56: return s
57: end
# File app/models/wiki.rb, line 59
59: def top_contributors
60: arr = User.find(:all).collect {|u|[u, Version.count(:conditions => ['user_id = ? and baseline_process_id is null and wiki_id=?',u.id, self.id]) +
61: Comment.count(:conditions => ['user_id = ? and site_id=?',u.id, self.id]) +
62: Upload.count(:conditions => ['user_id = ?',u.id])]}
63: arr = arr.sort_by{|t|-t[1]}
64: end
# File app/models/wiki.rb, line 66
66: def top_monthly_contributors
67: arr = User.find(:all).collect {|u|[u, Version.count(:conditions => ['user_id = ? and baseline_process_id is null and wiki_id=?',u.id, self.id]) +
68: Comment.count(:conditions => ['user_id = ? and site_id=?',u.id, self.id]) +
69: Upload.count(:conditions => ['user_id = ?',u.id])]}
70: arr = arr.sort_by{|t|-t[1]}
71: end
Method update_wiki updates a Wiki with a BaselineProcess with the following steps:
TODO: notify users that want to be notified (add about notify_baseline_updates column to users) TODO: Change 68 - Update should continue with checkouts and should not overwrite not harvested changes
# File app/models/wiki.rb, line 115
115: def update_wiki(update)
116: update.update_attributes(:started_on => Time.now)
117: bp = update.baseline_process
118: logger.info("Starting update of wiki #{self.title} from baseline process #{self.baseline_process.title} (#{self.baseline_process.id}) to #{bp.title} (#{bp.id})")
119: logger.info("Copy update site " + bp.path + " to " + self.path)
120: cadmin = User.find_central_admin
121: # 1.
122: bp.copy_to(self, nil)
123:
124: # 2. Update status of EPFC pages to 'undetermined'
125: Page.update_all( "status = 'Undetermined'", ["tool = ? and site_id = ? ", 'EPFC', self.id, ])
126:
127: # 3. Update
128: bp.scan4content if bp.content_scanned_on.nil?
129: bp.pages.each do |p|
130: page = Page.find_by_site_id_and_rel_path(self.id, p.rel_path)
131: if page
132: page.status = 'Updated'
133: no = page.max_version_no + 1
134: else
135: page = WikiPage.new(:rel_path => p.rel_path, :site => self, :tool => 'EPFC', :status => 'New', :site_id => self.id)
136: no = 0
137: end
138: # create baseversion
139: baseversion = BaselineProcessVersion.new(:baseline_update => update,:user => cadmin, :page => page,
140: :wiki => self, :version => no, :done => 'Y', :note => 'Automatically created',
141: :baseline_process_id => bp.id)
142: page.baseline_process_versions << baseversion
143: page.save!
144: end
145:
146: # 4.
147: Page.find(:all, :conditions => ['site_id = ? and status = ?', self.id, 'Undetermined']).each do |p|
148: p.status = 'RemovedOrMoved'
149: p.save!
150: end
151:
152: # 5.
153: Page.find(:all, :conditions => ['site_id = ? and tool = ?', self.id, 'Wiki']).each do |p|
154: if p.harvested?
155: p.status = 'Harvested'
156: end
157: end
158:
159: # 6.
160: enhance_files
161:
162: # Change 68 - current versions not harvested
163: versions = UserVersion.find(:all, :conditions => ['wiki_id =? and done <> ? and version is not null', self.id, 'Y'])
164: logger.info("Found #{versions.size.to_s} versions with unharvested changes")
165: pages = versions.collect{|version| version.page}.uniq
166: if pages
167: logger.info("Found #{pages.size.to_s} pages with unharvested changes") if pages
168: snippets = Page.get_snippets
169: pages.each do |page|
170: logger.info("Processing page #{page.presentation_name}")
171: if page.checkout
172: logger.info("Page has unharvested versions, we don't need to set a current version")
173: else
174: cv = page.current_version
175: unless cv.nil?
176: if cv.current
177: logger.info("Page #{page.presentation_name} already has current version with id #{cv.id}, we don't need to set a current version")
178: else
179: logger.info("Page #{page.presentation_name} does not have a current version")
180: # set the current version equal to the last version that is not part of the update we are doing
181: page.current_version = Version.find(:first, :order => 'version DESC', :conditions => ['page_id=? and version is not null and update_id is null',page.id])
182: end
183: page.html = page.current_version.html
184: Page.enhance_file(page.path, snippets)
185: end
186: end
187: end
188: end
189: self.baseline_updated_on = Time.now
190: self.baseline_process = bp
191: self.save!
192: end
# File app/models/wiki.rb, line 194
194: def url(absolute = false, request_host = ENV['EPFWIKI_HOST'])
195: #--
196: # TODO anomaly, the following line shouldn't be necessary but is, in some cases.
197: # When this method is called from page.url request_host will be nil
198: #++
199: request_host = ENV['EPFWIKI_HOST'] if request_host.nil?
200:
201: logger.debug("url for site #{self.title}, absolute #{absolute.inspect}, request_host #{request_host.inspect}")
202: s = "/#{ENV['EPFWIKI_WIKIS_FOLDER']}/#{self.folder}/index.htm"
203: s = "http://#{request_host}#{s}" if absolute
204: logger.debug("returning: #{s}")
205: s
206: end
# File app/models/wiki.rb, line 218
218: def users
219: return User.find(:all, :conditions => ['exists (select * from versions vsn where vsn.wiki_id = ? and vsn.user_id = users.id and baseline_process_id is null) or exists (select * from da_texts cmt where cmt.user_id = users.id and cmt.site_id = ?) or exists (select * from uploads where uploads.user_id = ?)', id, id, id])
220: end
# File app/models/wiki.rb, line 208
208: def validate_on_create
209: logger.info("Folder #{ENV['EPFWIKI_WIKIS_PATH']}/#{self.folder} should not exists already")
210: errors.add(:folder, 'already exists') if (!self.folder.blank? && File.exists?("#{ENV['EPFWIKI_WIKIS_PATH']}/#{self.folder}")) || !Wiki.find_by_folder(self.folder).nil?
211: if self.title == 'Templates'
212: if Wiki.find(:first, :conditions => ['title = ?','Templates'])
213: errors.add(:title, ' "Templates" has been used. There can only be one Wiki with that name.')
214: end
215: end
216: end
Method wikify does the actual wikifying of the content. It is the second step of the two step process (the first step created the Wiki record and Update record).
NOTE: This method is typically not called directly but called via Update.wikify
# File app/models/wiki.rb, line 80
80: def wikify(update)
81: bp = update.baseline_process
82: logger.info("Updating Wiki #{self.title} with baseline process #{bp.title}")
83: raise 'The site was updated already or has a an update in progress!' if !update.first_update?
84: raise "Can only update with a baseline process (static site)" if bp.wiki?
85: update.update_attributes(:started_on => Time.now) # changes the wiki status to 'UpdateInProgress'
86: File.makedirs(self.path)
87: logger.info("Copying files from #{bp.path} to #{self.path}")
88: FileUtils.cp_r(bp.path + "/.", self.path) # How to copy the contents of a folder and not the folder [http://www.ruby-doc.org/core/classes/FileUtils.html#M001703]
89: bp.scan4content if !bp.content_scanned_on
90: cadmin = User.find_central_admin
91: bp.pages.each do |p|
92: newp = WikiPage.new(:rel_path => p.rel_path, :site => self, :tool => 'EPFC', :status => 'New', :site_id => self.id)
93: # create baseversion
94: baseversion = BaselineProcessVersion.new(:baseline_update => update, :user => cadmin, :page => newp,
95: :wiki => self, :version => 0, :done => 'Y', :note => 'Automatically created',
96: :baseline_process_id => bp.id)
97: newp.baseline_process_versions << baseversion
98: newp.save!
99: end
100: enhance_files
101: self.baseline_process = bp
102: self.wikified_on = Time.now
103: self.save!
104: end