From a7f3672b75dff07688c5e4196ad1835bb89ff690 Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Tue, 17 Jun 2014 21:53:26 +0300
Subject: [PATCH] Remove project observer

---
 app/observers/project_observer.rb        | 30 ------------------------
 app/services/projects/create_service.rb  |  2 ++
 app/services/projects/destroy_service.rb | 25 ++++++++++++++++++++
 app/services/projects/update_service.rb  | 10 +++++++-
 config/application.rb                    |  1 -
 5 files changed, 36 insertions(+), 32 deletions(-)
 delete mode 100644 app/observers/project_observer.rb
 create mode 100644 app/services/projects/destroy_service.rb

diff --git a/app/observers/project_observer.rb b/app/observers/project_observer.rb
deleted file mode 100644
index ad41ddad58f..00000000000
--- a/app/observers/project_observer.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-class ProjectObserver < BaseObserver
-  def after_create(project)
-    log_info("#{project.owner.name} created a new project \"#{project.name_with_namespace}\"")
-  end
-
-  def after_update(project)
-    project.send_move_instructions if project.namespace_id_changed?
-    project.rename_repo if project.path_changed?
-  end
-
-  def before_destroy(project)
-    project.repository.expire_cache unless project.empty_repo?
-  end
-
-  def after_destroy(project)
-    GitlabShellWorker.perform_async(
-      :remove_repository,
-      project.path_with_namespace
-    )
-
-    GitlabShellWorker.perform_async(
-      :remove_repository,
-      project.path_with_namespace + ".wiki"
-    )
-
-    project.satellite.destroy
-
-    log_info("Project \"#{project.name}\" was removed")
-  end
-end
diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb
index 3d2b9bf4875..25c9f0e53b5 100644
--- a/app/services/projects/create_service.rb
+++ b/app/services/projects/create_service.rb
@@ -51,6 +51,8 @@ module Projects
       @project.creator = current_user
 
       if @project.save
+        log_info("#{@project.owner.name} created a new project \"#{@project.name_with_namespace}\"")
+
         unless @project.group
           @project.users_projects.create(
             project_access: UsersProject::MASTER,
diff --git a/app/services/projects/destroy_service.rb b/app/services/projects/destroy_service.rb
new file mode 100644
index 00000000000..8c265199217
--- /dev/null
+++ b/app/services/projects/destroy_service.rb
@@ -0,0 +1,25 @@
+module Projects
+  class UpdateService < BaseService
+    def execute(role = :default)
+      return false unless can?(current_user, :remove_project, project)
+
+      project.repository.expire_cache unless project.empty_repo?
+
+      if project.destroy
+        GitlabShellWorker.perform_async(
+          :remove_repository,
+          project.path_with_namespace
+        )
+
+        GitlabShellWorker.perform_async(
+          :remove_repository,
+          project.path_with_namespace + ".wiki"
+        )
+
+        project.satellite.destroy
+
+        log_info("Project \"#{project.name}\" was removed")
+      end
+    end
+  end
+end
diff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rb
index d9d371da5c4..551a3653cad 100644
--- a/app/services/projects/update_service.rb
+++ b/app/services/projects/update_service.rb
@@ -13,7 +13,15 @@ module Projects
         project.change_head(new_branch)
       end
 
-      project.update_attributes(params[:project], as: role)
+      if project.update_attributes(params[:project], as: role)
+        if project.previous_changes.include?('namespace_id')
+          project.send_move_instructions
+        end
+
+        if project.previous_changes.include?('path')
+          project.rename_repo
+        end
+      end
     end
   end
 end
diff --git a/config/application.rb b/config/application.rb
index 1283c8b78ef..d0ed85d7cf6 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -20,7 +20,6 @@ module Gitlab
 
     # Activate observers that should always be running.
     config.active_record.observers = :note_observer,
-                                     :project_observer,
                                      :system_hook_observer,
                                      :user_observer,
                                      :users_project_observer
-- 
GitLab