ZoneRemover.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom\manager;
  3. use \MGModule\DNSManager2\mgLibs\custom\reverse\ReverseDNS;
  4. use MGModule\DNSManager2\models\custom\globalsetting\GlobalSettingEnum;
  5. use \MGModule\DNSManager2\models\custom\reverse\Repository;
  6. use \MGModule\DNSManager2\models\custom\zone\Zone;
  7. class ZoneRemover
  8. {
  9. /** @var Zone */
  10. private $zone;
  11. /**
  12. *
  13. * @param mixed $zone nazwa zona lub model z bazy
  14. */
  15. public function __construct($zone)
  16. {
  17. if(!($zone instanceof Zone)) {
  18. $zone = new Zone($zone);
  19. }
  20. $this->zone = $zone;
  21. }
  22. private function removePTRs()
  23. {
  24. foreach(Repository::factory()->byZone($this->zone)->get() as $reverse)
  25. {
  26. $helper = new ReverseDNS($reverse);
  27. $zone = new Zone();
  28. $zone->name = $reverse->name;
  29. $zone->serverid = $reverse->serverid;
  30. $module = $zone->getModule();
  31. $helper->remove();
  32. if($module->zoneExists() && count($module->getRDNSRecord($reverse->ip)) <= 1 && GlobalSettingHelper::getSetting(GlobalSettingEnum::DO_NOT_REMOVE_EMPTY_PTR_ZONES) !== 'on' )
  33. {
  34. $module->terminateZone();
  35. }
  36. }
  37. }
  38. /**
  39. * Usuwanie zona oraz jego rDNS z serwera i bazy
  40. */
  41. public function remove() {
  42. $this->removePTRs();
  43. $module = $this->zone->getModule();
  44. if ($module->zoneExists())
  45. $module->terminateZone();
  46. $this->zone->delete();
  47. $clientID = explode("|", $this->zone->clientid)[0];
  48. // LogHelper::addSuccessLog('Remove Zone', '', $this->zone->name, $clientID);
  49. EmailNotificationHelper::sendClientNotification(DefaultNotifications::GENERAL_ZONE_REMOVED_NOTIFICATION, $clientID, $this->item->type, $this->item->relid, array(
  50. 'zone_name' => $this->zone->name,
  51. ));
  52. }
  53. /**
  54. * Jednolinijkowe usuwanie zona
  55. * @param mixed $zone nazwa zona lub model z bazy
  56. */
  57. public static function removeZone($zone) {
  58. $remover = new self($zone);
  59. $remover->remove();
  60. }
  61. }