From d405c8fc605256c1273cca1e30dfa1196459d625 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 24 Nov 2012 12:25:04 +0200 Subject: Create namespace on username init. Raise exception if project cannot be moved --- lib/gitlab/project_mover.rb | 6 +++++- lib/tasks/gitlab/activate_namespaces.rake | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/project_mover.rb b/lib/gitlab/project_mover.rb index 9dc3e019faa..c9f5e822f6a 100644 --- a/lib/gitlab/project_mover.rb +++ b/lib/gitlab/project_mover.rb @@ -3,6 +3,8 @@ # Used for moving project repositories from one subdir to another module Gitlab class ProjectMover + class ProjectMoveError < StandardError; end + attr_reader :project, :old_dir, :new_dir def initialize(project, old_dir, new_dir) @@ -23,7 +25,9 @@ module Gitlab log_info "Project #{project.name} was moved from #{old_path} to #{new_path}" true else - log_info "Error! Project #{project.name} cannot be moved from #{old_path} to #{new_path}" + message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}" + log_info "Error! #{message}" + raise ProjectMoveError.new(message) false end end diff --git a/lib/tasks/gitlab/activate_namespaces.rake b/lib/tasks/gitlab/activate_namespaces.rake index 0c7c3e7160e..bfab46f66a4 100644 --- a/lib/tasks/gitlab/activate_namespaces.rake +++ b/lib/tasks/gitlab/activate_namespaces.rake @@ -2,11 +2,15 @@ namespace :gitlab do desc "GITLAB | Enable usernames and namespaces for user projects" task activate_namespaces: :environment do User.find_each(batch_size: 500) do |user| + next if user.namespace + User.transaction do username = user.email.match(/^[^@]*/)[0] - user.update_attributes!(username: username) - user.create_namespace!(code: username, name: user.name) - print '.'.green + if user.update_attributes!(username: username) + print '.'.green + else + print 'F'.red + end end end end -- cgit v1.2.1