diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 33bc0d975..09b5b81ac 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -25,7 +25,7 @@ class StatusMessagesController < ApplicationController @status_message.photos << photos end if @status_message.save - Rails.logger.info("event=create type=status_message chars=#{params[:status_message][:message].length}") + Rails.logger.info("event=create type=status_message chars=#{params[:status_message][:text].length}") current_user.add_to_streams(@status_message, aspects) receiving_services = params[:services].map{|s| current_user.services.where( diff --git a/app/models/mongo.rb b/app/models/mongo.rb deleted file mode 100644 index 704a37532..000000000 --- a/app/models/mongo.rb +++ /dev/null @@ -1,21 +0,0 @@ -module Mongo - def self.table_name_prefix - "mongo_" - end - - class Aspect < ActiveRecord::Base; end - class AspectMembership < ActiveRecord::Base; end - class Comment < ActiveRecord::Base; end - class Contact < ActiveRecord::Base; end - class Invitation < ActiveRecord::Base; end - class Notification < ActiveRecord::Base; end - class Person < ActiveRecord::Base; end - #Photo? - class Post < ActiveRecord::Base; end - class PostVisibility < ActiveRecord::Base; end - class Profile < ActiveRecord::Base; end - class Request < ActiveRecord::Base; end - class Service < ActiveRecord::Base; end - #StatusMessage? - class User < ActiveRecord::Base; end -end diff --git a/app/models/photo.rb b/app/models/photo.rb index 2c541d76a..1a60bcca1 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -9,12 +9,12 @@ class Photo < Post xml_attr :remote_photo_path xml_attr :remote_photo_name - xml_attr :caption + xml_attr :text xml_attr :status_message_guid belongs_to :status_message - attr_accessible :caption, :pending + attr_accessible :text, :pending validate :ownership_of_status_message before_destroy :ensure_user_picture @@ -101,7 +101,7 @@ class Photo < Post :id => self.id, :url => self.url(:thumb_medium), :thumb_small => self.url(:thumb_small), - :caption => self.caption + :text => self.text } } end diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 9768257dd..cbefe0849 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -10,18 +10,18 @@ class StatusMessage < Post acts_as_taggable_on :tags - validates_length_of :message, :maximum => 1000, :message => "please make your status messages less than 1000 characters" + validates_length_of :message, :maximum => 1000, :text => "please make your status messages less than 1000 characters" xml_name :status_message xml_attr :raw_message has_many :photos, :dependent => :destroy validate :message_or_photos_present? - attr_accessible :message + attr_accessible :text serialize :youtube_titles, Hash before_save do - get_youtube_title message + get_youtube_title text end before_create :build_tags @@ -31,10 +31,10 @@ class StatusMessage < Post end def raw_message - read_attribute(:message) + read_attribute(:text) end def raw_message=(text) - write_attribute(:message, text) + write_attribute(:text, text) end def formatted_message(opts={}) @@ -136,7 +136,7 @@ class StatusMessage < Post protected def message_or_photos_present? - if self.message.blank? && self.photos == [] + if self.text.blank? && self.photos == [] errors[:base] << 'Status message requires a message or at least one photo' end end diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml index 9d8b8ed18..4322718ec 100644 --- a/app/views/photos/_photo.haml +++ b/app/views/photos/_photo.haml @@ -8,7 +8,7 @@ = post.pending %p.photo_description - = post.caption + = post.text = link_to t('.view_all', :name => post.author.name), person_photos_path(post.author), :class => "small_text" diff --git a/app/views/photos/edit.html.haml b/app/views/photos/edit.html.haml index dd8ed7d6b..0128d72ad 100644 --- a/app/views/photos/edit.html.haml +++ b/app/views/photos/edit.html.haml @@ -9,7 +9,7 @@ = image_tag @photo.url(:scaled_full) = form_for @photo do |photo| - = photo.label :caption - = photo.text_field :caption, :value => @photo.caption + = photo.label :text + = photo.text_field :text, :value => @photo.text = photo.submit diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index b2075e701..439d9f258 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -25,7 +25,7 @@ = image_tag @photo.url(:scaled_full) #caption - = @photo.caption + = @photo.text - if @ownership .photo_options{:data=>{:actor=>"#{@photo.author.owner.id}", :actor_person => "#{@photo.author.id}", :image_url => "#{@photo.url(:thumb_large)}"}} @@ -56,7 +56,7 @@ %h4= t('.edit_delete_photo') %p = form_for @photo, :remote => true do |p| - = p.text_field :caption, :value => @photo.caption + = p.text_field :text, :value => @photo.text = p.submit t('.update_photo') %p = button_to t('.delete_photo'), @photo, :confirm => t('are_you_sure'), :method => :delete diff --git a/app/views/posts/photo.html.haml b/app/views/posts/photo.html.haml index 1384b80b4..06b0ff44f 100644 --- a/app/views/posts/photo.html.haml +++ b/app/views/posts/photo.html.haml @@ -15,7 +15,7 @@ = image_tag @post.url(:scaled_full) #caption - = @post.caption + = @post.text %br diff --git a/app/views/shared/_publisher.html.haml b/app/views/shared/_publisher.html.haml index 08d48efb3..b2c93bb9b 100644 --- a/app/views/shared/_publisher.html.haml +++ b/app/views/shared/_publisher.html.haml @@ -27,8 +27,8 @@ %params #publisher_textarea_wrapper %ul#photodropzone - = status.text_area :fake_message, :rows => 2, :value => h(params[:prefill]) - = status.hidden_field :message, :value => '', :class => 'clear_on_submit' + = status.text_area :fake_text, :rows => 2, :value => h(params[:prefill]) + = status.hidden_field :text, :value => '', :class => 'clear_on_submit' - for aspect_id in @aspect_ids = hidden_field_tag 'aspect_ids[]', aspect_id.to_s diff --git a/config/application.rb b/config/application.rb index fc51514cf..16c16a120 100644 --- a/config/application.rb +++ b/config/application.rb @@ -51,7 +51,6 @@ module Diaspora config.filter_parameters += [:xml] config.filter_parameters += [:message] config.filter_parameters += [:text] - config.filter_parameters += [:caption] config.filter_parameters += [:bio] end diff --git a/db/migrate/20110313015438_rename_text_fields.rb b/db/migrate/20110313015438_rename_text_fields.rb new file mode 100644 index 000000000..d667ca5ac --- /dev/null +++ b/db/migrate/20110313015438_rename_text_fields.rb @@ -0,0 +1,12 @@ +class RenameTextFields < ActiveRecord::Migration + def self.up + rename_column :posts, :message, :text + execute("UPDATE posts + SET posts.text = posts.caption + WHERE posts.caption IS NOT NULL;") + remove_column :posts, :caption + end + + def self.down + end +end diff --git a/db/migrate/20110314043119_drop_import_tables.rb b/db/migrate/20110314043119_drop_import_tables.rb new file mode 100644 index 000000000..e4d9e2de2 --- /dev/null +++ b/db/migrate/20110314043119_drop_import_tables.rb @@ -0,0 +1,10 @@ +require 'db/migrate/20110105051803_create_import_tables' +class DropImportTables < ActiveRecord::Migration + def self.up + CreateImportTables.down + end + + def self.down + CreateImportTables.up + end +end diff --git a/db/schema.rb b/db/schema.rb index 1b6d6195d..775bb8c47 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110311220249) do +ActiveRecord::Schema.define(:version => 20110314043119) do create_table "aspect_memberships", :force => true do |t| t.integer "aspect_id", :null => false @@ -127,66 +127,6 @@ ActiveRecord::Schema.define(:version => 20110311220249) do add_index "messages", ["author_id"], :name => "index_messages_on_author_id" - create_table "mongo_aspect_memberships", :force => true do |t| - t.string "aspect_mongo_id" - t.string "contact_mongo_id" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "mongo_aspect_memberships", ["aspect_mongo_id"], :name => "index_mongo_aspect_memberships_on_aspect_mongo_id" - add_index "mongo_aspect_memberships", ["contact_mongo_id"], :name => "index_mongo_aspect_memberships_on_contact_mongo_id" - - create_table "mongo_aspects", :force => true do |t| - t.string "mongo_id" - t.string "name" - t.string "user_mongo_id" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "mongo_aspects", ["user_mongo_id"], :name => "index_mongo_aspects_on_user_mongo_id" - - create_table "mongo_comments", :force => true do |t| - t.text "text" - t.string "mongo_id" - t.string "post_mongo_id" - t.string "person_mongo_id" - t.string "guid" - t.text "creator_signature" - t.text "post_creator_signature" - t.text "youtube_titles" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "mongo_comments", ["guid"], :name => "index_mongo_comments_on_guid", :unique => true - add_index "mongo_comments", ["post_mongo_id"], :name => "index_mongo_comments_on_post_mongo_id" - - create_table "mongo_contacts", :force => true do |t| - t.string "mongo_id" - t.string "user_mongo_id" - t.string "person_mongo_id" - t.boolean "pending", :default => true - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "mongo_contacts", ["person_mongo_id", "pending"], :name => "index_mongo_contacts_on_person_mongo_id_and_pending" - add_index "mongo_contacts", ["user_mongo_id", "pending"], :name => "index_mongo_contacts_on_user_mongo_id_and_pending" - - create_table "mongo_invitations", :force => true do |t| - t.string "mongo_id" - t.text "message" - t.string "sender_mongo_id" - t.string "recipient_mongo_id" - t.string "aspect_mongo_id" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "mongo_invitations", ["sender_mongo_id"], :name => "index_mongo_invitations_on_sender_mongo_id" - create_table "mongo_notifications", :force => true do |t| t.string "mongo_id" t.string "target_type", :limit => 127 @@ -201,131 +141,6 @@ ActiveRecord::Schema.define(:version => 20110311220249) do add_index "mongo_notifications", ["target_type", "target_mongo_id"], :name => "index_mongo_notifications_on_target_type_and_target_mongo_id" - create_table "mongo_people", :force => true do |t| - t.string "mongo_id" - t.string "guid" - t.text "url" - t.string "diaspora_handle" - t.text "serialized_public_key" - t.string "owner_mongo_id" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "mongo_people", ["diaspora_handle"], :name => "index_mongo_people_on_diaspora_handle", :unique => true - add_index "mongo_people", ["guid"], :name => "index_mongo_people_on_guid", :unique => true - add_index "mongo_people", ["owner_mongo_id"], :name => "index_mongo_people_on_owner_mongo_id", :unique => true - - create_table "mongo_post_visibilities", :force => true do |t| - t.string "aspect_mongo_id" - t.string "post_mongo_id" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "mongo_post_visibilities", ["aspect_mongo_id"], :name => "index_mongo_post_visibilities_on_aspect_mongo_id" - add_index "mongo_post_visibilities", ["post_mongo_id"], :name => "index_mongo_post_visibilities_on_post_mongo_id" - - create_table "mongo_posts", :force => true do |t| - t.string "person_mongo_id" - t.boolean "public", :default => false - t.string "diaspora_handle" - t.string "guid" - t.string "mongo_id" - t.boolean "pending", :default => false - t.string "type" - t.text "message" - t.string "status_message_mongo_id" - t.text "caption" - t.text "remote_photo_path" - t.string "remote_photo_name" - t.string "random_string" - t.string "image" - t.text "youtube_titles" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "mongo_posts", ["guid"], :name => "index_mongo_posts_on_guid" - add_index "mongo_posts", ["person_mongo_id"], :name => "index_mongo_posts_on_person_mongo_id" - add_index "mongo_posts", ["type"], :name => "index_mongo_posts_on_type" - - create_table "mongo_profiles", :force => true do |t| - t.string "diaspora_handle" - t.string "first_name", :limit => 127 - t.string "last_name", :limit => 127 - t.string "image_url" - t.string "image_url_small" - t.string "image_url_medium" - t.date "birthday" - t.string "gender" - t.text "bio" - t.boolean "searchable", :default => true - t.string "person_mongo_id" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "mongo_profiles", ["first_name", "last_name", "searchable"], :name => "index_mongo_profiles_on_first_name_and_last_name_and_searchable" - add_index "mongo_profiles", ["first_name", "searchable"], :name => "index_mongo_profiles_on_first_name_and_searchable" - add_index "mongo_profiles", ["last_name", "searchable"], :name => "index_mongo_profiles_on_last_name_and_searchable" - add_index "mongo_profiles", ["person_mongo_id"], :name => "index_mongo_profiles_on_person_mongo_id", :unique => true - - create_table "mongo_requests", :force => true do |t| - t.string "mongo_id" - t.string "sender_mongo_id", :limit => 127 - t.string "recipient_mongo_id", :limit => 127 - t.string "aspect_mongo_id" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "mongo_requests", ["recipient_mongo_id"], :name => "index_mongo_requests_on_recipient_mongo_id" - add_index "mongo_requests", ["sender_mongo_id", "recipient_mongo_id"], :name => "index_mongo_requests_on_sender_mongo_id_and_recipient_mongo_id", :unique => true - add_index "mongo_requests", ["sender_mongo_id"], :name => "index_mongo_requests_on_sender_mongo_id" - - create_table "mongo_services", :force => true do |t| - t.string "mongo_id" - t.string "type" - t.string "user_mongo_id" - t.string "provider" - t.string "uid" - t.string "access_token" - t.string "access_secret" - t.string "nickname" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "mongo_services", ["user_mongo_id"], :name => "index_mongo_services_on_user_mongo_id" - - create_table "mongo_users", :force => true do |t| - t.string "username" - t.text "serialized_private_key" - t.integer "invites" - t.boolean "getting_started" - t.boolean "disable_mail" - t.string "language" - t.string "email", :default => "", :null => false - t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false - t.string "invitation_token", :limit => 20 - t.datetime "invitation_sent_at" - t.string "reset_password_token" - t.string "remember_token" - t.datetime "remember_created_at" - t.integer "sign_in_count", :default => 0 - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.datetime "created_at" - t.datetime "updated_at" - t.string "mongo_id" - end - - add_index "mongo_users", ["mongo_id"], :name => "index_mongo_users_on_mongo_id", :unique => true - create_table "notification_actors", :force => true do |t| t.integer "notification_id" t.integer "person_id" @@ -385,9 +200,8 @@ ActiveRecord::Schema.define(:version => 20110311220249) do t.string "guid", :null => false t.boolean "pending", :default => false, :null => false t.string "type", :null => false - t.text "message" + t.text "text" t.integer "status_message_id" - t.text "caption" t.text "remote_photo_path" t.string "remote_photo_name" t.string "random_string" diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 7c92b9797..192dcafeb 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -117,7 +117,7 @@ end Given /^a user with email "([^\"]*)" has posted a status message "([^\"]*)" in all aspects$/ do |arg1, arg2| user = User.where(:email => arg1).first - status_message = user.build_post(:status_message, :message => arg2) + status_message = user.build_post(:status_message, :text => arg2) def status_message.socket_to_user(a1, a2); end user.add_to_streams(status_message, user.aspects) status_message.save! diff --git a/lib/data_conversion/base.rb b/lib/data_conversion/base.rb deleted file mode 100644 index da00eb803..000000000 --- a/lib/data_conversion/base.rb +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -module DataConversion - class Base - attr_accessor :start_time, :directory, :full_path - - def initialize(start_time = Time.now) - @start_time = start_time - @directory = "tmp/export-for-mysql" - @full_path = "#{Rails.root}/#{directory}" - end - def models - @models ||= [ - {:name => :aspects, - :main_attrs => ["mongo_id", "name", "user_mongo_id", "created_at", "updated_at"], - :mongo_attrs => ["_id" , "name", "user_id" , "created_at", "updated_at"], - :join_table_name => :post_visibilities, - :join_table_attrs => ["aspect_mongo_id", "post_mongo_id"]}, - {:name => :comments, - :attrs => ["mongo_id", "post_mongo_id", "person_mongo_id", "diaspora_handle", "text", "youtube_titles", "created_at", "updated_at"], - :mongo_attrs => ["_id", "post_id", "person_id", "diaspora_handle", "text", "youtube_titles", "created_at", "updated_at"]}, - {:name => :contacts, - :main_attrs => ["mongo_id", "user_mongo_id", "person_mongo_id", "pending", "created_at", "updated_at"], - :main_mongo_attrs => ["_id" , "user_id" , "person_id" , "pending", "created_at", "updated_at"], - :join_table_name => :aspect_memberships, - :join_table_attrs => ["contact_mongo_id", "aspect_mongo_id"]}, - {:name => :invitations, - :attrs => ["mongo_id", "recipient_mongo_id", "sender_mongo_id", "aspect_mongo_id", "message", "created_at", "updated_at"], - :mongo_attrs => ["_id" , "to_id" , "from_id" , "into_id" , "message", "created_at", "updated_at"]}, - {:name => :notifications, - :attrs => ["mongo_id", "target_mongo_id", "recipient_mongo_id", "actor_mongo_id", "action", "target_type", "unread", "created_at", "updated_at"], - :mongo_attrs => ["_id" , "target_id" , "user_id" , "person_id" , "action", "kind" , "unread", "created_at", "updated_at"]}, - {:name => :people, - :attrs => ["created_at", "updated_at", "serialized_public_key", "url", "mongo_id", "owner_mongo_id", "diaspora_handle"], - :profile_attrs => ["image_url_medium", "searchable", "image_url", "person_mongo_id", "gender", "diaspora_handle", "birthday", "last_name", "bio", "image_url_small", "first_name"]}, - {:name => :posts, - :attrs => ["youtube_titles", "pending", "created_at", "public", "updated_at", "status_message_mongo_id", "caption", "remote_photo_path", "remote_photo_name", "random_string", "image" , "mongo_id", "type", "diaspora_handle", "person_mongo_id", "message"], - :mongo_attrs => ["youtube_titles", "pending", "created_at", "public", "updated_at", "status_message_id" , "caption", "remote_photo_path", "remote_photo_name", "random_string", "image_filename", "_id" , "_type", "diaspora_handle", "person_id" , "message"]}, - {:name => :requests, - :attrs => ["mongo_id", "recipient_mongo_id", "sender_mongo_id", "aspect_mongo_id", "created_at", "updated_at"], - :mongo_attrs => ["_id" , "to_id" , "from_id" , "into_id" , "created_at", "updated_at"]}, - {:name => :services, - :attrs => ["mongo_id", "type", "user_mongo_id", "provider", "uid", "access_token", "access_secret", "nickname", "created_at", "updated_at"], - :mongo_attrs => ["_id" , "_type", "user_id", "provider", "uid", "access_token", "access_secret", "nickname", "created_at", "updated_at"]}, - {:name => :users, - :attrs => ["mongo_id","email", "username", "serialized_private_key", "encrypted_password", "invites", "invitation_token", "invitation_sent_at", "getting_started", "disable_mail", "language", "last_sign_in_ip", "last_sign_in_at", "reset_password_token", "password_salt", "created_at", "updated_at"], - :mongo_attrs => ["_id" , "email","username", "serialized_private_key", "encrypted_password", "invites", "invitation_token", "invitation_sent_at", "getting_started", "disable_mail", "language", "last_sign_in_ip", "last_sign_in_at", "reset_password_token", "password_salt", "created_at", "updated_at"]}, - ] - end - def log(message) - if ['development', 'production'].include?(Rails.env) - puts "#{sprintf("%.2f", Time.now - start_time)}s #{message}" - end - Rails.logger.debug(message) if Rails.logger - end - end -end diff --git a/lib/data_conversion/export_from_mongo.rb b/lib/data_conversion/export_from_mongo.rb deleted file mode 100644 index 973e22720..000000000 --- a/lib/data_conversion/export_from_mongo.rb +++ /dev/null @@ -1,227 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require 'json' -require 'csv' -require File.join(Rails.root, 'lib/data_conversion/base') - -module DataConversion - class ExportFromMongo < DataConversion::Base - def csv_options - {:col_sep => ",", - :row_sep => :auto, - :quote_char => '"', - :field_size_limit => nil, - :converters => nil, - :unconverted_fields => nil, - :headers => false, - :return_headers => false, - :header_converters => nil, - :skip_blanks => false, - :force_quotes => false} - end - - def clear_dir - ["#{full_path}/json", "#{full_path}/csv"].each do |path| - FileUtils.rm_rf(path) - FileUtils.mkdir_p(path) - end - end - - def db_name - "diaspora-#{Rails.env}" - end - - - - def id_sed - @id_sed = sed_replace('{\ \"$oid\"\ :\ \(\"[^"]*\"\)\ }') - end - - def date_sed - @date_sed = sed_replace('{\ \"$date\"\ :\ \([0-9]*\)\ }') - end - - def sed_replace(regex) - "sed 's/#{regex}/\\1/g'" - end - - def json_for_model model_name - "mongoexport -d #{db_name} -c #{model_name} | #{id_sed} | #{date_sed}" - end - - def write_json_export - log "Starting JSON export..." - models.each do |model| - log "Starting #{model[:name]} JSON export..." - filename ="#{full_path}/json/#{model[:name]}.json" - model[:json_file] = filename - `#{json_for_model(model[:name])} > #{filename}` - log "Completed #{model[:name]} JSON export to #{directory}/json/#{model[:name]}.json." - end - log "JSON export complete." - end - - def convert_json_files - models.each do |model| - self.send("#{model[:name]}_json_to_csv".to_sym, model) - end - end - - def generic_json_to_csv model_hash - log "Converting #{model_hash[:name]} json to csv" - json_file = File.open(model_hash[:json_file]) - - csv = CSV.open("#{full_path}/csv/#{model_hash[:name]}.csv", 'w') - csv << model_hash[:attrs] - - json_file.each do |aspect_json| - hash = JSON.parse(aspect_json) - csv << yield(hash) - end - json_file.close - csv.close - end - - def comments_json_to_csv model_hash - generic_json_to_csv(model_hash) do |hash| - model_hash[:mongo_attrs].map { |attr_name| - attr_val = hash[attr_name] - if (attr_name == "youtube_titles" && attr_val && !attr_val.empty?) - attr_val.to_yaml - else - attr_val - end - } - end - end - - def contacts_json_to_csv model_hash - generic_json_to_two_csvs(model_hash) do |hash| - main_row = model_hash[:main_mongo_attrs].map { |attr_name| hash[attr_name] } - if hash["aspect_ids"] - aspect_membership_rows = hash["aspect_ids"].map { |id| [hash["_id"], id] } - else - aspect_membership_rows = [] - end - [main_row, aspect_membership_rows] - end - #Also writes the aspect memberships csv - end - - def invitations_json_to_csv model_hash - generic_json_to_csv(model_hash) do |hash| - model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] } - end - end - - def notifications_json_to_csv model_hash - generic_json_to_csv(model_hash) do |hash| - model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] } - end - end - def services_json_to_csv model_hash - generic_json_to_csv(model_hash) do |hash| - model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] } - end - end - def people_json_to_csv model_hash - #Also writes the profiles csv - - log "Converting #{model_hash[:name]} json to csv" - json_file = File.open(model_hash[:json_file]) - - people_csv = CSV.open("#{full_path}/csv/#{model_hash[:name]}.csv", 'w') - people_csv << model_hash[:attrs] - - profiles_csv = CSV.open("#{full_path}/csv/profiles.csv", 'w') - profiles_csv << model_hash[:profile_attrs] - - json_file.each do |aspect_json| - hash = JSON.parse(aspect_json) - person_row = model_hash[:attrs].map do |attr_name| - attr_name = attr_name.gsub("mongo_", "") - attr_name = "_id" if attr_name == "id" - hash[attr_name] - end - people_csv << person_row - - profile_row = model_hash[:profile_attrs].map do |attr_name| - if attr_name == "person_mongo_id" - hash["_id"] #set person_mongo_id to the person id - else - hash["profile"][attr_name] - end - end - profiles_csv << profile_row - end - json_file.close - people_csv.close - profiles_csv.close - end - - def posts_json_to_csv model_hash - generic_json_to_csv(model_hash) do |hash| - model_hash[:mongo_attrs].map { |attr_name| - attr_val = hash[attr_name] - if (attr_name == "youtube_titles" && attr_val && !attr_val.empty?) - attr_val.to_yaml - else - attr_val - end - } - end - #has to handle the polymorphic stuff - end - - def requests_json_to_csv model_hash - generic_json_to_csv(model_hash) do |hash| - model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] } - end - end - - def users_json_to_csv model_hash - generic_json_to_csv(model_hash) do |hash| - model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] } - end - end - - def aspects_json_to_csv model_hash - log "Converting aspects json to aspects and post_visibilities csvs" - - generic_json_to_two_csvs(model_hash) do |hash| - main_row = model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] } - - if hash["post_ids"] - post_visibility_rows = hash["post_ids"].map { |id| [hash["_id"], id] } - else - post_visibility_rows = [] - end - - [main_row, post_visibility_rows] - end - end - - def generic_json_to_two_csvs model_hash - log "Converting #{model_hash[:name]} json to two csvs" - json_file = File.open(model_hash[:json_file]) - - main_csv = CSV.open("#{full_path}/csv/#{model_hash[:name]}.csv", 'w') - main_csv << model_hash[:main_attrs] - - join_csv = CSV.open("#{full_path}/csv/#{model_hash[:join_table_name]}.csv", 'w') - join_csv << model_hash[:join_table_attrs] unless model_hash[:join_table_attrs].empty? - - json_file.each do |aspect_json| - hash = JSON.parse(aspect_json) - result = yield(hash) - main_csv << result.first - result.last.each { |row| join_csv << row } - end - json_file.close - main_csv.close - join_csv.close - end - end -end diff --git a/lib/data_conversion/import_to_mysql.rb b/lib/data_conversion/import_to_mysql.rb deleted file mode 100644 index 9aee99ef5..000000000 --- a/lib/data_conversion/import_to_mysql.rb +++ /dev/null @@ -1,551 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require File.join(Rails.root, 'lib/data_conversion/base') -module DataConversion - class ImportToMysql < DataConversion::Base - - def import_raw - truncate_tables - - import_raw_users - import_raw_aspects - import_raw_aspect_memberships - import_raw_comments - import_raw_invitations - import_raw_notifications - import_raw_people - import_raw_profiles - import_raw_posts - import_raw_contacts - import_raw_post_visibilities - import_raw_requests - import_raw_services - end - - def process_raw_tables - process_raw_users - process_raw_aspects - process_raw_services - process_raw_people - process_raw_contacts - process_raw_aspect_memberships - process_raw_invitations - process_raw_requests - process_raw_profiles - process_raw_posts - process_raw_comments - process_raw_post_visibilities - process_raw_notifications - end - - def truncate_tables - Mongo::User.connection.execute "TRUNCATE TABLE mongo_users" - Mongo::Aspect.connection.execute "TRUNCATE TABLE mongo_aspects" - Mongo::AspectMembership.connection.execute "TRUNCATE TABLE mongo_aspect_memberships" - Mongo::Comment.connection.execute "TRUNCATE TABLE mongo_comments" - Mongo::Invitation.connection.execute "TRUNCATE TABLE mongo_invitations" - Mongo::Notification.connection.execute "TRUNCATE TABLE mongo_notifications" - Mongo::Person.connection.execute "TRUNCATE TABLE mongo_people" - Mongo::Profile.connection.execute "TRUNCATE TABLE mongo_profiles" - Mongo::Post.connection.execute "TRUNCATE TABLE mongo_posts" - Mongo::Contact.connection.execute "TRUNCATE TABLE mongo_contacts" - Mongo::PostVisibility.connection.execute "TRUNCATE TABLE mongo_post_visibilities" - Mongo::Request.connection.execute "TRUNCATE TABLE mongo_requests" - Mongo::Service.connection.execute "TRUNCATE TABLE mongo_services" - end - - def process_raw_users - log "Importing users to main table..." - User.connection.execute <<-SQL - INSERT INTO users (username, serialized_private_key, invites, getting_started, disable_mail, - language, email, encrypted_password, password_salt, invitation_token, - invitation_sent_at, reset_password_token, remember_token, remember_created_at, - sign_in_count, current_sign_in_at, last_sign_in_at, current_sign_in_ip, - last_sign_in_ip, created_at, updated_at, mongo_id, invitation_service, - invitation_identifier) - SELECT username, serialized_private_key, invites, getting_started, disable_mail, - language, email, encrypted_password, password_salt, invitation_token, - invitation_sent_at, reset_password_token, remember_token, remember_created_at, - sign_in_count, current_sign_in_at, last_sign_in_at, current_sign_in_ip, - last_sign_in_ip, created_at, updated_at, mongo_id, 'email', - email - FROM mongo_users - SQL - User.connection.execute <<-SQL - UPDATE users - SET users.invitation_service = NULL, users.invitation_identifier = NULL - WHERE users.invitation_token IS NULL AND users.mongo_id IS NOT NULL - SQL - log "Imported #{User.count} users." - end - - def process_raw_posts - log "Importing posts to main table..." - Post.connection.execute <<-SQL - INSERT INTO posts - SELECT mongo_posts.id, - people.id, - mongo_posts.public, - mongo_posts.diaspora_handle, - mongo_posts.guid, - mongo_posts.pending, - mongo_posts.type, - mongo_posts.message, - NULL, - mongo_posts.caption, - mongo_posts.remote_photo_path, - mongo_posts.remote_photo_name, - mongo_posts.random_string, - mongo_posts.image, - mongo_posts.youtube_titles, - mongo_posts.created_at, - mongo_posts.updated_at, - mongo_posts.mongo_id - FROM mongo_posts - INNER JOIN people ON (people.mongo_id = mongo_posts.person_mongo_id) - SQL - log "Imported #{Post.count} posts." - - log "Setting Photo -> StatusMessage relation column..." - Photo.connection.execute <<-SQL - UPDATE posts AS photos, mongo_posts, posts AS statuses - SET photos.status_message_id = statuses.id - WHERE photos.type = "Photo" AND mongo_posts.mongo_id = photos.mongo_id AND statuses.mongo_id = mongo_posts.status_message_mongo_id - SQL - log "Processed #{Photo.count} photos." - end - - def process_raw_aspects - log "Importing aspects to main table..." - Aspect.connection.execute <<-SQL - INSERT INTO aspects - SELECT mongo_aspects.id, - mongo_aspects.name, - users.id, - mongo_aspects.created_at, - mongo_aspects.updated_at, - mongo_aspects.mongo_id, - mongo_aspects.user_mongo_id, - false, - false - FROM mongo_aspects - INNER JOIN users ON (users.mongo_id = mongo_aspects.user_mongo_id) - SQL - log "Imported #{Aspect.count} aspects." - end - def process_raw_contacts - log "Importing contacts to main table..." - Contact.connection.execute <<-SQL - INSERT INTO contacts - SELECT mongo_contacts.id, - users.id, - people.id, - mongo_contacts.pending, - mongo_contacts.created_at, - mongo_contacts.updated_at, - mongo_contacts.mongo_id - FROM mongo_contacts - INNER JOIN (users, people) ON (users.mongo_id = mongo_contacts.user_mongo_id - AND people.mongo_id = mongo_contacts.person_mongo_id) - SQL - log "Imported #{Contact.count} contacts." - end - def process_raw_profiles - log "Importing profiles to main table..." - Profile.connection.execute <<-SQL - INSERT INTO profiles - SELECT mongo_profiles.id, - mongo_profiles.diaspora_handle, - mongo_profiles.first_name, - mongo_profiles.last_name, - mongo_profiles.image_url, - mongo_profiles.image_url_small, - mongo_profiles.image_url_medium, - mongo_profiles.birthday, - mongo_profiles.gender, - mongo_profiles.bio, - mongo_profiles.searchable, - people.id, - mongo_profiles.created_at, - mongo_profiles.updated_at, - mongo_profiles.person_mongo_id - FROM mongo_profiles - INNER JOIN (people) ON (people.mongo_id = mongo_profiles.person_mongo_id) - SQL - log "Imported #{Profile.count} profiles." - end - def process_raw_aspect_memberships - log "Importing aspect_memberships to main table..." - AspectMembership.connection.execute <<-SQL - INSERT INTO aspect_memberships - SELECT mongo_aspect_memberships.id, - aspects.id, - contacts.id, - mongo_aspect_memberships.created_at, - mongo_aspect_memberships.updated_at - FROM mongo_aspect_memberships INNER JOIN (aspects, contacts) - ON (aspects.mongo_id = mongo_aspect_memberships.aspect_mongo_id AND contacts.mongo_id = mongo_aspect_memberships.contact_mongo_id) - SQL - log "Imported #{AspectMembership.count} aspect_memberships." - end - def process_raw_invitations - log "Importing invitations to main table..." - Invitation.connection.execute <<-SQL - INSERT INTO invitations - SELECT m_inv.id, - m_inv.message, - senders.id, - recipients.id, - aspects.id, - m_inv.created_at, - m_inv.updated_at, - m_inv.mongo_id - FROM mongo_invitations AS m_inv - INNER JOIN users AS senders ON m_inv.sender_mongo_id = senders.mongo_id - INNER JOIN users AS recipients ON m_inv.recipient_mongo_id = recipients.mongo_id - INNER JOIN aspects ON m_inv.aspect_mongo_id = aspects.mongo_id - SQL - log "Imported #{Invitation.count} invitations." - end - def process_raw_requests - log "Importing requests to main table..." - Request.connection.execute <<-SQL - INSERT INTO requests - SELECT m_r.id, - senders.id, - recipients.id, - aspects.id, - m_r.created_at, - m_r.updated_at, - m_r.mongo_id - FROM mongo_requests AS m_r - INNER JOIN people AS senders ON m_r.sender_mongo_id = senders.mongo_id - INNER JOIN people AS recipients ON m_r.recipient_mongo_id = recipients.mongo_id - LEFT JOIN aspects ON m_r.aspect_mongo_id = aspects.mongo_id - SQL - log "Imported #{Request.count} requests." - end - def process_raw_services - log "Importing services to main table..." - Service.connection.execute <<-SQL - INSERT INTO services - SELECT mongo_services.id, - mongo_services.type, - users.id, - mongo_services.uid, - mongo_services.access_token, - mongo_services.access_secret, - mongo_services.nickname, - mongo_services.created_at, - mongo_services.updated_at, - mongo_services.mongo_id, - mongo_services.user_mongo_id - FROM mongo_services INNER JOIN users ON (users.mongo_id = mongo_services.user_mongo_id) - SQL - log "Imported #{Service.count} services." - end - def process_raw_comments - log "Importing comments to main table..." - Comment.connection.execute <<-SQL - INSERT INTO comments - SELECT mongo_comments.id, - mongo_comments.text, - posts.id, - people.id, - mongo_comments.guid, - mongo_comments.creator_signature, - mongo_comments.post_creator_signature, - mongo_comments.youtube_titles, - mongo_comments.created_at, - mongo_comments.updated_at, - mongo_comments.mongo_id - FROM mongo_comments INNER JOIN (posts, people) - ON (posts.mongo_id = mongo_comments.post_mongo_id AND people.mongo_id = mongo_comments.person_mongo_id) - SQL - log "Imported #{Comment.count} comments." - end - def process_raw_people - log "Importing people to main table..." - Person.connection.execute <<-SQL - INSERT INTO people - SELECT mongo_people.id, - mongo_people.guid, - mongo_people.url, - mongo_people.diaspora_handle, - mongo_people.serialized_public_key, - users.id, - mongo_people.created_at, - mongo_people.updated_at, - mongo_people.mongo_id - FROM mongo_people LEFT JOIN users ON (users.mongo_id = mongo_people.owner_mongo_id) - SQL - log "Imported #{Person.count} people." - end - def process_raw_post_visibilities - log "Importing post_visibilities to main table..." - PostVisibility.connection.execute <<-SQL - INSERT INTO post_visibilities - SELECT mongo_post_visibilities.id, - aspects.id, - posts.id, - mongo_post_visibilities.created_at, - mongo_post_visibilities.updated_at - FROM mongo_post_visibilities INNER JOIN (aspects, posts) - ON (aspects.mongo_id = mongo_post_visibilities.aspect_mongo_id AND posts.mongo_id = mongo_post_visibilities.post_mongo_id) - SQL - log "Imported #{PostVisibility.count} post_visibilities." - end - - def process_raw_notifications - log "Not importing notifications." - end - - def import_raw_users - log "Loading users file..." - Mongo::User.connection.execute set_time_zone_to_utc - Mongo::User.connection.execute <<-SQL - #{load_string("users")} - #{infile_opts} - (mongo_id, email, @username, serialized_private_key, encrypted_password, - invites, @invitation_token, @invitation_sent_at, @getting_started, - @disable_mail, language, @last_sign_in_ip, @last_sign_in_at, - @reset_password_token, password_salt) - SET #{unix_time("last_sign_in_at")}, - #{nil_es("invitation_token")}, - #{nil_es("username")}, - #{nil_es("last_sign_in_ip")}, - #{nil_es("reset_password_token")}, - #{unix_time("created_at")}, - #{unix_time("updated_at")}, - #{boolean_set("getting_started")}, - #{boolean_set("disable_mail")}; - SQL - log "Finished. Imported #{Mongo::User.count} users." - end - - - def import_raw_aspects - log "Loading aspects file..." - Mongo::Aspect.connection.execute set_time_zone_to_utc - Mongo::Aspect.connection.execute <<-SQL - #{load_string("aspects")} - #{infile_opts} - (mongo_id, name, user_mongo_id, @created_at, @updated_at) - SET #{unix_time("created_at")}, - #{unix_time("updated_at")}; - SQL - log "Finished. Imported #{Mongo::Aspect.count} aspects." - end - - def import_raw_aspect_memberships - log "Loading aspect memberships file..." - Mongo::AspectMembership.connection.execute set_time_zone_to_utc - Mongo::AspectMembership.connection.execute <<-SQL - #{load_string("aspect_memberships")} - #{infile_opts} - (contact_mongo_id, aspect_mongo_id) - SQL - log "Finished. Imported #{Mongo::AspectMembership.count} aspect memberships." - end - - def import_raw_comments - log "Loading comments file..." - Mongo::Comment.connection.execute set_time_zone_to_utc - Mongo::Comment.connection.execute <<-SQL - #{load_string("comments")} - #{infile_opts} - (mongo_id, post_mongo_id, person_mongo_id, @diaspora_handle, text, @youtube_titles, @created_at, @updated_at) - SET guid = mongo_id, - #{unix_time("created_at")}, - #{unix_time("updated_at")}, - #{nil_es("youtube_titles")}; - SQL - log "Finished. Imported #{Mongo::Comment.count} comments." - end - - def import_raw_posts - log "Loading posts file..." - Mongo::Post.connection.execute set_time_zone_to_utc - Mongo::Post.connection.execute <<-SQL - #{load_string("posts")} - #{infile_opts} - (@youtube_titles, @pending, @created_at, @public, @updated_at, @status_message_mongo_id, @caption, - @remote_photo_path, @remote_photo_name, @random_string, @image, mongo_id, type, diaspora_handle, person_mongo_id, @message) - SET guid = mongo_id, - #{nil_es("youtube_titles")}, - #{nil_es("status_message_mongo_id")}, - #{nil_es("caption")}, - #{nil_es("remote_photo_path")}, - #{nil_es("remote_photo_name")}, - #{nil_es("random_string")}, - #{nil_es("image")}, - #{nil_es("message")}, - #{unix_time("created_at")}, - #{unix_time("updated_at")}, - #{boolean_set("pending")}, - #{boolean_set("public")}; - SQL - log "Finished. Imported #{Mongo::Post.count} posts." - end - - def import_raw_contacts - log "Loading contacts file..." - Mongo::Contact.connection.execute set_time_zone_to_utc - Mongo::Contact.connection.execute <<-SQL - #{load_string("contacts")} - #{infile_opts} - (mongo_id, user_mongo_id, person_mongo_id, @pending, @created_at, @updated_at) - SET #{boolean_set("pending")}, - #{unix_time("created_at")}, - #{unix_time("updated_at")}; - SQL - log "Finished. Imported #{Mongo::Contact.count} contacts." - end - - def import_raw_services - log "Loading services file..." - Mongo::Service.connection.execute set_time_zone_to_utc - Mongo::Service.connection.execute <<-SQL - #{load_string("services")} - #{infile_opts} - (mongo_id, type,user_mongo_id,@provider,@uid,@access_token,@access_secret,@nickname, @created_at, @updated_at) - SET #{nil_es("provider")}, - #{nil_es("uid")}, - #{unix_time("created_at")}, - #{unix_time("updated_at")}, - #{nil_es("access_token")}, - #{nil_es("access_secret")}, - #{nil_es("nickname")}; - SQL - log "Finished. Imported #{Mongo::Service.count} services." - end - - def import_raw_post_visibilities - log "Loading post visibilities file..." - Mongo::PostVisibility.connection.execute set_time_zone_to_utc - Mongo::PostVisibility.connection.execute <<-SQL - #{load_string("post_visibilities")} - #{infile_opts} - (aspect_mongo_id, post_mongo_id) - SQL - log "Finished. Imported #{Mongo::PostVisibility.count} post visibilities." - end - - def import_raw_requests - log "Loading requests file..." - Mongo::Request.connection.execute set_time_zone_to_utc - Mongo::Request.connection.execute <<-SQL - #{load_string("requests")} - #{infile_opts} - (mongo_id, recipient_mongo_id, sender_mongo_id, @aspect_mongo_id, @created_at, @updated_at) - SET #{nil_es("aspect_mongo_id")}, - #{unix_time("created_at")}, - #{unix_time("updated_at")}; - SQL - log "Finished. Imported #{Mongo::Request.count} requests." - end - - def import_raw_invitations - log "Loading invitations file..." - Mongo::Invitation.connection.execute set_time_zone_to_utc - Mongo::Invitation.connection.execute <<-SQL - #{load_string("invitations")} - #{infile_opts} - (mongo_id, recipient_mongo_id, sender_mongo_id, aspect_mongo_id, message, @created_at, @updated_at) - SET #{unix_time("created_at")}, - #{unix_time("updated_at")}; - SQL - log "Finished. Imported #{Mongo::Invitation.count} invitations." - end - - def import_raw_notifications - log "Loading notifications file..." - Mongo::Notification.connection.execute set_time_zone_to_utc - Mongo::Notification.connection.execute <<-SQL - #{load_string("notifications")} - #{infile_opts} - (mongo_id,target_mongo_id,recipient_mongo_id,actor_mongo_id,@null_action,action,@unread, @created_at, @updated_at) - SET #{boolean_set("unread")}, - #{unix_time("created_at")}, - #{unix_time("updated_at")}; - SQL - log "Finished. Imported #{Mongo::Notification.count} notifications." - {"new_request" => "Request", - "request_accepted" => "Request", - "comment_on_post" => "Comment", - "also_commented" => "Comment"}.each_pair do |key, value| - Mongo::Notification.where(:action => key).update_all(:target_type => value) - end - log "Notification target types set." - end - - def import_raw_people - log "Loading people file..." - Mongo::Person.connection.execute set_time_zone_to_utc - Mongo::Person.connection.execute <<-SQL - #{load_string("people")} - #{infile_opts} - (@created_at,@updated_at,serialized_public_key,url,mongo_id,@owner_mongo_id,diaspora_handle) - SET guid = mongo_id, - #{nil_es("owner_mongo_id")}, - #{unix_time("created_at")}, - #{unix_time("updated_at")}; - SQL - log "Finished. Imported #{Mongo::Person.count} people." - end - - def import_raw_profiles - log "Loading profiles file..." - Mongo::Profile.connection.execute set_time_zone_to_utc - Mongo::Profile.connection.execute <<-SQL - #{load_string("profiles")} - #{infile_opts} - (@image_url_medium,@searchable,@image_url,person_mongo_id, - @gender,@diaspora_handle,@birthday,@last_name,@bio, - @image_url_small,@first_name) - SET #{boolean_set("searchable")}, - #{unix_time("birthday")}, - #{nil_es("image_url_medium")}, - #{nil_es("image_url")}, - #{nil_es("gender")}, - #{nil_es("diaspora_handle")}, - #{nil_es("last_name")}, - #{nil_es("bio")}, - #{nil_es("image_url_small")}, - #{nil_es("first_name")}; - SQL - #STRCMP returns 0 if the arguments are the same - log "Finished. Imported #{Mongo::Profile.count} profiles." - end - - def boolean_set(string) - "#{string}= IF(STRCMP(@#{string},'false'), TRUE, FALSE)" - end - - def nil_es(string) - "#{string} = NULLIF(@#{string}, '')" - end - - def unix_time(string) - "#{string} = FROM_UNIXTIME(@#{string} / 1000)" - end - - def infile_opts - <<-OPTS - FIELDS TERMINATED BY ',' - ENCLOSED BY '"' - IGNORE 1 LINES -OPTS - end - - def load_string model_name - "LOAD DATA INFILE '#{full_path}/#{model_name}.csv' INTO TABLE mongo_#{model_name}" - end - - def set_time_zone_to_utc - "set time_zone = '+0:00'" - end - end -end diff --git a/lib/tasks/migrations.rake b/lib/tasks/migrations.rake index ed049a2d7..0d3a59835 100644 --- a/lib/tasks/migrations.rake +++ b/lib/tasks/migrations.rake @@ -2,38 +2,7 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -require File.join(Rails.root, 'lib', 'data_conversion', 'base') -require File.join(Rails.root, 'lib', 'data_conversion', 'export_from_mongo') -require File.join(Rails.root, 'lib', 'data_conversion', 'import_to_mysql') - namespace :migrations do - desc 'export data for mysql import' - task :export_for_mysql do - migrator = DataConversion::ExportFromMongo.new - migrator.full_path = "/tmp/data_conversion" - migrator.log("**** Starting export for MySQL ****") - migrator.clear_dir - migrator.write_json_export - migrator.convert_json_files - migrator.log("**** Export finished! ****") - migrator.log("total elapsed time") - end - - desc 'import data to mysql' - task :import_to_mysql do - require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment') - migrator = DataConversion::ImportToMysql.new - migrator.full_path = "/tmp/data_conversion/csv" - migrator.log("**** Starting import to MySQL database #{ActiveRecord::Base.connection.current_database} ****") - migrator.import_raw - migrator.process_raw_tables - migrator.log("**** Import finished! ****") - migrator.log("total elapsed time") - end - - desc 'execute mongo to mysql migration. Requires mongoexport to be accessible.' - task :migrate_to_mysql => [:export_for_mysql, :import_to_mysql] - desc 'absolutify all existing image references' task :absolutify_image_references do require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment') @@ -43,7 +12,7 @@ namespace :migrations do # extract root # pod = URI::parse(photo.person.url) - pod_url = "#{pod.scheme}://#{pod.host}" + pod_url = "#{pod.scheme}://#{pod.host}" if photo.image.url remote_path = "#{photo.image.url}" @@ -65,11 +34,11 @@ namespace :migrations do task :upload_photos_to_s3 do require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment') puts AppConfig[:s3_key] - + connection = Aws::S3.new( AppConfig[:s3_key], AppConfig[:s3_secret]) bucket = connection.bucket('joindiaspora') dir_name = File.dirname(__FILE__) + "/../../public/uploads/images/" - + count = Dir.foreach(dir_name).count current = 0 @@ -85,7 +54,7 @@ namespace :migrations do puts "error #{e} on #{current} (#{file_name}), retrying" retry end - end + end } end diff --git a/public/javascripts/photo-show.js b/public/javascripts/photo-show.js index 5f940c6be..b8aa8e2db 100644 --- a/public/javascripts/photo-show.js +++ b/public/javascripts/photo-show.js @@ -26,8 +26,8 @@ $(document).ready(function() { $('.edit_photo').bind('ajax:success', function(data, json, xhr) { json = $.parseJSON(json); - $(".edit_photo input:text").val(json.photo.caption); - $("#caption").html(json.photo.caption); + $(".edit_photo input:text").val(json.photo.text); + $("#caption").html(json.photo.text); $("#show_photo").find("img").fadeTo(200,1); $("#photo_spinner").hide(); }); diff --git a/public/javascripts/publisher.js b/public/javascripts/publisher.js index 8b711c311..3e2eaa495 100644 --- a/public/javascripts/publisher.js +++ b/public/javascripts/publisher.js @@ -24,7 +24,7 @@ var Publisher = { cachedInput : false, input: function(){ if(!Publisher.cachedInput){ - Publisher.cachedInput = Publisher.form().find('#status_message_fake_message'); + Publisher.cachedInput = Publisher.form().find('#status_message_fake_text'); } return Publisher.cachedInput; }, @@ -39,7 +39,7 @@ var Publisher = { cachedHiddenInput : false, hiddenInput: function(){ if(!Publisher.cachedHiddenInput){ - Publisher.cachedHiddenInput = Publisher.form().find('#status_message_message'); + Publisher.cachedHiddenInput = Publisher.form().find('#status_message_text'); } return Publisher.cachedHiddenInput; }, @@ -315,7 +315,7 @@ var Publisher = { Publisher.bindServiceIcons(); Publisher.bindPublicIcon(); - if ($("#status_message_fake_message").val() == "") { + if ($("#status_message_fake_text").val() == "") { Publisher.close(); }; diff --git a/script/sanitize_database.rb b/script/sanitize_database.rb deleted file mode 100644 index 27efdf1a6..000000000 --- a/script/sanitize_database.rb +++ /dev/null @@ -1,177 +0,0 @@ -@start_time = Time.now.to_i -@count = 0 - -def sanitize_user(user) - log "Sanitizing user #{@count += 1}: #{user.username}" - people = Person.all(:owner_id => user.id) - log "#{user.username} has #{people.count} person objects." - - people.sort_by {|person| contact_count(person)} - - keep_person = people.last - dumb_people = people[0..(people.count)] - d_p_ids = dumb_people.map{|p| "ObjectId('#{p.id.to_s}')"} - d_p_ids_json = "[#{d_p_ids.join(',')}]" - - ["posts", "comments", "contacts"].each do |table_name| - eval_string = <<-JS - db.#{table_name}.find({ "person_id" : {"$in" : #{d_p_ids_json}}}).forEach(function(document){ - db.#{table_name}.update({"_id" : document["_id"]}, {"$set" : { "person_id" : ObjectId("#{keep_person.id.to_s}")}}); - }); - JS - MongoMapper.database.eval eval_string - end - - ['from_id', 'to_id'].each do |key| - eval_string = <<-JS - db.requests.find({ "#{key}" : {"$in" : #{d_p_ids_json}}}).forEach(function(document){ - db.requests.update({"_id" : document["_id"]}, {"$set" : { "#{key}" : ObjectId("#{keep_person.id.to_s}")}}); - }); - JS - MongoMapper.database.eval eval_string - end - - "Ids for user #{user.username} set to one person" - - dumb_people.each{|dumb| dumb.delete} - if user.serialized_private_key - keep_person.serialized_public_key = OpenSSL::PKey::RSA.new(user.serialized_private_key).public_key - keep_person.save - else - log "#{user.username} HAS NO ENCRYPTION KEY" - end -end - -def log string - time_diff = Time.now.to_i - @start_time - puts "#{time_diff}s; #{string}" -end - -def contact_count person - @contact_counts ||= {} - return @contact_counts[person.id] if @contact_counts[person.id] - query_result = @contacts_for_people_collection.find("_id" => person.id).first - - if query_result - @contact_counts[person.id] = query_result["value"] - else - @contact_counts[person.id] = 0 - end - - @contact_counts[person.id] -end -def get_user_ids - cmd = BSON::OrderedHash.new - cmd["mapreduce"] = "people" - cmd["map"] = 'function(){ emit(this["owner_id"], 1)};' - cmd["reduce"] = 'function(key, vals) {' + - 'var sum=0;' + - 'for(var i in vals) sum += vals[i];' + - 'return sum;' + - '};' - result = MongoMapper.database.command(cmd) - collection = MongoMapper.database.collection(result["result"]) - collection.find("value" => {"$gte" => 2}).map{|r| r["_id"]} -end - -def contacts_for_people_collection - cmd = BSON::OrderedHash.new - cmd["mapreduce"] = "contacts" - cmd["map"] = 'function(){ emit(this["person_id"], 1)};' - cmd["reduce"] = 'function(key, vals) {' + - 'var sum=0;' + - 'for(var i in vals) sum += vals[i];' + - 'return sum;' + - '};' - result = MongoMapper.database.command(cmd) - MongoMapper.database.collection(result["result"]) -end - -user_ids = get_user_ids - -@contacts_for_people_collection = contacts_for_people_collection -users = User.where(:id.in => user_ids).all -log "#{users.size} Users retreived." -users.each{ |user| sanitize_user(user) } - -log "Eliminating local people with no corresponding user." - -MongoMapper.database.eval <<-MOREJS -db.people.find().forEach( - function(doc){ - if(doc["owner_id"] != null && db.users.count({"_id" : doc["owner_id"]}) == 0){ - db.people.remove({"_id" : doc["_id"]}); - } - } -); -MOREJS - -def dup_user_emails - cmd = BSON::OrderedHash.new - cmd["mapreduce"] = "users" - cmd["map"] = 'function(){ emit(this["email"], 1)};' - cmd["reduce"] = 'function(key, vals) {' + - 'var sum=0;' + - 'for(var i in vals) sum += vals[i];' + - 'return sum;' + - '};' - result = MongoMapper.database.command(cmd) - coll = MongoMapper.database.collection(result["result"]) - user_emails = coll.find("value" => {"$gte" => 2}).map{|r| r["_id"]} -end - -emails = dup_user_emails -log "Eliminating #{emails.count} users with duplicate emails" - -users_coll = MongoMapper.database.collection("users") -users_coll.remove("email" => {"$in" => emails}) - -def dup_requests - cmd = BSON::OrderedHash.new - cmd["mapreduce"] = "requests" - cmd["map"] = 'function(){ emit(this["from_id"].toString() + "," + this["to_id"].toString(), {"array" : [this["_id"]], "count" : 1 })};' - cmd["reduce"] = 'function(key, vals) {' + - 'var result = {"array" : [], "count" : 0};' + - 'for(var i in vals){' + - 'result["array"] = result["array"].concat(vals[i]["array"]);' + - 'result["count"] += vals[i]["count"];' + - '}' + - 'return result;' + - '};' - result = MongoMapper.database.command(cmd) - coll = MongoMapper.database.collection(result["result"]) - #FIND WHERE "array" size is greater than 1 - coll.find({"value.count" => {"$gte" => 2}}).map{|r| r["value"]["array"]} -end -non_unique_requests = dup_requests -non_unique_requests.each{|request_id_array| request_id_array.pop} -non_unique_requests.flatten! - -log "Eliminating #{non_unique_requests.length} duplicate requests" -req_coll = MongoMapper.database.collection("requests") -req_coll.remove("_id" => {"$in" => non_unique_requests}) - -def dup_contacts - cmd = BSON::OrderedHash.new - cmd["mapreduce"] = "contacts" - cmd["map"] = 'function(){ emit(this["person_id"].toString() + "," + this["user_id"].toString(), {"array" : [this["_id"]], "count" : 1 })};' - cmd["reduce"] = 'function(key, vals) {' + - 'var result = {"array" : [], "count" : 0};' + - 'for(var i in vals){' + - 'result["array"] = result["array"].concat(vals[i]["array"]);' + - 'result["count"] += vals[i]["count"];' + - '}' + - 'return result;' + - '};' - result = MongoMapper.database.command(cmd) - coll = MongoMapper.database.collection(result["result"]) - #FIND WHERE "array" size is greater than 1 - coll.find({"value.count" => {"$gte" => 2}}).map{|r| r["value"]["array"]} -end -non_unique_contacts = dup_contacts -non_unique_contacts.each{|contact_id_array| contact_id_array.pop} -non_unique_contacts.flatten! - -log "Eliminating #{non_unique_contacts.length} duplicate contacts" -req_coll = MongoMapper.database.collection("contacts") -req_coll.remove("_id" => {"$in" => non_unique_contacts}) diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index e50a0b65d..2a4e89aea 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -64,7 +64,7 @@ describe AspectsController do save_fixture(html_for("body"), "aspects_index_services") end it 'generates a jasmine fixture with posts' do - @alice.post(:status_message, :message => "hello", :to => @alices_aspect_2.id) + @alice.post(:status_message, :text => "hello", :to => @alices_aspect_2.id) get :index save_fixture(html_for("body"), "aspects_index_with_posts") end @@ -76,7 +76,7 @@ describe AspectsController do aspect = user.aspects.create(:name => 'people') connect_users(@alice, @alices_aspect_1, user, aspect) target_aspect = n.even? ? @alices_aspect_1 : @alices_aspect_2 - post = @alice.post(:status_message, :message => "hello#{n}", :to => target_aspect) + post = @alice.post(:status_message, :text=> "hello#{n}", :to => target_aspect) post.created_at = Time.now - (2 - n).seconds post.save! @posts << post @@ -120,7 +120,7 @@ describe AspectsController do user = Factory.create(:user) aspect = user.aspects.create(:name => 'people') connect_users(@alice, @alices_aspect_1, user, aspect) - post = @alice.post(:status_message, :message => "hello#{n}", :to => @alices_aspect_2.id) + post = @alice.post(:status_message, :text => "hello#{n}", :to => @alices_aspect_2.id) 8.times do |n| user.comment "yo#{post.message}", :on => post end @@ -272,7 +272,7 @@ describe AspectsController do response.should be_success end end - + describe "#toggle_contact_visibility" do it 'sets contacts visible' do @alices_aspect_1.contacts_visible = false diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index f003ae71c..0f2b3897e 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -24,7 +24,7 @@ describe CommentsController do } context "on my own post" do before do - @post = @user1.post :status_message, :message => 'GIANTS', :to => @aspect1.id + @post = @user1.post :status_message, :text => 'GIANTS', :to => @aspect1.id end it 'responds to format js' do post :create, comment_hash.merge(:format => 'js') @@ -35,7 +35,7 @@ describe CommentsController do context "on a post from a contact" do before do - @post = @user2.post :status_message, :message => 'GIANTS', :to => @aspect2.id + @post = @user2.post :status_message, :text => 'GIANTS', :to => @aspect2.id end it 'comments' do post :create, comment_hash @@ -56,7 +56,7 @@ describe CommentsController do end context 'on a post from a stranger' do before do - @post = eve.post :status_message, :message => 'GIANTS', :to => eve.aspects.first.id + @post = eve.post :status_message, :text => 'GIANTS', :to => eve.aspects.first.id end it 'posts no comment' do @user1.should_not_receive(:comment) diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index cb6c647ea..f015cb30a 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -63,7 +63,7 @@ describe PeopleController do aspect = user.aspects.create(:name => 'people') connect_users(@user, @user.aspects.first, user, aspect) - @posts << @user.post(:status_message, :message => "hello#{n}", :to => aspect.id) + @posts << @user.post(:status_message, :text => "hello#{n}", :to => aspect.id) end @posts.each do |post| @users.each do |user| @@ -113,16 +113,16 @@ describe PeopleController do it "assigns all the user's posts" do @user.posts.should be_empty - @user.post(:status_message, :message => "to one aspect", :to => @aspect.id) - @user.post(:status_message, :message => "to all aspects", :to => 'all') - @user.post(:status_message, :message => "public", :to => 'all', :public => true) + @user.post(:status_message, :text => "to one aspect", :to => @aspect.id) + @user.post(:status_message, :text => "to all aspects", :to => 'all') + @user.post(:status_message, :text => "public", :to => 'all', :public => true) @user.reload.posts.length.should == 3 get :show, :id => @user.person.to_param assigns(:posts).should =~ @user.posts end it "renders the comments on the user's posts" do - message = @user.post :status_message, :message => 'test more', :to => @aspect.id + message = @user.post :status_message, :text => 'test more', :to => @aspect.id @user.comment 'I mean it', :on => message get :show, :id => @user.person.id response.should be_success @@ -140,10 +140,10 @@ describe PeopleController do end it "assigns only public posts" do public_posts = [] - public_posts << bob.post(:status_message, :message => "first public ", :to => bob.aspects[0].id, :public => true) - bob.post(:status_message, :message => "to an aspect @user is not in", :to => bob.aspects[1].id) - bob.post(:status_message, :message => "to all aspects", :to => 'all') - public_posts << bob.post(:status_message, :message => "public", :to => 'all', :public => true) + public_posts << bob.post(:status_message, :text => "first public ", :to => bob.aspects[0].id, :public => true) + bob.post(:status_message, :text => "to an aspect @user is not in", :to => bob.aspects[1].id) + bob.post(:status_message, :text => "to all aspects", :to => 'all') + public_posts << bob.post(:status_message, :text => "public", :to => 'all', :public => true) get :show, :id => @person.id @@ -163,10 +163,10 @@ describe PeopleController do it "assigns only the posts the current user can see" do bob.posts.should be_empty posts_user_can_see = [] - posts_user_can_see << bob.post(:status_message, :message => "to an aspect @user is in", :to => bob.aspects[0].id) - bob.post(:status_message, :message => "to an aspect @user is not in", :to => bob.aspects[1].id) - posts_user_can_see << bob.post(:status_message, :message => "to all aspects", :to => 'all') - posts_user_can_see << bob.post(:status_message, :message => "public", :to => 'all', :public => true) + posts_user_can_see << bob.post(:status_message, :text => "to an aspect @user is in", :to => bob.aspects[0].id) + bob.post(:status_message, :text => "to an aspect @user is not in", :to => bob.aspects[1].id) + posts_user_can_see << bob.post(:status_message, :text => "to all aspects", :to => 'all') + posts_user_can_see << bob.post(:status_message, :text => "public", :to => 'all', :public => true) bob.reload.posts.length.should == 4 get :show, :id => @person.id @@ -186,9 +186,9 @@ describe PeopleController do it "assigns only public posts" do eve.posts.should be_empty - eve.post(:status_message, :message => "to an aspect @user is not in", :to => eve.aspects.first.id) - eve.post(:status_message, :message => "to all aspects", :to => 'all') - public_post = eve.post(:status_message, :message => "public", :to => 'all', :public => true) + eve.post(:status_message, :text => "to an aspect @user is not in", :to => eve.aspects.first.id) + eve.post(:status_message, :text => "to all aspects", :to => 'all') + public_post = eve.post(:status_message, :text => "public", :to => 'all', :public => true) eve.reload.posts.length.should == 3 get :show, :id => @person.id diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index f8e241b9b..0908a7cce 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -30,7 +30,7 @@ describe PhotosController do post :create, @params }.should change(Photo, :count).by(1) end - + it 'can set the photo as the profile photo' do old_url = @alice.person.profile.image_url @params[:photo][:set_profile_photo] = true @@ -137,19 +137,19 @@ describe PhotosController do describe "#update" do it "updates the caption of a photo" do - put :update, :id => @alices_photo.id, :photo => { :caption => "now with lasers!" } + put :update, :id => @alices_photo.id, :photo => { :text => "now with lasers!" } @alices_photo.reload.caption.should == "now with lasers!" end it "doesn't overwrite random attributes" do new_user = Factory.create(:user) - params = { :caption => "now with lasers!", :author_id => new_user.id } + params = { :text => "now with lasers!", :author_id => new_user.id } put :update, :id => @alices_photo.id, :photo => params @alices_photo.reload.author_id.should == @alice.person.id end it 'redirects if you do not have access to the post' do - params = { :caption => "now with lasers!" } + params = { :text => "now with lasers!" } put :update, :id => @bobs_photo.id, :photo => params response.should redirect_to(:action => :index, :person_id => @alice.person.id.to_s) end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 9b54098c2..41d558880 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -23,9 +23,9 @@ describe PostsController do pending posts = [] 2.times do - posts << @user.post(:status_message, :message => "#what", :to => 'all') + posts << @user.post(:status_message, :text => "#what", :to => 'all') end - eve.post(:status_message, :message => "#what", :to => 'all') + eve.post(:status_message, :text => "#what", :to => 'all') get :index assigns[:posts].should =~ posts @@ -34,9 +34,9 @@ describe PostsController do pending posts = [] 2.times do - posts << bob.post(:status_message, :message => "#what", :to => 'all') + posts << bob.post(:status_message, :text => "#what", :to => 'all') end - eve.post(:status_message, :message => "#what", :to => 'all') + eve.post(:status_message, :text => "#what", :to => 'all') get :index assigns[:posts].should =~ posts @@ -45,10 +45,10 @@ describe PostsController do it 'restricts the posts by tag' do posts = [] 2.times do - posts << @user.post(:status_message, :message => "#what", :public => true, :to => 'all') + posts << @user.post(:status_message, :text => "#what", :public => true, :to => 'all') end 2.times do - @user.post(:status_message, :message => "#hello", :public => true, :to => 'all') + @user.post(:status_message, :text => "#hello", :public => true, :to => 'all') end get :index, :tag => 'what' @@ -59,7 +59,7 @@ describe PostsController do pending posts = [] 3.times do - posts << @user.post(:status_message, :message => "hello", :public => true, :to => 'all') + posts << @user.post(:status_message, :text => "hello", :public => true, :to => 'all') end get :index assigns[:posts].should =~ posts @@ -67,7 +67,7 @@ describe PostsController do it' shows only local posts' do pending 3.times do - @user.post(:status_message, :message => "hello", :public => true, :to => 'all') + @user.post(:status_message, :text => "hello", :public => true, :to => 'all') end @user.person.update_attributes(:owner_id => nil) get :index @@ -76,14 +76,14 @@ describe PostsController do end describe '#show' do it 'shows a public post' do - status = @user.post(:status_message, :message => "hello", :public => true, :to => 'all') + status = @user.post(:status_message, :text => "hello", :public => true, :to => 'all') get :show, :id => status.id response.status= 200 end it 'does not show a private post' do - status = @user.post(:status_message, :message => "hello", :public => false, :to => 'all') + status = @user.post(:status_message, :text => "hello", :public => false, :to => 'all') get :show, :id => status.id response.status = 302 end diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index 7fd6d9a3b..a4eb80d1f 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -35,7 +35,7 @@ describe PublicsController do it 'unescapes the xml before sending it to receive_salmon' do aspect = @user.aspects.create(:name => 'foo') - post1 = @user.post(:status_message, :message => 'moms', :to => [aspect.id]) + post1 = @user.post(:status_message, :text => 'moms', :to => [aspect.id]) xml2 = post1.to_diaspora_xml user2 = Factory(:user) diff --git a/spec/controllers/sockets_controller_spec.rb b/spec/controllers/sockets_controller_spec.rb index c8bab6399..da6e6524f 100644 --- a/spec/controllers/sockets_controller_spec.rb +++ b/spec/controllers/sockets_controller_spec.rb @@ -20,7 +20,7 @@ describe SocketsController do describe 'actionhash' do before do @aspect = @user.aspects.first - @message = @user.post :status_message, :message => "post through user for victory", :to => @aspect.id + @message = @user.post :status_message, :text => "post through user for victory", :to => @aspect.id @fixture_name = File.dirname(__FILE__) + '/../fixtures/button.png' end diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 305656dc2..28910582e 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -22,7 +22,7 @@ describe StatusMessagesController do describe '#show' do before do - @message = @user1.build_post :status_message, :message => "ohai", :to => @aspect1.id + @message = @user1.build_post :status_message, :text => "ohai", :to => @aspect1.id @message.save! @user1.add_to_streams(@message, [@aspect1]) @@ -55,7 +55,7 @@ describe StatusMessagesController do let(:status_message_hash) { { :status_message => { :public => "true", - :message => "facebook, is that you?", + :text => "facebook, is that you?", }, :aspect_ids => [@aspect1.id.to_s] } } @@ -72,7 +72,7 @@ describe StatusMessagesController do end it 'escapes XSS' do xss = "" - post :create, status_message_hash.merge(:format => 'js', :message => xss) + post :create, status_message_hash.merge(:format => 'js', :text => xss) json = JSON.parse(response.body) json['html'].should_not =~ /" + @message.text = "" @message.to_xml.to_s.should include @message.message end it 'serializes the message' do @@ -282,7 +282,7 @@ STR mock_http.should_receive(:get).with('/feeds/api/videos/'+video_id+'?v=2', nil).and_return( [nil, 'Foobar