2012-03-04 14:35:15 +01:00
|
|
|
class ProjectObserver < ActiveRecord::Observer
|
2012-11-22 21:34:06 +01:00
|
|
|
def before_save(project)
|
2012-11-22 20:41:16 +01:00
|
|
|
# Move repository if namespace changed
|
2012-11-23 04:39:09 +01:00
|
|
|
if project.namespace_id_changed? and not project.new_record?
|
2012-11-22 20:41:16 +01:00
|
|
|
move_project(project)
|
|
|
|
end
|
2012-03-04 14:35:15 +01:00
|
|
|
end
|
|
|
|
|
2012-11-22 21:34:06 +01:00
|
|
|
def after_save(project)
|
|
|
|
project.update_repository
|
|
|
|
end
|
|
|
|
|
2012-03-04 14:35:15 +01:00
|
|
|
def after_destroy(project)
|
2012-09-11 22:24:53 +02:00
|
|
|
log_info("Project \"#{project.name}\" was removed")
|
|
|
|
|
2012-03-04 14:35:15 +01:00
|
|
|
project.destroy_repository
|
|
|
|
end
|
2012-09-11 22:24:53 +02:00
|
|
|
|
|
|
|
def after_create project
|
|
|
|
log_info("#{project.owner.name} created a new project \"#{project.name}\"")
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def log_info message
|
|
|
|
Gitlab::AppLogger.info message
|
|
|
|
end
|
2012-11-22 20:41:16 +01:00
|
|
|
|
|
|
|
def move_project(project)
|
|
|
|
old_dir = Namespace.find_by_id(project.namespace_id_was).try(:code) || ''
|
|
|
|
new_dir = Namespace.find_by_id(project.namespace_id).try(:code) || ''
|
|
|
|
|
|
|
|
# Create new dir if missing
|
|
|
|
new_dir_path = File.join(Gitlab.config.git_base_path, new_dir)
|
|
|
|
Dir.mkdir(new_dir_path) unless File.exists?(new_dir_path)
|
|
|
|
|
|
|
|
old_path = File.join(Gitlab.config.git_base_path, old_dir, "#{project.path}.git")
|
|
|
|
new_path = File.join(new_dir_path, "#{project.path}.git")
|
|
|
|
|
|
|
|
`mv #{old_path} #{new_path}`
|
2012-11-22 21:34:06 +01:00
|
|
|
|
|
|
|
log_info "Project #{project.name} was moved from #{old_path} to #{new_path}"
|
2012-11-22 20:41:16 +01:00
|
|
|
end
|
2012-03-04 14:35:15 +01:00
|
|
|
end
|