An application can add DNS records to customer domains. Suppose, you need to add a TXT record in all customer domains, and it should be done during provisioning of the application tenant (management context) resource. The following procedure directs you through the relevant steps.
Get permissions to view and edit domains by establishing the impersonated connection to the APS controller:
$apsc = \APS\Request::getController();
$apsc2 = $apsc->impersonate($this);
Retrieve all domains from the APS controller:
$allDomains = $apsc2->getResources('implementing(http://aps-standard.org/types/dns/domain/1.0)');
Initiate a DNS record object by its APS type. In our example, it must be the DNS TXT record:
$dNSRecord = \APS\TypeLibrary::newResourceByTypeId('http://parallels.com/aps/types/pa/dns/record/txt/1.0');
For each domain, fill in the DNS record properties and call the linkResource method to create a new record in the domain zone.
Note
Refer to linkResource for more information.
Full code example:
<?php
...
$apsc = \APS\Request::getController();
$apsc2 = $apsc->impersonate($this);
$allDomains = $apsc2->getResources('implementing(http://aps-standard.org/types/dns/domain/1.0)');
$dNSRecord = \APS\TypeLibrary::newResourceByTypeId('http://parallels.com/aps/types/pa/dns/record/txt/1.0');
foreach ($allDomains as $dm) {
$dNSRecord->source = $dm->name .'.';
$dNSRecord->txt_data = 'sampledata';
$dNSRecord->TTL = 3600;
$dNSRecord->RRState = 'active';
$dNSRecord->recordId = 0;
$apsc2->linkResource($dm, 'records', $dNSRecord);
}