setBatchAsFailed($testId); $this->sendNextBatch(); return; } $results = $result['results']; // Prepare the query to insert the test $insertQuery = 'INSERT INTO #__acyc_test (`email`, `date`, `raw_result`, `test_result`, `disposable`, `free`, `accept_all`, `role_email`, `current_step`, `block_reason`) VALUES '; $allTests = []; $dateTimeNow = new \DateTime('NOW'); $dateTimeNow->setTimezone(new \DateTimeZone('UTC')); $dateNow = $dateTimeNow->format('Y-m-d H:i:s'); foreach ($results as $oneResult) { $allTests[$oneResult['email']] = [ 'email' => Database::escapeDB($oneResult['email']), 'date' => Database::escapeDB($dateNow), 'raw_result' => Database::escapeDB(json_encode($oneResult)), 'test_result' => Database::escapeDB($oneResult['email_exists']), 'disposable' => $oneResult['disposable'] ? 1 : 0, 'free' => $oneResult['free_mailbox'] ? 1 : 0, 'accept_all' => $oneResult['accept_all'] ? 1 : 0, 'role_email' => $oneResult['role_based_address'] ? 1 : 0, 'current_step' => $testClass::STEP['finished'], 'block_reason' => 'NULL', ]; } // We get the selected table to check $tablesSelected = $this->config->get('tables_selected'); if (empty($tablesSelected)) { DebugService::logMessage('callback_controller.log', 'No table selected in the configuration'); } else { $tablesSelected = explode(',', $tablesSelected); if (in_array('acymailing', $tablesSelected)) { $acymailingUserClass = new AcymailingUserClass(); $acymailingUserClass->handleBatchCallback($results, $allTests); } if (in_array('cms', $tablesSelected)) { $cmsUserClass = new CmsUserClass(); $cmsUserClass->handleBatchCallback($results, $allTests); } } foreach ($allTests as $email => $databaseValues) { $allTests[$email] = implode(',', array_values($databaseValues)); } $insertQuery .= '('.implode('),(', array_values($allTests)).')'; $insertQuery .= 'ON DUPLICATE KEY UPDATE email=VALUES(email), `date`=VALUES(`date`), raw_result=VALUES(raw_result), test_result=VALUES(test_result), disposable=VALUES(disposable), free=VALUES(free), accept_all=VALUES(accept_all), role_email=VALUES(role_email), current_step=VALUES(current_step), block_reason=VALUES(block_reason)'; try { // We execute the query to store the email tested Database::query($insertQuery); } catch (\Exception $exception) { DebugService::logMessage('callback_controller.log', 'Error on updating the table test - '.$exception->getMessage()); } $this->sendNextBatch(); } private function sendNextBatch() { $cronService = new CronService(); $cronService->sendNextBatchToAPI(); } }