diff --git a/example_profile.yml b/example_profile.yml new file mode 100644 index 0000000..e0dc7ad --- /dev/null +++ b/example_profile.yml @@ -0,0 +1,775 @@ +--- +:community: + - :id: 1 + :name: Lorem Ipsum + :type: Community + :identifier: lorem + :environment_id: 1 + :active: true + :address: '' + :contact_phone: + :home_page_id: 310 + :user_id: + :region_id: + :data: + :moderated_articles: false + :layout_template: default + :closed: false + :redirect_l10n: false + :email_suggestions: false + :fields_privacy: !ruby/hash:ActiveSupport::HashWithIndifferentAccess + address: public + :created_at: 2014-12-05 11:09:15.201420000 Z + :lat: + :lng: + :geocode_precision: + :enabled: true + :nickname: + :custom_header: + :custom_footer: + :theme: + :public_profile: true + :birth_date: + :preferred_domain_id: + :updated_at: 2015-06-24 20:40:28.548303000 Z + :visible: true + :image_id: 49 + :validated: true + :cnpj: + :national_region_code: + :is_template: false + :template_id: 67 + :redirection_after_login: keep_on_same_page + :friends_count: 0 + :members_count: 13 + :activities_count: 6 + :personal_website: + :jabber_id: + :welcome_page_id: + :allow_members_to_invite: true + :invite_friends_only: false + :secret: false +:image: + - :id: 49 + :parent_id: + :content_type: image/png + :filename: lorem.png + :thumbnail: + :size: 3574 + :width: 150 + :height: 183 + :thumbnails_processed: true + :label: '' + - :id: 50 + :parent_id: 49 + :content_type: image/png + :filename: lorem_big.png + :thumbnail: big + :size: 18720 + :width: 123 + :height: 150 + :thumbnails_processed: false + :label: '' + - :id: 51 + :parent_id: 49 + :content_type: image/png + :filename: lorem_thumb.png + :thumbnail: thumb + :size: 10781 + :width: 82 + :height: 100 + :thumbnails_processed: false + :label: '' + - :id: 52 + :parent_id: 49 + :content_type: image/png + :filename: lorem_portrait.png + :thumbnail: portrait + :size: 5771 + :width: 52 + :height: 64 + :thumbnails_processed: false + :label: '' + - :id: 53 + :parent_id: 49 + :content_type: image/png + :filename: lorem_minor.png + :thumbnail: minor + :size: 4146 + :width: 41 + :height: 50 + :thumbnails_processed: false + :label: '' + - :id: 54 + :parent_id: 49 + :content_type: image/png + :filename: lorem_icon.png + :thumbnail: icon + :size: 1232 + :width: 20 + :height: 20 + :thumbnails_processed: false + :label: '' +:box: + - :id: 262 + :owner_type: Profile + :owner_id: 1 + :position: 1 + - :id: 263 + :owner_type: Profile + :owner_id: 1 + :position: 2 + - :id: 264 + :owner_type: Profile + :owner_id: 1 + :position: 3 + - :id: 1592 + :owner_type: Profile + :owner_id: 1 + :position: 4 +:block: + - :id: 489 + :title: '' + :box_id: 262 + :type: MainBlock + :settings: + :fixed: false + :display: always + :display_user: all + :language: all + :position: 3 + :enabled: true + :created_at: 2014-12-05 11:09:15.563837000 Z + :updated_at: 2014-12-08 18:13:12.306137000 Z + :fetched_at: + :mirror: false + :mirror_block_id: + :observers_id: + - :id: 490 + :title: + :box_id: 262 + :type: CategoriesAndTagsBlock + :settings: + :display: home_page_only + :position: 4 + :enabled: true + :created_at: 2014-12-05 11:09:15.584732000 Z + :updated_at: 2014-12-05 11:09:15.584732000 Z + :fetched_at: + :mirror: false + :mirror_block_id: + :observers_id: + - :id: 1700 + :title: '' + :box_id: 263 + :type: LinkListBlock + :settings: + :links: + - !ruby/hash:ActiveSupport::HashWithIndifferentAccess + :icon: no-icon + :name: Link + :address: /link + :target: _self + :fixed: false + :display: always + :display_user: all + :language: all + :position: 1 + :enabled: true + :created_at: 2015-03-12 14:27:35.845251000 Z + :updated_at: 2015-03-12 14:31:22.355721000 Z + :fetched_at: + :mirror: false + :mirror_block_id: + :observers_id: + - :id: 494 + :title: + :box_id: 264 + :type: ProfileImageBlock + :settings: + :display: except_home_page + :show_name: false + :position: 1 + :enabled: true + :created_at: 2014-12-05 11:09:15.882481000 Z + :updated_at: 2014-12-05 11:09:15.882481000 Z + :fetched_at: + :mirror: false + :mirror_block_id: + :observers_id: + - :id: 498 + :title: Integrantes + :box_id: 264 + :type: MembersBlock + :settings: + :display: never + :name: '' + :address: '' + :visible_role: '' + :limit: 6 + :prioritize_profiles_with_image: true + :show_join_leave_button: false + :fixed: false + :display_user: all + :language: all + :position: 5 + :enabled: true + :created_at: 2014-12-05 11:09:16.181404000 Z + :updated_at: 2015-03-13 01:50:49.150748000 Z + :fetched_at: + :mirror: false + :mirror_block_id: + :observers_id: +:article: + - :id: 302 + :name: Blog + :slug: blog + :path: blog + :parent_id: + :body: + :abstract: + :profile_id: 1 + :updated_at: 2014-12-08 11:07:35.894768000 Z + :created_at: 2014-12-05 11:09:16.334973000 Z + :last_changed_by_id: + :version: 1 + :type: Blog + :size: + :content_type: + :filename: + :height: + :width: + :comments_count: 0 + :advertise: false + :published: true + :start_date: + :end_date: + :children_count: 2 + :accept_comments: true + :reference_article_id: + :setting: {} + :notify_comments: true + :hits: 40 + :published_at: 2014-10-21 12:01:07.090025000 Z + :source: + :highlighted: false + :external_link: + :thumbnails_processed: false + :is_image: false + :translation_of_id: + :language: + :source_name: + :license_id: + :image_id: + :position: + :spam_comments_count: 0 + :author_id: + :created_by_id: + :show_to_followers: false + - :id: 303 + :name: feed + :slug: feed + :path: blog/feed + :parent_id: 302 + :body: {} + :abstract: + :profile_id: 1 + :updated_at: 2014-12-05 11:09:16.348735000 Z + :created_at: 2014-12-05 11:09:16.348735000 Z + :last_changed_by_id: + :version: 1 + :type: RssFeed + :size: + :content_type: + :filename: + :height: + :width: + :comments_count: 0 + :advertise: false + :published: true + :start_date: + :end_date: + :children_count: 0 + :accept_comments: true + :reference_article_id: + :setting: {} + :notify_comments: true + :hits: 0 + :published_at: 2014-12-05 11:09:16.348516000 Z + :source: + :highlighted: false + :external_link: + :thumbnails_processed: false + :is_image: false + :translation_of_id: + :language: + :source_name: + :license_id: + :image_id: + :position: + :spam_comments_count: 0 + :author_id: + :created_by_id: + :show_to_followers: false + - :id: 304 + :name: Gallery + :slug: gallery + :path: gallery + :parent_id: + :body: + :abstract: + :profile_id: 1 + :updated_at: 2014-12-08 20:41:54.571859000 Z + :created_at: 2014-12-05 11:09:16.544535000 Z + :last_changed_by_id: + :version: 1 + :type: Gallery + :size: + :content_type: + :filename: + :height: + :width: + :comments_count: 0 + :advertise: false + :published: true + :start_date: + :end_date: + :children_count: 5 + :accept_comments: true + :reference_article_id: + :setting: {} + :notify_comments: true + :hits: 52 + :published_at: 2014-10-21 12:01:07.278852000 Z + :source: + :highlighted: false + :external_link: + :thumbnails_processed: false + :is_image: false + :translation_of_id: + :language: + :source_name: + :license_id: + :image_id: + :position: + :spam_comments_count: 0 + :author_id: + :created_by_id: + :show_to_followers: false + - :id: 305 + :name: Documentação + :slug: documentacao + :path: documentacao + :parent_id: + :body: Pasta destinada para documentação + :abstract: + :profile_id: 1 + :updated_at: 2015-01-29 13:00:52.171667000 Z + :created_at: 2014-12-05 11:09:16.591802000 Z + :last_changed_by_id: 82 + :version: 2 + :type: Folder + :size: + :content_type: + :filename: + :height: + :width: + :comments_count: 0 + :advertise: true + :published: true + :start_date: + :end_date: + :children_count: 0 + :accept_comments: false + :reference_article_id: + :setting: {} + :notify_comments: true + :hits: 197 + :published_at: 2014-12-04 18:24:31.823160000 Z + :source: + :highlighted: false + :external_link: + :thumbnails_processed: false + :is_image: false + :translation_of_id: + :language: + :source_name: + :license_id: + :image_id: + :position: + :spam_comments_count: 0 + :author_id: + :created_by_id: + :show_to_followers: false + - :id: 386 + :name: Em construção + :slug: em-construcao + :path: blog/em-construcao + :parent_id: 302 + :body: ! '

Em construção.

' + :abstract: '' + :profile_id: 1 + :updated_at: 2014-12-08 11:07:35.818152000 Z + :created_at: 2014-12-08 11:07:35.818152000 Z + :last_changed_by_id: 71 + :version: 1 + :type: TinyMceArticle + :size: + :content_type: + :filename: + :height: + :width: + :comments_count: 0 + :advertise: true + :published: true + :start_date: + :end_date: + :children_count: 0 + :accept_comments: false + :reference_article_id: + :setting: + :allow_members_to_edit: false + :moderate_comments: false + :display_hits: true + :display_versions: false + :author_name: Joana Silva + :notify_comments: true + :hits: 1 + :published_at: 2014-12-08 11:07:35.817826000 Z + :source: + :highlighted: false + :external_link: + :thumbnails_processed: false + :is_image: false + :translation_of_id: + :language: pt + :source_name: + :license_id: + :image_id: + :position: + :spam_comments_count: 0 + :author_id: 71 + :created_by_id: 71 + :show_to_followers: false +:role_assignment: + - :id: 33 + :accessor_id: 71 + :accessor_type: Profile + :resource_id: 1 + :resource_type: Profile + :role_id: 6 + :is_global: + - :id: 43 + :accessor_id: 93 + :accessor_type: Profile + :resource_id: 1 + :resource_type: Profile + :role_id: 7 + :is_global: + - :id: 49 + :accessor_id: 82 + :accessor_type: Profile + :resource_id: 1 + :resource_type: Profile + :role_id: 6 + :is_global: +:software_info: + - :id: 12 + :license_info_id: 1 + :community_id: 1 + :e_mag: false + :icp_brasil: false + :intern: false + :e_ping: false + :e_arq: false + :operating_platform: '' + :demonstration_url: http://teste.lorem.cc + :acronym: '' + :objectives: + :features: ! "\r\nLorem ipsum dolor sit amet, consectetur adipiscing elit. + Ut facilisis augue a libero volutpat malesuada. Pellentesque diam mi, venenatis + et ante sodales, auctor maximus tortor. Suspendisse sodales varius lacus, ut + varius est luctus vel. Donec id ligula vitae diam volutpat dictum. Duis et sem + tempor, sagittis ligula nec, iaculis est. Etiam pulvinar nulla in luctus cursus. + Suspendisse fringilla ex sit amet luctus fringilla. Fusce eu nibh varius nisl + faucibus imperdiet. Aliquam erat volutpat. Fusce hendrerit pulvinar auctor. + Quisque vitae posuere metus. Vivamus eros elit, egestas et pharetra id, luctus + sed orci. Donec vestibulum lacus vel sapien dignissim, sed tempus metus maximus. + Integer consequat elit sed dignissim rhoncus. + na rede." + :finality: Lorem ipsum dolor sit amet + :repository_link: https://portal.softwarepublico.gov.br/gitlab/groups/lorem/ + :public_software: true + :first_edit: false + :settings: {} +:article_version: + - :id: 313 + :article_id: 302 + :version: 1 + :name: Blog + :slug: blog + :path: blog + :parent_id: + :body: + :abstract: + :profile_id: 1 + :updated_at: 2014-12-05 11:09:16.334973000 Z + :created_at: 2014-12-05 11:09:16.334973000 Z + :last_changed_by_id: + :size: + :content_type: + :filename: + :height: + :width: + :versioned_type: Blog + :comments_count: 0 + :advertise: false + :published: true + :start_date: + :end_date: + :children_count: 0 + :accept_comments: true + :reference_article_id: + :setting: + :notify_comments: true + :hits: 0 + :published_at: 2014-10-21 12:01:07.090025000 Z + :source: + :highlighted: false + :external_link: + :thumbnails_processed: false + :is_image: false + :translation_of_id: + :language: + :source_name: + :license_id: + :image_id: + :position: + :spam_comments_count: 0 + :author_id: + :created_by_id: + - :id: 312 + :article_id: 303 + :version: 1 + :name: feed + :slug: feed + :path: blog/feed + :parent_id: 302 + :body: ! '--- {}' + :abstract: + :profile_id: 1 + :updated_at: 2014-12-05 11:09:16.348735000 Z + :created_at: 2014-12-05 11:09:16.348735000 Z + :last_changed_by_id: + :size: + :content_type: + :filename: + :height: + :width: + :versioned_type: RssFeed + :comments_count: 0 + :advertise: false + :published: true + :start_date: + :end_date: + :children_count: 0 + :accept_comments: true + :reference_article_id: + :setting: + :notify_comments: true + :hits: 0 + :published_at: 2014-12-05 11:09:16.348516000 Z + :source: + :highlighted: false + :external_link: + :thumbnails_processed: false + :is_image: false + :translation_of_id: + :language: + :source_name: + :license_id: + :image_id: + :position: + :spam_comments_count: 0 + :author_id: + :created_by_id: + - :id: 544 + :article_id: 386 + :version: 1 + :name: Em construção + :slug: em-construcao + :path: blog/em-construcao + :parent_id: 302 + :body: ! '

Em construção.

' + :abstract: '' + :profile_id: 1 + :updated_at: 2014-12-08 11:07:35.818152000 Z + :created_at: 2014-12-08 11:07:35.818152000 Z + :last_changed_by_id: 71 + :size: + :content_type: + :filename: + :height: + :width: + :versioned_type: TinyMceArticle + :comments_count: 0 + :advertise: true + :published: true + :start_date: + :end_date: + :children_count: 0 + :accept_comments: false + :reference_article_id: + :setting: + :notify_comments: true + :hits: 0 + :published_at: 2014-12-08 11:07:35.817826000 Z + :source: + :highlighted: false + :external_link: + :thumbnails_processed: false + :is_image: false + :translation_of_id: + :language: pt + :source_name: + :license_id: + :image_id: + :position: + :spam_comments_count: 0 + :author_id: 71 + :created_by_id: 71 + - :id: 314 + :article_id: 304 + :version: 1 + :name: Gallery + :slug: gallery + :path: gallery + :parent_id: + :body: + :abstract: + :profile_id: 1 + :updated_at: 2014-12-05 11:09:16.544535000 Z + :created_at: 2014-12-05 11:09:16.544535000 Z + :last_changed_by_id: + :size: + :content_type: + :filename: + :height: + :width: + :versioned_type: Gallery + :comments_count: 0 + :advertise: false + :published: true + :start_date: + :end_date: + :children_count: 0 + :accept_comments: true + :reference_article_id: + :setting: + :notify_comments: true + :hits: 0 + :published_at: 2014-10-21 12:01:07.278852000 Z + :source: + :highlighted: false + :external_link: + :thumbnails_processed: false + :is_image: false + :translation_of_id: + :language: + :source_name: + :license_id: + :image_id: + :position: + :spam_comments_count: 0 + :author_id: + :created_by_id: + - :id: 315 + :article_id: 305 + :version: 1 + :name: Documentação + :slug: documentacao + :path: documentacao + :parent_id: + :body: Pasta + :abstract: + :profile_id: 1 + :updated_at: 2014-12-05 11:09:16.591802000 Z + :created_at: 2014-12-05 11:09:16.591802000 Z + :last_changed_by_id: + :size: + :content_type: + :filename: + :height: + :width: + :versioned_type: Folder + :comments_count: 0 + :advertise: false + :published: true + :start_date: + :end_date: + :children_count: 0 + :accept_comments: false + :reference_article_id: + :setting: + :notify_comments: true + :hits: 0 + :published_at: 2014-12-04 18:24:31.823160000 Z + :source: + :highlighted: false + :external_link: + :thumbnails_processed: false + :is_image: false + :translation_of_id: + :language: + :source_name: + :license_id: 1 + :image_id: + :position: + :spam_comments_count: 0 + :author_id: + :created_by_id: + - :id: 1170 + :article_id: 305 + :version: 2 + :name: Documentação + :slug: documentacao + :path: documentacao + :parent_id: + :body: Pasta destinada para documentação + :abstract: + :profile_id: 1 + :updated_at: 2015-01-29 13:00:52.171667000 Z + :created_at: 2014-12-05 11:09:16.591802000 Z + :last_changed_by_id: 82 + :size: + :content_type: + :filename: + :height: + :width: + :versioned_type: Folder + :comments_count: 0 + :advertise: true + :published: true + :start_date: + :end_date: + :children_count: 0 + :accept_comments: false + :reference_article_id: + :setting: + :notify_comments: true + :hits: 73 + :published_at: 2014-12-04 18:24:31.823160000 Z + :source: + :highlighted: false + :external_link: + :thumbnails_processed: false + :is_image: false + :translation_of_id: + :language: + :source_name: + :license_id: + :image_id: + :position: + :spam_comments_count: 0 + :author_id: + :created_by_id: diff --git a/import_profile b/import_profile new file mode 100755 index 0000000..79bc298 --- /dev/null +++ b/import_profile @@ -0,0 +1,39 @@ +#!/usr/bin/env ruby + +require 'rubygems' +require "#{File.dirname(__FILE__)}/../config/environment" + +def import_profile(config) + puts "Importing profile" + config.keys.each do |record_type| + puts record_type.to_s + puts "#{config[record_type].size} registros" + if record_type == :article_version + klass = Article::Version + else + klass = record_type.to_s.camelize.constantize + end + config[record_type.to_sym].each do |attrs| + settings = attrs.keys.select { |k| attrs[k.to_sym].is_a? Hash } + names = attrs.except(*settings).keys + values = names.map {|k| ActiveRecord::Base.send(:sanitize_sql_array, ['?', attrs[k.to_sym]]) } + sql = 'insert into %s(%s) values (%s)' % [klass.table_name, names.join(','), values.join(',')] + klass.connection.execute(sql) + record = klass.find(attrs[:id]) + + settings.each do |setting| + record.send("#{setting}=", attrs[setting.to_sym]) + record.save + end + end + end +end + +if ARGV.blank? + puts "--- Please provide the yaml configuration file ---" + exit 0 +else + $config_file = ARGV[0] + config = YAML::load_file($config_file) + import_profile config +end -- libgit2 0.21.2