0); protected $taskTypeCode = TaskTypeCodesCodes::EXPORTTOFILEWHMCS; public function mainDescription() { // $serverTo = new server\Server($this->getParams('toServer')); return 'Export from: '.$this->getParams('fromFile').' to: WHMCS'; } public function main($params) { $cron_import_run_each = manager\GlobalSettingHelper::getSetting(GlobalSettingEnum::CRON_IMPORT_RUN_EACH?:5); if(!$this->isReadyToRun( $cron_import_run_each )) { return true; } if($this->getStatus() == task\TaskStatusEnum::START) { $this->addChild('fetchZonesList', [], $this->task->clientid)->run(); $this->setStatus(task\TaskStatusEnum::IN_PROGRESS); } elseif($this->getStatus() == task\TaskStatusEnum::IN_PROGRESS) { $zones_per_run = manager\GlobalSettingHelper::getSetting(GlobalSettingEnum::CRON_IMPORT_ZONES_PER_RUN); $childs = $this->getXChilds($zones_per_run, 'export', task\TaskStatusEnum::START); if(count($childs) < $zones_per_run) { $childs += $this->getXChilds($zones_per_run - count($childs), 'export'); } foreach($childs as $child) { $child->run(); } $this->setFinishedStatusOnCronRun('export', $zones_per_run); } } public function fetchZonesList($params) { $zoneList = $this->listBulkZones(); foreach($zoneList as $zone) { $this->addResult(array( 'domain' => $zone->zoneName, 'ip' => $zone->ip ? $zone->ip : '', // 'zoneDetails' => $zone->zoneDetails )); } $this->setStatus(task\TaskStatusEnum::FINISHED); } public function export($params) { try { $file = $this->parent->getParams('fromFile'); $zoneParams = $this->getZone($params['domain']); if(empty($zoneParams)) { return; } $fileExporting = ClientFilesManage::getFileForClient($zoneParams->clientid, $file, ClientFilesManage::FROM_FILE_TO_WHMCS); if(!$file || $zoneParams->clientid != $fileExporting->clientid) //incase other user export another { return; } $server = new server\Server($zoneParams->serverid); $moduleTo = $server->getModule(); $moduleTo->setDomain($zoneParams->name); if($moduleTo->isIPRequired()) { $moduleTo->setIP($zoneParams->ip); } if(!$moduleTo->zoneExists()) { $moduleTo->activateZone(); } $this->setStatus(task\TaskStatusEnum::FINISHED); $result = TaskManager::getTaskResultByID($this->getParams('resultid')); $result->data['status'] = 'exported'; $result->save(); } catch(Exception $e) { $result = TaskManager::getTaskResultByID($this->getParams('resultid')); $result->data['status'] = $e->getMessage(); $result->save(); } } private function getZone($zoneName) { return main\models\custom\zone\Repository::factory()->byName($zoneName)->one(); } private function getZoneIfExists() { $repo = new ZoneRepo(); $repo->byName($this->getParams('domain')); $zone = $repo->one(); return $zone; } private function listBulkZones() { $path = 'zonesFilesStorage' . DIRECTORY_SEPARATOR . 'bulkZones'; $zoneList = helpers\ImportExportFileHelper::listBulkExportZones($this->parent->getParams('fromFile'), $path); return $zoneList; } }