Commit 05c93013813701736ba53ce2838c44533aad6c7e
Exists in
send_email_to_admins
and in
5 other branches
Merge branch 'use-application-record-pattern' into 'master'
Use ApplicationRecord pattern Anticipating a pattern from Rails 5 See merge request !868
Showing
167 changed files
with
310 additions
and
353 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 167 files displayed.
README.rails.md
... | ... | @@ -99,7 +99,7 @@ Description of contents |
99 | 99 | Holds controllers that should be named like weblog_controller.rb for automated URL mapping. All controllers should descend from `ActionController::Base`. |
100 | 100 | |
101 | 101 | * `app/models` |
102 | - Holds models that should be named like post.rb. Most models will descend from `ActiveRecord::Base`. | |
102 | + Holds models that should be named like post.rb. Most models will descend from `ApplicationRecord`. | |
103 | 103 | |
104 | 104 | * `app/views` |
105 | 105 | Holds the template files for the view that should be named like `weblog/index.rhtml` for the `WeblogController#index` action. All views use eRuby syntax. This directory can also be used to keep stylesheets, images, and so on that can be symlinked to public. | ... | ... |
app/mailers/mailing.rb
app/models/abuse_report.rb
app/models/action_tracker_notification.rb
... | ... | @@ -0,0 +1,64 @@ |
1 | +class ApplicationRecord < ActiveRecord::Base | |
2 | + | |
3 | + self.abstract_class = true | |
4 | + | |
5 | + def self.postgresql? | |
6 | + self.connection.adapter_name == 'PostgreSQL' | |
7 | + end | |
8 | + | |
9 | + # an ActionView instance for rendering views on models | |
10 | + def self.action_view | |
11 | + @action_view ||= begin | |
12 | + view_paths = ::ActionController::Base.view_paths | |
13 | + action_view = ::ActionView::Base.new view_paths | |
14 | + # for using Noosfero helpers inside render calls | |
15 | + action_view.extend ::ApplicationHelper | |
16 | + action_view | |
17 | + end | |
18 | + end | |
19 | + | |
20 | + # default value needed for the above ActionView | |
21 | + def to_partial_path | |
22 | + self.class.name.underscore | |
23 | + end | |
24 | + | |
25 | + alias :meta_cache_key :cache_key | |
26 | + def cache_key | |
27 | + key = [Noosfero::VERSION, meta_cache_key] | |
28 | + key.unshift(ApplicationRecord.connection.schema_search_path) if ApplicationRecord.postgresql? | |
29 | + key.join('/') | |
30 | + end | |
31 | + | |
32 | + def self.like_search(query, options={}) | |
33 | + if defined?(self::SEARCHABLE_FIELDS) || options[:fields].present? | |
34 | + fields_per_table = {} | |
35 | + fields_per_table[table_name] = (options[:fields].present? ? options[:fields] : self::SEARCHABLE_FIELDS.keys.map(&:to_s)) & column_names | |
36 | + | |
37 | + if options[:joins].present? | |
38 | + join_asset = options[:joins].to_s.classify.constantize | |
39 | + if defined?(join_asset::SEARCHABLE_FIELDS) || options[:fields].present? | |
40 | + fields_per_table[join_asset.table_name] = (options[:fields].present? ? options[:fields] : join_asset::SEARCHABLE_FIELDS.keys.map(&:to_s)) & join_asset.column_names | |
41 | + end | |
42 | + end | |
43 | + | |
44 | + query = query.downcase.strip | |
45 | + fields_per_table.delete_if { |table,fields| fields.blank? } | |
46 | + conditions = fields_per_table.map do |table,fields| | |
47 | + fields.map do |field| | |
48 | + "lower(#{table}.#{field}) LIKE '%#{query}%'" | |
49 | + end.join(' OR ') | |
50 | + end.join(' OR ') | |
51 | + | |
52 | + if options[:joins].present? | |
53 | + joins(options[:joins]).where(conditions) | |
54 | + else | |
55 | + where(conditions) | |
56 | + end | |
57 | + | |
58 | + else | |
59 | + raise "No searchable fields defined for #{self.name}" | |
60 | + end | |
61 | + end | |
62 | + | |
63 | +end | |
64 | + | ... | ... |
app/models/article.rb
app/models/article_categorization.rb
app/models/article_follower.rb
app/models/block.rb
app/models/box.rb
app/models/category.rb
app/models/certifier.rb
app/models/chat_message.rb
app/models/comment.rb
app/models/contact_list.rb
app/models/custom_field.rb
app/models/custom_field_value.rb
app/models/domain.rb
app/models/email_template.rb
app/models/environment.rb
1 | 1 | # A Environment is like a website to be hosted in the platform. It may |
2 | 2 | # contain multiple Profile's and can be identified by several different |
3 | 3 | # domains. |
4 | -class Environment < ActiveRecord::Base | |
4 | +class Environment < ApplicationRecord | |
5 | 5 | |
6 | 6 | attr_accessible :name, :is_default, :signup_welcome_text_subject, |
7 | 7 | :signup_welcome_text_body, :terms_of_use, | ... | ... |
app/models/external_feed.rb
app/models/favorite_enterprise_person.rb
app/models/friendship.rb
app/models/image.rb
app/models/input.rb
app/models/license.rb
app/models/mailing_sent.rb
app/models/national_region.rb
app/models/national_region_type.rb
app/models/person.rb
... | ... | @@ -336,7 +336,7 @@ class Person < Profile |
336 | 336 | environment ||= self.environment |
337 | 337 | role_assignments.includes([:role, :resource]).select { |ra| ra.resource == environment }.map{|ra|ra.role.permissions}.any? do |ps| |
338 | 338 | ps.any? do |p| |
339 | - ActiveRecord::Base::PERMISSIONS['Environment'].keys.include?(p) | |
339 | + ApplicationRecord::PERMISSIONS['Environment'].keys.include?(p) | |
340 | 340 | end |
341 | 341 | end |
342 | 342 | end | ... | ... |
app/models/price_detail.rb
app/models/product.rb
app/models/product_qualifier.rb
app/models/production_cost.rb
app/models/profile.rb
1 | 1 | # A Profile is the representation and web-presence of an individual or an |
2 | 2 | # organization. Every Profile is attached to its Environment of origin, |
3 | 3 | # which by default is the one returned by Environment:default. |
4 | -class Profile < ActiveRecord::Base | |
4 | +class Profile < ApplicationRecord | |
5 | 5 | |
6 | 6 | attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, |
7 | 7 | :redirection_after_login, :custom_url_redirection, | ... | ... |
app/models/profile_activity.rb
app/models/profile_categorization.rb
app/models/profile_suggestion.rb
app/models/qualifier.rb
app/models/qualifier_certifier.rb
app/models/reported_image.rb
app/models/scrap.rb
app/models/search_term.rb
1 | -class SearchTerm < ActiveRecord::Base | |
1 | +class SearchTerm < ApplicationRecord | |
2 | 2 | validates_presence_of :term, :context |
3 | 3 | validates_uniqueness_of :term, :scope => [:context_id, :context_type, :asset] |
4 | 4 | |
... | ... | @@ -25,7 +25,7 @@ class SearchTerm < ActiveRecord::Base |
25 | 25 | # Therefore the score is 97. Them we sum every score to get the total score |
26 | 26 | # for a search term. |
27 | 27 | def self.occurrences_scores |
28 | - Hash[*ActiveRecord::Base.connection.execute( | |
28 | + Hash[*ApplicationRecord.connection.execute( | |
29 | 29 | joins(:occurrences). |
30 | 30 | select("search_terms.id, sum(#{SearchTermOccurrence::EXPIRATION_TIME.to_i} - extract(epoch from (now() - search_term_occurrences.created_at))) as value"). |
31 | 31 | where("search_term_occurrences.created_at > ?", DateTime.now - SearchTermOccurrence::EXPIRATION_TIME). | ... | ... |
app/models/search_term_occurrence.rb
app/models/suggestion_connection.rb
app/models/task.rb
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | # This class has a +data+ field of type <tt>text</tt>, where you can store any |
10 | 10 | # type of data (as serialized Ruby objects) you need for your subclass (which |
11 | 11 | # will need to declare <ttserialize</tt> itself). |
12 | -class Task < ActiveRecord::Base | |
12 | +class Task < ApplicationRecord | |
13 | 13 | |
14 | 14 | acts_as_having_settings :field => :data |
15 | 15 | ... | ... |
app/models/thumbnail.rb
app/models/unit.rb
app/models/user.rb
... | ... | @@ -4,7 +4,7 @@ require 'securerandom' |
4 | 4 | |
5 | 5 | # User models the system users, and is generated by the acts_as_authenticated |
6 | 6 | # Rails generator. |
7 | -class User < ActiveRecord::Base | |
7 | +class User < ApplicationRecord | |
8 | 8 | |
9 | 9 | attr_accessible :login, :email, :password, :password_confirmation, :activated_at |
10 | 10 | ... | ... |
app/models/validation_info.rb
app/views/profile_roles/_form.html.erb
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | <% permissions.each do |key| %> |
10 | 10 | <div class="permissions <%= key.downcase %>"> |
11 | 11 | <h4><%= _('%s Permissions:' % key) %></h4> |
12 | - <% ActiveRecord::Base::PERMISSIONS[key].keys.each do |p| %> | |
12 | + <% ApplicationRecord::PERMISSIONS[key].keys.each do |p| %> | |
13 | 13 | <%= check_box_tag("role[permissions][]", p, role.has_permission?(p), { :id => p }) %> |
14 | 14 | <%= content_tag(:label, permission_name(p), { :for => p }) %><br/> |
15 | 15 | <% end %> | ... | ... |
app/views/role/_form.html.erb
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | <% permissions.each do |key| %> |
10 | 10 | <div class="permissions <%= key.downcase %>"> |
11 | 11 | <h4><%= _('%s Permissions:' % key) %></h4> |
12 | - <% ActiveRecord::Base::PERMISSIONS[key].keys.each do |p| %> | |
12 | + <% ApplicationRecord::PERMISSIONS[key].keys.each do |p| %> | |
13 | 13 | <%= check_box_tag("role[permissions][]", p, role.has_permission?(p), { :id => p }) %> |
14 | 14 | <%= content_tag(:label, permission_name(p), { :for => p }) %><br/> |
15 | 15 | <% end %> | ... | ... |
config/initializers/active_record_extensions.rb
db/migrate/033_destroy_organization_and_person_infos.rb
1 | 1 | class DestroyOrganizationAndPersonInfos < ActiveRecord::Migration |
2 | 2 | def self.up |
3 | 3 | Person.find_each do |i| |
4 | - info = ActiveRecord::Base.connection.select_one("select * from person_infos where person_id = #{i.id}") | |
4 | + info = ApplicationRecord.connection.select_one("select * from person_infos where person_id = #{i.id}") | |
5 | 5 | i.name = info["name"] unless info["name"].nil? |
6 | 6 | i.address = info["address"] unless info["address"].nil? |
7 | 7 | [ "photo", "contact_information", "birth_date", "sex", "city", "state", "country" ].each do |field| |
... | ... | @@ -12,7 +12,7 @@ class DestroyOrganizationAndPersonInfos < ActiveRecord::Migration |
12 | 12 | drop_table :person_infos |
13 | 13 | |
14 | 14 | Organization.find_each do |i| |
15 | - info = ActiveRecord::Base.connection.select_one("select * from organization_infos where organization_id = #{i.id}") | |
15 | + info = ApplicationRecord.connection.select_one("select * from organization_infos where organization_id = #{i.id}") | |
16 | 16 | [ "contact_person", "contact_email", "acronym", "foundation_year", "legal_form", "economic_activity", "management_information", "validated" ].each do |field| |
17 | 17 | i.send("#{field}=", info[field]) |
18 | 18 | end | ... | ... |
db/migrate/059_add_birth_date_to_person.rb
db/migrate/069_add_enviroment_id_to_role.rb
1 | -class Role < ActiveRecord::Base; end | |
2 | -class RoleWithEnvironment < ActiveRecord::Base | |
1 | +class Role < ApplicationRecord | |
2 | +class RoleWithEnvironment < ApplicationRecord | |
3 | 3 | self.table_name = 'roles' |
4 | 4 | belongs_to :environment |
5 | 5 | end |
6 | -class RoleAssignment < ActiveRecord::Base | |
6 | +class RoleAssignment < ApplicationRecord | |
7 | 7 | belongs_to :accessor, :polymorphic => true |
8 | 8 | belongs_to :resource, :polymorphic => true |
9 | 9 | end | ... | ... |
db/migrate/074_move_title_to_name_from_blogs.rb
... | ... | @@ -2,7 +2,7 @@ class MoveTitleToNameFromBlogs < ActiveRecord::Migration |
2 | 2 | def self.up |
3 | 3 | select_all("select id, setting from articles where type = 'Blog' and name != 'Blog'").each do |blog| |
4 | 4 | title = YAML.load(blog['setting'])[:title] |
5 | - assignments = ActiveRecord::Base.sanitize_sql_for_assignment(:name => title) | |
5 | + assignments = ApplicationRecord.sanitize_sql_for_assignment(:name => title) | |
6 | 6 | update("update articles set %s where id = %d" % [assignments, blog['id']] ) |
7 | 7 | end |
8 | 8 | end | ... | ... |
db/migrate/20100921121528_add_is_image_to_articles.rb
... | ... | @@ -3,7 +3,7 @@ class AddIsImageToArticles < ActiveRecord::Migration |
3 | 3 | add_column :articles, :is_image, :boolean, :default => false |
4 | 4 | add_column :article_versions, :is_image, :boolean, :default => false |
5 | 5 | |
6 | - execute ActiveRecord::Base.sanitize_sql(["update articles set is_image = ? where articles.content_type like 'image/%'", true]) | |
6 | + execute ApplicationRecord.sanitize_sql(["update articles set is_image = ? where articles.content_type like 'image/%'", true]) | |
7 | 7 | end |
8 | 8 | |
9 | 9 | def self.down | ... | ... |
db/migrate/20101129234429_convert_folders_to_galleries.rb
... | ... | @@ -10,7 +10,7 @@ class ConvertFoldersToGalleries < ActiveRecord::Migration |
10 | 10 | select_all("select id, setting from articles where type = 'Gallery'").each do |folder| |
11 | 11 | settings = YAML.load(folder['setting'] || {}.to_yaml) |
12 | 12 | settings[:view_as] = 'image_gallery' |
13 | - assignments = ActiveRecord::Base.sanitize_sql_for_assignment(:setting => settings.to_yaml) | |
13 | + assignments = ApplicationRecord.sanitize_sql_for_assignment(:setting => settings.to_yaml) | |
14 | 14 | update("update articles set %s, type = 'Folder' where id = %d" % [assignments, folder['id']]) |
15 | 15 | end |
16 | 16 | end | ... | ... |
db/migrate/20101202205446_remove_published_articles.rb
... | ... | @@ -3,7 +3,7 @@ class RemovePublishedArticles < ActiveRecord::Migration |
3 | 3 | select_all("SELECT * from articles WHERE type = 'PublishedArticle'").each do |published| |
4 | 4 | reference = select_one('select * from articles where id = %d' % published['reference_article_id']) |
5 | 5 | if reference |
6 | - execute(ActiveRecord::Base.sanitize_sql(["UPDATE articles SET type = ?, abstract = ?, body = ? WHERE articles.id = ?", reference['type'], reference['abstract'], reference['body'], published['id']])) | |
6 | + execute(ApplicationRecord.sanitize_sql(["UPDATE articles SET type = ?, abstract = ?, body = ? WHERE articles.id = ?", reference['type'], reference['abstract'], reference['body'], published['id']])) | |
7 | 7 | else |
8 | 8 | execute("DELETE from articles where articles.id = #{published['id']}") |
9 | 9 | end | ... | ... |
db/migrate/20101205034144_add_language_and_translation_of_id_to_article.rb
... | ... | @@ -11,7 +11,7 @@ class AddLanguageAndTranslationOfIdToArticle < ActiveRecord::Migration |
11 | 11 | select_all("select id, setting from articles where type = 'Blog'").each do |blog| |
12 | 12 | settings = YAML.load(blog['setting'] || {}.to_yaml) |
13 | 13 | settings[:display_posts_in_current_language] = true |
14 | - assignments = ActiveRecord::Base.sanitize_sql_for_assignment(:setting => settings.to_yaml) | |
14 | + assignments = ApplicationRecord.sanitize_sql_for_assignment(:setting => settings.to_yaml) | |
15 | 15 | update("update articles set %s where id = %d" % [assignments, blog['id']]) |
16 | 16 | end |
17 | 17 | ... | ... |
db/migrate/20110203160153_rename_images_path_on_tracked_actions.rb
... | ... | @@ -15,7 +15,7 @@ class RenameImagesPathOnTrackedActions < ActiveRecord::Migration |
15 | 15 | end |
16 | 16 | params[param_name] = paths |
17 | 17 | |
18 | - execute(ActiveRecord::Base.sanitize_sql(["UPDATE action_tracker SET params = ? WHERE id = ?", params.to_yaml, tracker['id']])) | |
18 | + execute(ApplicationRecord.sanitize_sql(["UPDATE action_tracker SET params = ? WHERE id = ?", params.to_yaml, tracker['id']])) | |
19 | 19 | end |
20 | 20 | end |
21 | 21 | ... | ... |
db/migrate/20110215153624_move_data_serialized_hash_to_setting_field_for_articles.rb
... | ... | @@ -12,9 +12,9 @@ class MoveDataSerializedHashToSettingFieldForArticles < ActiveRecord::Migration |
12 | 12 | end |
13 | 13 | if body.kind_of?(Hash) |
14 | 14 | settings = article.setting.merge(body) |
15 | - body = ActiveRecord::Base.sanitize_sql_for_assignment(:body => settings[:description]) | |
15 | + body = ApplicationRecord.sanitize_sql_for_assignment(:body => settings[:description]) | |
16 | 16 | update("UPDATE articles set %s WHERE id = %d" % [body, article.id]) |
17 | - setting = ActiveRecord::Base.sanitize_sql_for_assignment(:setting => settings.to_yaml) | |
17 | + setting = ApplicationRecord.sanitize_sql_for_assignment(:setting => settings.to_yaml) | |
18 | 18 | update("UPDATE articles set %s WHERE id = %d" % [setting, article.id]) |
19 | 19 | end |
20 | 20 | end | ... | ... |
db/migrate/20110302214607_move_data_serialized_hash_to_setting_field_for_events.rb
... | ... | @@ -11,9 +11,9 @@ class MoveDataSerializedHashToSettingFieldForEvents < ActiveRecord::Migration |
11 | 11 | end |
12 | 12 | if body.kind_of?(Hash) |
13 | 13 | settings = article.setting.merge(body) |
14 | - body = ActiveRecord::Base.sanitize_sql_for_assignment(:body => settings[:description]) | |
14 | + body = ApplicationRecord.sanitize_sql_for_assignment(:body => settings[:description]) | |
15 | 15 | update("UPDATE articles set %s WHERE id = %d" % [body, article.id]) |
16 | - setting = ActiveRecord::Base.sanitize_sql_for_assignment(:setting => settings.to_yaml) | |
16 | + setting = ApplicationRecord.sanitize_sql_for_assignment(:setting => settings.to_yaml) | |
17 | 17 | update("UPDATE articles set %s WHERE id = %d" % [setting, article.id]) |
18 | 18 | end |
19 | 19 | end | ... | ... |
db/migrate/20110706171330_fix_misunderstood_script_filename.rb
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | # from the migration fall on a loop and breaks the migration. Both them are |
3 | 3 | # related to alias_method_chain, probably there is a problem with this kind of |
4 | 4 | # alias on the migration level. |
5 | -class Article < ActiveRecord::Base | |
5 | +class Article < ApplicationRecord | |
6 | 6 | def sanitize_tag_list |
7 | 7 | end |
8 | 8 | end | ... | ... |
db/migrate/20110824192153_add_activated_at_to_users.rb
... | ... | @@ -2,7 +2,7 @@ class AddActivatedAtToUsers < ActiveRecord::Migration |
2 | 2 | def self.up |
3 | 3 | add_column :users, :activation_code, :string, :limit => 40 |
4 | 4 | add_column :users, :activated_at, :datetime |
5 | - if ActiveRecord::Base.connection.adapter_name == 'SQLite' | |
5 | + if ApplicationRecord.connection.adapter_name == 'SQLite' | |
6 | 6 | execute "update users set activated_at = datetime();" |
7 | 7 | else |
8 | 8 | execute "update users set activated_at = now();" | ... | ... |
db/migrate/20140724134601_fix_yaml_encoding.rb
db/migrate/20150216213259_create_profile_activity.rb
lib/activities_counter_cache_job.rb
1 | 1 | class ActivitiesCounterCacheJob |
2 | 2 | |
3 | 3 | def perform |
4 | - person_activities_counts = ActiveRecord::Base.connection.execute("SELECT profiles.id, count(action_tracker.id) as count FROM profiles LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.user_id WHERE (action_tracker.created_at >= #{ActiveRecord::Base.connection.quote(ActionTracker::Record::RECENT_DELAY.days.ago.to_s(:db))}) AND ( (profiles.type = 'Person' ) ) GROUP BY profiles.id;") | |
5 | - organization_activities_counts = ActiveRecord::Base.connection.execute("SELECT profiles.id, count(action_tracker.id) as count FROM profiles LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.target_id WHERE (action_tracker.created_at >= #{ActiveRecord::Base.connection.quote(ActionTracker::Record::RECENT_DELAY.days.ago.to_s(:db))}) AND ( (profiles.type = 'Community' OR profiles.type = 'Enterprise' OR profiles.type = 'Organization' ) ) GROUP BY profiles.id;") | |
4 | + person_activities_counts = ApplicationRecord.connection.execute("SELECT profiles.id, count(action_tracker.id) as count FROM profiles LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.user_id WHERE (action_tracker.created_at >= #{ApplicationRecord.connection.quote(ActionTracker::Record::RECENT_DELAY.days.ago.to_s(:db))}) AND ( (profiles.type = 'Person' ) ) GROUP BY profiles.id;") | |
5 | + organization_activities_counts = ApplicationRecord.connection.execute("SELECT profiles.id, count(action_tracker.id) as count FROM profiles LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.target_id WHERE (action_tracker.created_at >= #{ApplicationRecord.connection.quote(ActionTracker::Record::RECENT_DELAY.days.ago.to_s(:db))}) AND ( (profiles.type = 'Community' OR profiles.type = 'Enterprise' OR profiles.type = 'Organization' ) ) GROUP BY profiles.id;") | |
6 | 6 | activities_counts = person_activities_counts.entries + organization_activities_counts.entries |
7 | 7 | activities_counts.each do |count| |
8 | - update_sql = ActiveRecord::Base.__send__(:sanitize_sql, ["UPDATE profiles SET activities_count=? WHERE profiles.id=?;", count['count'].to_i, count['id'] ], '') | |
9 | - ActiveRecord::Base.connection.execute(update_sql) | |
8 | + update_sql = ApplicationRecord.__send__(:sanitize_sql, ["UPDATE profiles SET activities_count=? WHERE profiles.id=?;", count['count'].to_i, count['id'] ], '') | |
9 | + ApplicationRecord.connection.execute(update_sql) | |
10 | 10 | end |
11 | 11 | Delayed::Job.enqueue(ActivitiesCounterCacheJob.new, {:priority => -3, :run_at => 1.day.from_now}) |
12 | 12 | end | ... | ... |
lib/acts_as_customizable.rb
lib/acts_as_filesystem.rb
... | ... | @@ -33,7 +33,7 @@ module ActsAsFileSystem |
33 | 33 | module ClassMethods |
34 | 34 | |
35 | 35 | def build_ancestry(parent_id = nil, ancestry = '') |
36 | - ActiveRecord::Base.transaction do | |
36 | + ApplicationRecord.transaction do | |
37 | 37 | self.base_class.where(parent_id: parent_id).each do |node| |
38 | 38 | node.update_column :ancestry, ancestry |
39 | 39 | |
... | ... | @@ -263,5 +263,5 @@ module ActsAsFileSystem |
263 | 263 | end |
264 | 264 | end |
265 | 265 | |
266 | -ActiveRecord::Base.extend ActsAsFileSystem::ActsMethods | |
266 | +ApplicationRecord.extend ActsAsFileSystem::ActsMethods | |
267 | 267 | ... | ... |
lib/acts_as_having_boxes.rb
lib/acts_as_having_image.rb
lib/acts_as_having_posts.rb
lib/acts_as_having_settings.rb
lib/code_numbering.rb
lib/delayed_attachment_fu.rb
lib/noosfero/core_ext.rb
lib/noosfero/core_ext/active_record.rb
... | ... | @@ -1,74 +0,0 @@ |
1 | -require 'active_record' | |
2 | - | |
3 | -class ActiveRecord::Base | |
4 | - | |
5 | - def self.postgresql? | |
6 | - ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' | |
7 | - end | |
8 | - | |
9 | - # an ActionView instance for rendering views on models | |
10 | - def self.action_view | |
11 | - @action_view ||= begin | |
12 | - view_paths = ::ActionController::Base.view_paths | |
13 | - action_view = ::ActionView::Base.new view_paths | |
14 | - # for using Noosfero helpers inside render calls | |
15 | - action_view.extend ::ApplicationHelper | |
16 | - action_view | |
17 | - end | |
18 | - end | |
19 | - | |
20 | - # default value needed for the above ActionView | |
21 | - def to_partial_path | |
22 | - self.class.name.underscore | |
23 | - end | |
24 | - | |
25 | - alias :meta_cache_key :cache_key | |
26 | - def cache_key | |
27 | - key = [Noosfero::VERSION, meta_cache_key] | |
28 | - key.unshift(ActiveRecord::Base.connection.schema_search_path) if ActiveRecord::Base.postgresql? | |
29 | - key.join('/') | |
30 | - end | |
31 | - | |
32 | - def self.like_search(query, options={}) | |
33 | - if defined?(self::SEARCHABLE_FIELDS) || options[:fields].present? | |
34 | - fields_per_table = {} | |
35 | - fields_per_table[table_name] = (options[:fields].present? ? options[:fields] : self::SEARCHABLE_FIELDS.keys.map(&:to_s)) & column_names | |
36 | - | |
37 | - if options[:joins].present? | |
38 | - join_asset = options[:joins].to_s.classify.constantize | |
39 | - if defined?(join_asset::SEARCHABLE_FIELDS) || options[:fields].present? | |
40 | - fields_per_table[join_asset.table_name] = (options[:fields].present? ? options[:fields] : join_asset::SEARCHABLE_FIELDS.keys.map(&:to_s)) & join_asset.column_names | |
41 | - end | |
42 | - end | |
43 | - | |
44 | - query = query.downcase.strip | |
45 | - fields_per_table.delete_if { |table,fields| fields.blank? } | |
46 | - conditions = fields_per_table.map do |table,fields| | |
47 | - fields.map do |field| | |
48 | - "lower(#{table}.#{field}) LIKE '%#{query}%'" | |
49 | - end.join(' OR ') | |
50 | - end.join(' OR ') | |
51 | - | |
52 | - if options[:joins].present? | |
53 | - joins(options[:joins]).where(conditions) | |
54 | - else | |
55 | - where(conditions) | |
56 | - end | |
57 | - | |
58 | - else | |
59 | - raise "No searchable fields defined for #{self.name}" | |
60 | - end | |
61 | - end | |
62 | - | |
63 | -end | |
64 | - | |
65 | -ActiveRecord::Calculations.class_eval do | |
66 | - def count_with_distinct column_name=self.primary_key | |
67 | - if column_name | |
68 | - distinct.count_without_distinct column_name | |
69 | - else | |
70 | - count_without_distinct | |
71 | - end | |
72 | - end | |
73 | - alias_method_chain :count, :distinct | |
74 | -end |
... | ... | @@ -0,0 +1,10 @@ |
1 | +ActiveRecord::Calculations.class_eval do | |
2 | + def count_with_distinct column_name=self.primary_key | |
3 | + if column_name | |
4 | + distinct.count_without_distinct column_name | |
5 | + else | |
6 | + count_without_distinct | |
7 | + end | |
8 | + end | |
9 | + alias_method_chain :count, :distinct | |
10 | +end | ... | ... |
lib/noosfero/multi_tenancy.rb
... | ... | @@ -12,12 +12,12 @@ module Noosfero |
12 | 12 | def self.db_by_host=(host) |
13 | 13 | if host != @db_by_host |
14 | 14 | @db_by_host = host |
15 | - ActiveRecord::Base.connection.schema_search_path = self.mapping[host] | |
15 | + ApplicationRecord.connection.schema_search_path = self.mapping[host] | |
16 | 16 | end |
17 | 17 | end |
18 | 18 | |
19 | 19 | def self.setup!(host) |
20 | - if Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql? | |
20 | + if Noosfero::MultiTenancy.on? and ApplicationRecord.postgresql? | |
21 | 21 | Noosfero::MultiTenancy.db_by_host = host |
22 | 22 | end |
23 | 23 | end | ... | ... |
lib/noosfero/unicorn.rb
... | ... | @@ -7,11 +7,11 @@ GC.respond_to?(:copy_on_write_friendly=) and |
7 | 7 | GC.copy_on_write_friendly = true |
8 | 8 | |
9 | 9 | before_fork do |server, worker| |
10 | - ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base) | |
10 | + ApplicationRecord.connection.disconnect! if defined?(ApplicationRecord) | |
11 | 11 | end |
12 | 12 | |
13 | 13 | after_fork do |server, worker| |
14 | - ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base) | |
14 | + ApplicationRecord.establish_connection if defined?(ApplicationRecord) | |
15 | 15 | end |
16 | 16 | |
17 | 17 | # load local configuration file, if it exists | ... | ... |
lib/postgresql_attachment_fu.rb
... | ... | @@ -9,11 +9,12 @@ module PostgresqlAttachmentFu |
9 | 9 | module InstanceMethods |
10 | 10 | def full_filename(thumbnail = nil) |
11 | 11 | file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s |
12 | - file_system_path = File.join(file_system_path, ActiveRecord::Base.connection.schema_search_path) if ActiveRecord::Base.postgresql? and Noosfero::MultiTenancy.on? | |
12 | + file_system_path = File.join(file_system_path, ApplicationRecord.connection.schema_search_path) if ApplicationRecord.postgresql? and Noosfero::MultiTenancy.on? | |
13 | 13 | Rails.root.join(file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))).to_s |
14 | 14 | end |
15 | 15 | end |
16 | 16 | |
17 | 17 | end |
18 | 18 | |
19 | -ActiveRecord::Base.send(:extend, PostgresqlAttachmentFu::ClassMethods) | |
19 | +ApplicationRecord.extend PostgresqlAttachmentFu::ClassMethods | |
20 | + | ... | ... |
lib/split_datetime.rb
lib/sqlite_extension.rb
1 | -if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite' | |
1 | +if ApplicationRecord.connection.adapter_name.downcase == 'sqlite' | |
2 | 2 | |
3 | - database = ActiveRecord::Base.connection.raw_connection | |
3 | + database = ApplicationRecord.connection.raw_connection | |
4 | 4 | |
5 | 5 | database.create_function('pow', 2, 1) do |func, base, exponent| |
6 | 6 | func.set_result(base.to_f ** exponent.to_f) |
7 | 7 | end |
8 | - | |
8 | + | |
9 | 9 | database.create_function('sqrt', 1, 1) do |func, value| |
10 | 10 | func.set_result(Math.sqrt(value)) |
11 | 11 | end |
... | ... | @@ -18,8 +18,8 @@ if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite' |
18 | 18 | func.set_result( |
19 | 19 | radius.to_f * Math.acos( |
20 | 20 | [1, |
21 | - Math.cos(lat1.to_f) * Math.cos(long1.to_f) * Math.cos(lat2.to_f) * Math.cos(long2.to_f) + | |
22 | - Math.cos(lat1.to_f) * Math.sin(long1.to_f) * Math.cos(lat2.to_f) * Math.sin(long2.to_f) + | |
21 | + Math.cos(lat1.to_f) * Math.cos(long1.to_f) * Math.cos(lat2.to_f) * Math.cos(long2.to_f) + | |
22 | + Math.cos(lat1.to_f) * Math.sin(long1.to_f) * Math.cos(lat2.to_f) * Math.sin(long2.to_f) + | |
23 | 23 | Math.sin(lat1.to_f) * Math.sin(lat2.to_f) |
24 | 24 | ].min |
25 | 25 | ) | ... | ... |
lib/tasks/backup.rake
... | ... | @@ -115,7 +115,7 @@ end |
115 | 115 | |
116 | 116 | desc 'Removes emails from database' |
117 | 117 | task 'restore:remove_emails' => :environment do |
118 | - connection = ActiveRecord::Base.connection | |
118 | + connection = ApplicationRecord.connection | |
119 | 119 | [ |
120 | 120 | "UPDATE users SET email = concat('user', id, '@localhost.localdomain')", |
121 | 121 | "UPDATE environments SET contact_email = concat('environment', id, '@localhost.localdomain')", | ... | ... |
lib/tasks/multitenancy.rake
1 | 1 | namespace :multitenancy do |
2 | 2 | |
3 | 3 | task :create => :environment do |
4 | - db_envs = ActiveRecord::Base.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) } | |
4 | + db_envs = ApplicationRecord.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) } | |
5 | 5 | cd Rails.root.join('config', 'environments'), :verbose => true |
6 | 6 | file_envs = Dir.glob "{*_development.rb,*_production.rb,*_test.rb}" |
7 | 7 | (db_envs.map{ |e| e + '.rb' } - file_envs).each { |env| ln_s env.split('_').last, env } |
8 | 8 | end |
9 | 9 | |
10 | 10 | task :remove => :environment do |
11 | - db_envs = ActiveRecord::Base.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) } | |
11 | + db_envs = ApplicationRecord.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) } | |
12 | 12 | cd Rails.root.join('config', 'environments'), :verbose => true |
13 | 13 | file_envs = Dir.glob "{*_development.rb,*_production.rb,*_test.rb}" |
14 | 14 | (file_envs - db_envs.map{ |e| e + '.rb' }).each { |env| safe_unlink env } |
... | ... | @@ -19,7 +19,7 @@ end |
19 | 19 | namespace :db do |
20 | 20 | |
21 | 21 | task :migrate_other_environments => :environment do |
22 | - envs = ActiveRecord::Base.configurations.keys.select{ |k| k.match(/_#{Rails.env}$/) } | |
22 | + envs = ApplicationRecord.configurations.keys.select{ |k| k.match(/_#{Rails.env}$/) } | |
23 | 23 | envs.each do |e| |
24 | 24 | puts "*** Migrating #{e}" if Rake.application.options.trace |
25 | 25 | system "rake db:migrate RAILS_ENV=#{e} SCHEMA=/dev/null" | ... | ... |
lib/upload_sanitizer.rb
plugins/analytics/models/analytics_plugin/page_view.rb
plugins/analytics/models/analytics_plugin/visit.rb
plugins/comment_classification/lib/comment_classification_plugin/comment_label_user.rb
plugins/comment_classification/lib/comment_classification_plugin/comment_status_user.rb
plugins/comment_classification/lib/comment_classification_plugin/label.rb
plugins/comment_classification/lib/comment_classification_plugin/status.rb
plugins/custom_forms/db/migrate/20130823151900_associate_fields_to_alternatives.rb
1 | 1 | class AssociateFieldsToAlternatives < ActiveRecord::Migration |
2 | - class CustomFormsPlugin::Field < ActiveRecord::Base | |
2 | + class CustomFormsPlugin::Field < ApplicationRecord | |
3 | 3 | self.table_name = :custom_forms_plugin_fields |
4 | 4 | has_many :alternatives, :class_name => 'CustomFormsPlugin::Alternative' |
5 | 5 | serialize :choices, Hash | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/alternative.rb
plugins/custom_forms/lib/custom_forms_plugin/answer.rb
1 | -class CustomFormsPlugin::Answer < ActiveRecord::Base | |
1 | +class CustomFormsPlugin::Answer < ApplicationRecord | |
2 | 2 | self.table_name = :custom_forms_plugin_answers |
3 | 3 | belongs_to :field, :class_name => 'CustomFormsPlugin::Field' |
4 | 4 | belongs_to :submission, :class_name => 'CustomFormsPlugin::Submission' | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/field.rb
plugins/custom_forms/lib/custom_forms_plugin/form.rb
plugins/custom_forms/lib/custom_forms_plugin/submission.rb