Import.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Artur
  5. * Date: 24.09.2018
  6. * Time: 17:20
  7. */
  8. namespace MGModule\DNSManager2\mgLibs\custom\helpers\datatable;
  9. use MGModule\DNSManager2\mgLibs\custom\helpers\IdnaHelper;
  10. use MGModule\DNSManager2\models\custom\task\result\Repository;
  11. use MGModule\DNSManager2\helpers\WHMCS\Service;
  12. use MGModule\DNSManager2\helpers\WHMCS\Client;
  13. use MGModule\DNSManager2\helpers\WHMCS\Domain;
  14. use MGModule\DNSManager2\models\custom\globalsetting\GlobalSettingEnum;
  15. use MGModule\DNSManager2\mgLibs\custom\manager\GlobalSettingHelper;
  16. class Import
  17. {
  18. CONST DOMAINS = 'domains';
  19. CONST SERVICES = 'services';
  20. CONST CLIENTS = 'clients';
  21. public function getNeeded($zones)
  22. {
  23. $activeServices = GlobalSettingHelper::getSetting(GlobalSettingEnum::IMPORT_ACTIVE_SERVICES);
  24. $activeUsers = GlobalSettingHelper::getSetting(GlobalSettingEnum::IMPORT_ACTIVE_USERS);
  25. if (!$activeUsers && !$activeServices)
  26. {
  27. return $zones;
  28. }
  29. $data = $this->getZonesData();
  30. foreach ($zones as $domain => $ip)
  31. {
  32. $domainInLowerCases = IdnaHelper::idnaDecode(strtolower($domain));
  33. if ($activeServices && $this->isToRemoveByServiceStatus($data, $domainInLowerCases))
  34. {
  35. unset($zones[$domain]);
  36. continue;
  37. }
  38. if ($activeUsers && $this->isToRemoveByClientStatus($data, $domainInLowerCases))
  39. {
  40. unset($zones[$domain]);
  41. continue;
  42. }
  43. }
  44. return $zones;
  45. }
  46. public function isToRemoveByClientStatus($data, $zone)
  47. {
  48. $domains = $data[SELF::DOMAINS][$zone];
  49. if (isset($domains))
  50. {
  51. $clientId = $domains['userid'];
  52. return $data[SELF::CLIENTS][$clientId]['status'] != Client::STATUS_ACTIVE ? true : false;
  53. }
  54. $services = $data[SELF::SERVICES][$zone];
  55. if (isset($services))
  56. {
  57. $clientId = $services['userid'];
  58. return $data[SELF::CLIENTS][$clientId]['status'] != Client::STATUS_ACTIVE ? true : false;
  59. }
  60. return true;
  61. }
  62. public function isToRemoveByServiceStatus($data, $zone)
  63. {
  64. if (!isset($data[SELF::SERVICES][$zone]) && !isset($data[SELF::DOMAINS][$zone]))
  65. {
  66. return true;
  67. }
  68. if ($data[SELF::SERVICES][$zone]['domainstatus'] != Service::ACTIVE && $data[SELF::DOMAINS][$zone]['status'] != Service::ACTIVE)
  69. {
  70. return true;
  71. }
  72. return false;
  73. }
  74. public function getZonesData()
  75. {
  76. return [
  77. SELF::DOMAINS => array_change_key_case(Domain::getDomainsAsDomainKey(), CASE_LOWER),
  78. SELF::SERVICES => array_change_key_case(Service::getServicesAsDomainKey(), CASE_LOWER),
  79. SELF::CLIENTS => Client::getClientsAsIdKey()
  80. ];
  81. }
  82. }