From 7f8f3fa15230cba9e9b6250ead642dfbe2710833 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 2 Feb 2016 18:47:53 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=A2=ABrubymine=E5=9D=91=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E8=BF=99=E4=B8=A4=E4=B8=AA=E6=96=87=E4=BB=B6=E6=B2=A1?= =?UTF-8?q?=E5=8A=A0=E8=BF=9B=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/secdomain.rb | 18 ++++++++++++ .../20160202034530_create_secdomains.rb | 28 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 app/models/secdomain.rb create mode 100644 db/migrate/20160202034530_create_secdomains.rb diff --git a/app/models/secdomain.rb b/app/models/secdomain.rb new file mode 100644 index 000000000..4d0abe5db --- /dev/null +++ b/app/models/secdomain.rb @@ -0,0 +1,18 @@ +class Secdomain < ActiveRecord::Base + attr_accessible :pid, :subname, :sub_type, :desc + + validates_presence_of :subname, :sub_type + validates_uniqueness_of :subname + + def controller + return 'organizations' if sub_type == 2 + return 'users' if sub_type == 3 + nil + end + + def action + return 'show' if sub_type == 2 + return 'show' if sub_type == 3 + nil + end +end diff --git a/db/migrate/20160202034530_create_secdomains.rb b/db/migrate/20160202034530_create_secdomains.rb new file mode 100644 index 000000000..49650d073 --- /dev/null +++ b/db/migrate/20160202034530_create_secdomains.rb @@ -0,0 +1,28 @@ +class CreateSecdomains < ActiveRecord::Migration + def change + create_table :secdomains do |t| + t.integer :sub_type #1.系统预留 2.Organization 3.users + t.string :subname #子域名 + t.integer :pid, default: 0 #参数id + t.string :desc + + t.timestamps + end + + #系统保留 + Secdomain.create(sub_type: 1, subname: 'gitlab') + Secdomain.create(sub_type: 1, subname: 'wechat') + Secdomain.create(sub_type: 1, subname: 'judge') + + #organization + Secdomain.create(sub_type: 2, subname: 'micros', pid: 5) + Secdomain.create(sub_type: 2, subname: 'nubot', pid: 23) + Secdomain.create(sub_type: 2, subname: 'team', pid: 1) + + #users + Secdomain.create(sub_type: 3, subname: 'whm', pid: 7) + Secdomain.create(sub_type: 3, subname: 'yg', pid: 5) + Secdomain.create(sub_type: 3, subname: 'wt', pid: 11) + + end +end From eb3644a197caf5fc3c4df1af6f725996c363a22c Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 2 Feb 2016 19:16:15 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=B0=86=E4=B8=80=E5=A0=86=E7=9A=84rake?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E5=8F=98=E4=B8=BA=E4=B8=80=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/elasticsearch_batch_op.rake | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/tasks/elasticsearch_batch_op.rake b/lib/tasks/elasticsearch_batch_op.rake index 4be382367..b9933cf75 100644 --- a/lib/tasks/elasticsearch_batch_op.rake +++ b/lib/tasks/elasticsearch_batch_op.rake @@ -1,17 +1,11 @@ namespace :importer do - task :import_all => :environment do - Rake::Task["importer:importuser"].execute - Rake::Task["importer:importproject"].execute - Rake::Task["importer:importcourse"].execute - Rake::Task["importer:importattachment"].execute - Rake::Task["importer:importmemo"].execute - end + task :importuser => :environment do ENV['CLASS']='User' ENV['SCOPE']='indexable' ENV['FORCE']='y' ENV['BATCH']='1000' - Rake::Task["elasticsearch:import:model"].invoke + Rake::Task["elasticsearch:import:model"].execute end task :importproject => :environment do @@ -19,27 +13,30 @@ namespace :importer do ENV['SCOPE']='indexable' ENV['FORCE']='y' ENV['BATCH']='1000' - Rake::Task["elasticsearch:import:model"].invoke + Rake::Task["elasticsearch:import:model"].execute end task :importcourse => :environment do ENV['CLASS']='Course' ENV['SCOPE']='indexable' ENV['FORCE']='y' ENV['BATCH']='1000' - Rake::Task["elasticsearch:import:model"].invoke + Rake::Task["elasticsearch:import:model"].execute end task :importattachment => :environment do ENV['CLASS']='Attachment' ENV['SCOPE']='indexable' ENV['FORCE']='y' ENV['BATCH']='1000' - Rake::Task["elasticsearch:import:model"].invoke + Rake::Task["elasticsearch:import:model"].execute end task :importmemo => :environment do ENV['CLASS']='Memo' ENV['SCOPE']='indexable' ENV['FORCE']='y' ENV['BATCH']='1000' - Rake::Task["elasticsearch:import:model"].invoke + Rake::Task["elasticsearch:import:model"].execute end + + desc "Run all tasks" + task :all => [:importuser,:importproject,:importcourse,:importattachment,:importmemo] end \ No newline at end of file From 1f7bcbed20ef8f63fad191ab166fc8266d74b290 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 2 Feb 2016 21:28:52 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E9=A2=98=E5=BA=93=E6=A0=87=E9=A2=98=E4=B8=AD=E7=9A=84=E6=8D=A2?= =?UTF-8?q?=E8=A1=8C=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_fix.rake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/tasks/import_fix.rake diff --git a/lib/tasks/import_fix.rake b/lib/tasks/import_fix.rake new file mode 100644 index 000000000..e5bd1a796 --- /dev/null +++ b/lib/tasks/import_fix.rake @@ -0,0 +1,14 @@ +namespace :import do + desc "fix import name" + task :fix => :environment do + HomeworkCommon.find_each do |homework| + name = homework.name.sub("\n", " ").sub("\r\n", " ") + if name != homework.name + homework.name = name + homework.save! + end + + end + end + +end