1313
1414class SaveDns extends Action
1515{
16+ private ZoneServiceEnum $ serviceType ;
17+
1618 public function __invoke (Request $ request ): array
1719 {
18- if ($ request ->params ['dnsmanagement ' ] === true && App::registrarConfig ()->hasDnsSupport ()) {
20+ if ($ request ->params ['dnsmanagement ' ] === true && App::registrarConfig ()->hasDnsSupport () === true ) {
21+ $ this ->serviceType = ZoneServiceEnum::from (App::registrarConfig ()->get ('dns_support ' ));
1922 $ domain = $ this ->domainInfo ($ request );
2023 $ zone = App::client ()->domains ->get ($ domain ->domainName )->zone ;
2124 return $ this ->processUpdate ($ zone , $ domain , $ _POST ['soa ' ], $ _POST ['dns-items ' ]);
@@ -50,7 +53,7 @@ private function processUpdate(?Zone $zone, DomainDetails $domain, array $soaDat
5053 $ dnsRecords [$ k ]['name ' ] = $ domain ->domainName ;
5154 }
5255
53- if (!in_array ('ttl ' , $ data )) {
56+ if (!array_key_exists ('ttl ' , $ data )) {
5457 $ dnsRecords [$ k ]['ttl ' ] = 3600 ;
5558 }
5659 }
@@ -67,28 +70,22 @@ private function processUpdate(?Zone $zone, DomainDetails $domain, array $soaDat
6770 'ttl ' => (int )$ soaData ['ttl ' ],
6871 'records ' => DomainZoneRecordCollection::fromArray ($ dnsRecords )
6972 ];
70-
7173 if (!$ zone ) {
7274 App::client ()->dnszones ->create (
7375 name: $ domain ->domainName ,
74- service: App::registrarConfig ()->get ('dns_support ' ) === 'basic ' ? ZoneServiceEnum::BASIC
75- : ZoneServiceEnum::PREMIUM ,
76+ service: $ this ->serviceType ,
7677 hostMaster: $ soaData ['hostmaster ' ],
7778 refresh: (int )$ soaData ['refresh ' ],
7879 retry: (int )$ soaData ['retry ' ],
7980 expire: (int )$ soaData ['expire ' ],
8081 records: DomainZoneRecordCollection::fromArray ($ dnsRecords ),
8182 );
82-
8383 // Enable the just created zone, and thus, enable it to the domain
8484 App::client ()->domains ->update (
8585 domainName: $ domain ->domainName ,
8686 zone: Zone::fromArray (
8787 [
88- 'service ' => App::registrarConfig ()->get (
89- 'dns_support '
90- ) === 'basic ' ? ZoneServiceEnum::BASIC ->value : ZoneServiceEnum::PREMIUM ->value ,
91- 'managed ' => true
88+ 'service ' => $ this ->serviceType ->value ,
9289 ]
9390 )
9491 );
0 commit comments