fnp
/
redakcja.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of stigma.nowoczesnapolska.org.pl:platforma
[redakcja.git]
/
redmine
/
redmine_publications
/
lib
/
redmine_publications
/
issue_patch.rb
diff --git
a/redmine/redmine_publications/lib/redmine_publications/issue_patch.rb
b/redmine/redmine_publications/lib/redmine_publications/issue_patch.rb
index
f8a83c4
..
bd1f73e
100644
(file)
--- a/
redmine/redmine_publications/lib/redmine_publications/issue_patch.rb
+++ b/
redmine/redmine_publications/lib/redmine_publications/issue_patch.rb
@@
-11,14
+11,8
@@
module RedminePublications
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
- validate :check_relations
+
validate :check_relations
after_save :update_relations
after_save :update_relations
-
- # Add visible to Redmine 0.8.x
- unless respond_to?(:visible)
- named_scope :visible, lambda {|*args| { :include => :project,
- :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
- end
end
end
end
end
@@
-29,55
+23,55
@@
module RedminePublications
module InstanceMethods
def publication_names
module InstanceMethods
def publication_names
- if not @pubnames
- self.publications.map { |pub| pub.name }
+
if not @pubnames
+
self.publications.map { |pub| pub.name }
else
else
- @pubnames
- end
+ @pubnames
+
end
end
def publication_names=(value)
end
def publication_names=(value)
- @pubnames = value.sort!
+
@pubnames = value.sort!
end
def publications
Publication.all(
end
def publications
Publication.all(
- :joins =>
- "JOIN issue_publications ON (issue_publications.publication_id = publications.id)",
- :conditions =>
- ["issue_publications.issue_id = ? ", self.id] )
+ :joins =>
+
"JOIN issue_publications ON (issue_publications.publication_id = publications.id)",
+
:conditions =>
+ ["issue_publications.issue_id = ? ", self.id] )
end
def check_relations
end
def check_relations
- current_names = self.publication_names
- non_existant = []
+
current_names = self.publication_names
+
non_existant = []
- pubs = Publication.find_all_by_name(current_names).map {|i| i.name}
- missing = current_names.select {|name| not pubs.include?name }
+
pubs = Publication.find_all_by_name(current_names).map {|i| i.name}
+
missing = current_names.select {|name| not pubs.include?name }
- if not missing.empty?
- errors.add("publications", "Missing publication(s): " + missing.join(', '))
- end
- end
+
if not missing.empty?
+
errors.add("publications", "Missing publication(s): " + missing.join(', '))
+
end
+
end
- def update_relations
- self.reload
-
old = self.publication
s
- current_names = self.publication_names
+
def update_relations
+ old = self.publications
+
current_names = self.publication_name
s
+ Rails.logger.info('[INFO] Updating relations: old= ' << old.inspect << ' current=' << current_names.inspect)
- # delete unused relations
- deleted = old.select { |v| not (current_names.include?(v.name)) }
- deleted.each do |pub|
- IssuePublication.delete_all(["issue_publications.issue_id = ? AND issue_publications.publication_id = ?", self.id, pub.id])
- end
+
# delete unused relations
+
deleted = old.select { |v| not (current_names.include?(v.name)) }
+ deleted.each do |pub|
+
IssuePublication.delete_all(["issue_publications.issue_id = ? AND issue_publications.publication_id = ?", self.id, pub.id])
+
end
- current_names.each do |name|
-
pub = Publication.find_by_name(name)
-
IssuePublication.find_or_create_by_publication_id_and_issue_id(pub.id, self.id)
- end
+ current_names.each do |name|
+ pub = Publication.find_by_name(name)
+ IssuePublication.find_or_create_by_publication_id_and_issue_id(pub.id, self.id)
+
end
return true
return true
- end
+
end
end
end
end
end