0]; protected $taskTypeCode = TaskTypeCodesCodes::IMPORTTOFILEWHMCS; public function mainDescription() { // $server_from = new server\Server($this->getParams('from')); return 'Import from: WHMCS to: ' . $this->getParams('toFile'); } 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; } LogHelper::addSuccessLog('Cron Importer', 'Cron Importer Started'); if ($this->getStatus() == task\TaskStatusEnum::START) { $this->addChild('fetchZonesList', [], $this->task->clientid)->run(); $this->setStatus(task\TaskStatusEnum::WAITING); } else if ($this->getStatus() == task\TaskStatusEnum::IN_PROGRESS) { $zones_per_run = manager\GlobalSettingHelper::getSetting(GlobalSettingEnum::CRON_IMPORT_ZONES_PER_RUN); $childs = $this->getXChilds($zones_per_run, 'import', task\TaskStatusEnum::START); if (count($childs) < $zones_per_run) { $childs += $this->getXChilds($zones_per_run - count($childs), 'import'); } foreach ($childs as $child) { $child->run(); } $this->setFinishedStatusOnCronRun('import', $zones_per_run); } LogHelper::addSuccessLog('Cron Importer', 'End Of Cron Importer Run'); } public function fetchZonesList($params) { if ($this->isInCliMode()) { LogHelper::addSuccessLog('Cron Importer', 'Fetching Zones List For Server Id: ' . $this->parent->getParams('from') . ' Started.'); } $zones = ZoneRepository::factory()->byClientID($this->task->clientid); foreach ($zones->get() as $zone) { $arZone = $zone->toArray()['Zone']; unset($arZone['status']); $this->addResult($arZone); } $this->setStatus(task\TaskStatusEnum::FINISHED); if ($this->isInCliMode()) { LogHelper::addSuccessLog('Cron Importer', 'Fetching Zones List From WHMCS Completed.'); } } public function import($params) { try { $server_from = new server\Server($this->getParams('serverid')); $module_from = $server_from->getModule(); $module_from->setDomain($params['name']); $zone = new Zone(); $zone->clientid = $this->getParams('clientid'); $zone->type = $this->getParams('type'); $zone->relid = $this->getParams('relid'); $zone->name = $this->getParams('name'); $zone->ip = $this->getParams('ip'); $zone->connectedWithType = $this->getParams('connectedWithType'); $zone->connectedWithRelid = $this->getParams('connectedWithRelid'); $zone->serverid = $this->getParams('serverid'); $zone->created_at = $this->getParams('created_at'); $zone->updated_at = $this->getParams('updated_at'); $zone->status = 1; // TODO status if (!$module_from->zoneExists()) { $zone->status = 0; } $file = $this->parent->getParams('toFile'); $createdBy = $this->parent->getParams('createdBy'); ClientFilesManage::saveIfNotExists($file, $zone->clientid, ClientFilesManage::BACKUP, $createdBy); helpers\ImportExportFileHelper::bulkImportZoneToFile($zone, 'zonesFilesStorage' . DIRECTORY_SEPARATOR . 'bulkZones', $file); $this->setStatus(task\TaskStatusEnum::FINISHED); $result = TaskManager::getTaskResultByID($this->getParams('resultid')); $result->data['status'] = 'imported'; $result->save(); LogHelper::addSuccessLogUsingZone('Cron Importer - Import Zone', 'Zone Imported', $zone); } catch (Exception $exc) { $result = TaskManager::getTaskResultByID($this->getParams('resultid')); $result->data['status'] = $exc->getMessage(); $result->save(); LogHelper::addFailLog('Cron Importer - Import Failed', $exc->getMessage()); } } }