2013-03-26 12:11:38 -04:00
|
|
|
class ProjectObserver < BaseObserver
|
2012-11-21 00:54:05 -05:00
|
|
|
def after_create(project)
|
2013-08-15 05:46:52 -04:00
|
|
|
project.update_column(:last_activity_at, project.created_at)
|
|
|
|
|
2013-08-12 11:21:47 -04:00
|
|
|
return true if project.forked?
|
|
|
|
|
|
|
|
if project.import?
|
|
|
|
RepositoryImportWorker.perform_in(5.seconds, project.id)
|
|
|
|
else
|
|
|
|
GitlabShellWorker.perform_async(
|
|
|
|
:add_repository,
|
|
|
|
project.path_with_namespace
|
|
|
|
)
|
|
|
|
|
|
|
|
log_info("#{project.owner.name} created a new project \"#{project.name_with_namespace}\"")
|
|
|
|
end
|
2013-09-10 09:57:34 -04:00
|
|
|
|
|
|
|
if project.wiki_enabled?
|
2013-10-17 02:48:35 -04:00
|
|
|
begin
|
|
|
|
# force the creation of a wiki,
|
|
|
|
GollumWiki.new(project, project.owner).wiki
|
|
|
|
rescue GollumWiki::CouldNotCreateWikiError => ex
|
|
|
|
# Prevent project observer crash
|
|
|
|
# if failed to create wiki
|
|
|
|
nil
|
|
|
|
end
|
2013-09-10 09:57:34 -04:00
|
|
|
end
|
2012-03-04 08:35:15 -05:00
|
|
|
end
|
|
|
|
|
2012-12-20 15:16:51 -05:00
|
|
|
def after_update(project)
|
|
|
|
project.send_move_instructions if project.namespace_id_changed?
|
2013-05-24 17:07:19 -04:00
|
|
|
project.rename_repo if project.path_changed?
|
2012-11-21 00:54:05 -05:00
|
|
|
end
|
|
|
|
|
2013-06-04 11:20:50 -04:00
|
|
|
def before_destroy(project)
|
|
|
|
project.repository.expire_cache unless project.empty_repo?
|
|
|
|
end
|
|
|
|
|
2012-03-04 08:35:15 -05:00
|
|
|
def after_destroy(project)
|
2013-02-11 12:27:26 -05:00
|
|
|
GitlabShellWorker.perform_async(
|
2013-02-04 08:07:56 -05:00
|
|
|
:remove_repository,
|
2013-02-05 05:47:50 -05:00
|
|
|
project.path_with_namespace
|
2013-02-04 08:07:56 -05:00
|
|
|
)
|
2012-09-11 16:24:53 -04:00
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
GitlabShellWorker.perform_async(
|
|
|
|
:remove_repository,
|
|
|
|
project.path_with_namespace + ".wiki"
|
|
|
|
)
|
|
|
|
|
2013-01-28 10:22:45 -05:00
|
|
|
project.satellite.destroy
|
2012-09-11 16:24:53 -04:00
|
|
|
|
2013-02-04 08:07:56 -05:00
|
|
|
log_info("Project \"#{project.name}\" was removed")
|
2012-09-11 16:24:53 -04:00
|
|
|
end
|
2012-03-04 08:35:15 -05:00
|
|
|
end
|