'.Database::escapeDB($lastYear)); } public function getUsersEmail($offset = 0, $limit = 5000, $fromCron = false, $onlyNew = false, $lists = []) { // We filter the users if we need to $filters = []; if ($onlyNew) $filters[] = ' email NOT IN (SELECT email FROM #__acyc_test)'; if ($fromCron) $filters[] = 'user.enabled = 1'; $query = 'SELECT user.email from #__acymailing_subscriber AS user '; // If we selected list we only select users subscribed to it if (!empty($lists)) { SecurityService::arrayToInteger($lists); $query .= 'JOIN #__acymailing_listsub AS user_list ON user.subid = user_list.subid AND user_list.listid IN ('.implode(',', $lists).') AND user_list.status = 1'; } $queryWhere = empty($filters) ? '' : ' WHERE ('.implode(') AND (', $filters).')'; $query .= ' '.$queryWhere.' LIMIT '.$offset.','.$limit; return Database::loadResultArray($query); } public function handleBatchCallback($emailsResults, &$allTests) { // We get the conditions selected $conditionsSelected = $this->config->get('conditions_selected'); if (empty($conditionsSelected)) { DebugService::logMessage('callback_controller.log', 'No conditions set in the configuration for AcyMailing 5 users'); return; } $conditionsSelected = explode(',', $conditionsSelected); if (empty($conditionsSelected)) { DebugService::logMessage('callback_controller.log', 'No conditions set in the configuration for AcyMailing 5 users'); return; } // We get all the emails in the test $emails = array_column($emailsResults, 'email'); foreach ($emails as $key => $email) { $emails[$key] = Database::escapeDB($email); } // We filter with the email in the database try { $emailsInAcymailing5 = Database::loadResultArray('SELECT email FROM #__acymailing_subscriber WHERE email in ('.implode(',', $emails).')'); } catch (\Exception $exception) { DebugService::logMessage('callback_controller.log', 'Error on getting AcyMailing 5 users from results - '.$exception->getMessage()); return; } $apiService = new ApiService(); $blockUserClass = new BlockUserClass(); $blockUserClass->block_action = BlockUserClass::BLOCK_ACTION_BATCH; $blockEmail = []; // We check if we have to block users or not foreach ($emailsInAcymailing5 as $email) { $arrayKey = array_search($email, array_column($emailsResults, 'email')); // We test if the email is ok for the condition $emailOk = $apiService->isEmailAccepted($emailsResults[$arrayKey], $conditionsSelected); if ($emailOk === true) continue; $blockEmail[] = Database::escapeDB($email); // We set the reason why we block the user if (!empty($allTests)) { $blockedEmail = new \stdClass(); $blockedEmail->email = $email; $blockedEmail->block_reason = $emailOk; $blockUserClass->save($blockedEmail); $allTests[$email]['block_reason'] = Database::escapeDB($emailOk); } } // We block all the users if (empty($blockEmail)) return; try { Database::query('UPDATE #__acymailing_subscriber SET enabled = 0 WHERE email IN ('.implode(',', $blockEmail).')'); } catch (\Exception $exception) { DebugService::logMessage('callback_controller.log', 'Error on request to block AcyMailing 5 users - '.$exception->getMessage()); } } }