implement websites.models.Website.delete

- implement delete method and let it call these tasks:
  - disable_web_vhost
  - delete_web_vhost_config
  - delete_file_website_hierarchy
  - delete_web_php_fpm_pool_config if this was the last website of the
    user
This commit is contained in:
Jan Dittberner 2015-01-27 18:42:07 +01:00
parent be1e7bd27f
commit 1f485e6b29

View file

@ -13,10 +13,14 @@ from osusers.models import User as OsUser
from fileservertasks.tasks import (
create_file_website_hierarchy,
delete_file_website_hierarchy,
)
from webtasks.tasks import (
create_web_php_fpm_pool_config,
create_web_vhost_config,
delete_web_php_fpm_pool_config,
delete_web_vhost_config,
disable_web_vhost,
enable_web_vhost,
)
@ -61,3 +65,15 @@ class Website(models.Model):
self.osuser.username, fqdn, self.wildcard).get()
enable_web_vhost.delay(fqdn).get()
return super(Website, self).save(*args, **kwargs)
@transaction.atomic
def delete(self, *args, **kwargs):
fqdn = self.get_fqdn()
osuser = self.osuser
disable_web_vhost.delay(fqdn).get()
delete_web_vhost_config.delay(fqdn).get()
delete_file_website_hierarchy.delay(osuser.username, fqdn).get()
deleted = super(Website, self).delete(*args, **kwargs)
if not Website.objects.filter(osuser=osuser):
delete_web_php_fpm_pool_config.delay(osuser.username).get()
return deleted