Synchronisierung
syncDomains()
Diese Funktion wird für die „Domain-Synchronisierung“ verwendet. Dabei handelt es sich um eine Funktion, die einmal täglich in der hostware-Umgebung ausgeführt wird, um die aktuellen Domaineinstellungen abzurufen und die hostware-Datenbank auf dem neuesten Stand zu halten. In der Antwort kannst Du sehen, welche Daten aktualisiert werden.
Dies sollte außerdem die Domain-Handle-Daten für alle 4 Handles zurückgeben. Wenn hostware keine inside the hat
Parameter
Diese Funktion erhält als Parameter eine Sammlung von Domains, die überprüft werden müssen. Du kannst MEHR Domains zurückgeben, aber hostware überprüft und aktualisiert nur die Domains, die in der Eingabesammlung bereitgestellt werden.
Typ | Name | Beschreibung |
|---|---|---|
Collection | $domains | Sammlung von Domain Models, die abgefragt werden sollen |
Antwort
Array der Klasse DomainSyncResponse(). Der Array-Schlüssel muss die Domain-ID sein.
Wenn eine angeforderte Domain in der Antwort nicht verfügbar ist, nimmt hostware an, dass sie übertragen wurde, und löscht sie in der hostware-Datenbank.
Typ | Name | Beschreibung |
|---|---|---|
DomainSyncStatusEnum | $domainStatus | Der Status der Domain (ACTIVE, INACTIVE, TRANSFERRED_AWAY) |
Bool | $autoRenewActive | Der Status der automatischen Verlängerung |
Carbon oder Null | $expiryDate | Das Ablaufdatum der Domain |
Carbon oder Null | $registrationDate | Das Erstellungsdatum der Domain |
Bool | $transferLockActive | Der Status der Transfersperre |
Bool | $privacyActive | Der Status des Datenschutzes |
Beispielcode
public function syncDomains(Collection $domains): array {
$responseData = [];
$xml = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<request>
{$this->getXmlHeader()}
<transaction>
<report>
<group>domain</group>
<data_type>csv</data_type>
</report>
</transaction>
</request>
XML;
$response = $this->getClient()->callreportRaw($xml, $this->config['sandbox']);
$explode = explode("\n", $response->result->detail->report->domain->data);
foreach ($explode as $domainItem) {
$domainItemExploded = explode(';', $domainItem);
if ($domainItemExploded[0] == 'domain') continue;
if ($domainItemExploded[0] == '') continue;
$allDomainsStructured[strtolower($domainItemExploded[0])] = $domainItemExploded;
}
/**
* Get all domain handles
*/
$xml = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<request>
{$this->getXmlHeader()}
<transaction>
<report>
<group>contact</group>
<data_type>csv</data_type>
</report>
</transaction>
</request>
XML;
$explodedresponse = Cache::remember("hw-CPS-contactCsv", 60 * 5, function () use ($xml) {
$response = $this->getClient()->callreportRaw($xml, $this->config['sandbox']);
return explode("\n", $response->result->detail->report->contact->data);
});
$contacts = collect([]);
foreach ($explodedresponse as $lineItem) {
$lineItem = explode(";", $lineItem);
if($lineItem[0] === "cid") continue;
if(count($lineItem) !== 16) continue;
// dd($lineItem);
$contacts->add($this->_getContactFromHandle($lineItem));
}
$contacts = $contacts->keyBy(function ($item) {
return (string)$item->getAttributes()['id'];
});
foreach ($domains as $domain) {
$resItem = $allDomainsStructured[strtolower($domain->fqdn)] ?? $allDomainsStructured[strtolower($domain->punycode_fqdn)] ?? null;
if ($resItem === null) {
$responseData[$domain->id] = new DomainSyncResponse(DomainSyncStatusEnum::INACTIVE);
continue;
}
$responseData[$domain->id] = new DomainSyncResponse(
DomainSyncStatusEnum::ACTIVE,
$resItem[16] === "active",
Carbon::parse($resItem[10]),
Carbon::parse($resItem[7]),
$resItem[14] === "active",
false,
$contacts->get($resItem[20]),
$contacts->get($resItem[21]),
$contacts->get($resItem[22]),
$contacts->get($resItem[23]),
);
}
// dd($responseData);
return $responseData;
}
private function _getContactFromHandle(array $reportLine) {
$type = ContactTypeEnum::PERSON;
if ($reportLine[4] === "organisation") {
$type = ContactTypeEnum::ORG;
} elseif ($reportLine[4] === "role") {
$type = ContactTypeEnum::ROLE;
}
$street = $reportLine[8];
$streetNumber = null;
if (preg_match('/^(.+?)\s+(\d+[\w\-\/]*)$/u', $street, $matches)) {
$street = $matches[1];
$streetNumber = $matches[2];
}
if($reportLine[7] === "-" || $type === ContactTypeEnum::PERSON) {
$reportLine[7] = null;
}
// if($reportLine[2] === "EVMI7") {
// dd($reportLine);
// }
return new DomainContact([
"id" => $reportLine[2],
"type" => $type,
"sex" => ContactSexEnum::MALE,
"first_name" => $reportLine[5],
"last_name" => $reportLine[6],
"organisation" => $reportLine[7],
"street" => $street,
"street_number" => $streetNumber,
"zipcode" => $reportLine[9],
"city" => $reportLine[10],
"state" => $reportLine[11],
"country" => $reportLine[12],
"telephone" => $reportLine[13],
"telefax" => $reportLine[14],
"email" => $reportLine[15]
]);
}Testen
Diese Funktion wird täglich im Cronjob / im Hintergrund ausgeführt. Jede Domain hat in der Datenbank eine Spalte "synced=true/false". Jeden Tag wird dieser Status auf false gesetzt, damit die Domain erneut synchronisiert wird. Nach der Synchronisierung wird die Spalte auf true gesetzt.
Setze die Spalte für die Domain-Synchronisierung zurück:
php artisan hw:resetDomainSyncFühre die Domain-Synchronisierung für eine bestimmte Domain aus. Du kannst den Domain-Parameter auch entfernen, damit die Synchronisierung für alle Domains in Deinem Portfolio ausgeführt wird.
php artisan hw:initiateDomainSync --sync YOUR_DOMAIN.de