/** * Updates some details of a ConnectTxt account * based on a user's input rather than a remote call * @param int $accountId ConnectTxt account ID * @param string $description ConnectTxt account description * @param object $decodedJson JSON request * @return string JSON response * @throws MoodletxtAJAXException * @version 2013061701 * @since 2012100801 */ private function updateAccountFromUser($accountId, $description, $newPassword) { $txttoolsAccount = $this->accountDAO->getTxttoolsAccountById($accountId); // Account must exist within system if (!is_object($txttoolsAccount)) { throw new MoodletxtAJAXException(get_string('errorinvalidaccountid', 'block_moodletxt'), MoodletxtAJAXException::$ERROR_CODE_BAD_ACCOUNT_ID, null, false, $accountId); } $txttoolsAccount->setDescription($description); // Set new encrypted password on object and attempt // to connect to ConnectTxt with it // (There's a method to check account validity but // we might as well update info while we're at it.) if ($newPassword != '') { $encrypter = new MoodletxtEncryption(); $key = get_config('moodletxt', 'EK'); $txttoolsAccount->setEncryptedPassword($encrypter->encrypt($key, $newPassword, 20)); // Update from ConnectTxt server try { $this->connector->updateAccountInfo($txttoolsAccount); } catch (MoodletxtRemoteProcessingException $ex) { throw new MoodletxtAJAXException(get_string('errorconn' . $ex->getCode(), 'block_moodletxt'), $ex->getCode(), null, true, $txttoolsAccount->getId()); } catch (Exception $ex) { throw new MoodletxtAJAXException(get_string('errorconndefault', 'block_moodletxt'), $ex->getCode(), null, true, $txttoolsAccount->getId()); } } $this->accountDAO->saveTxttoolsAccount($txttoolsAccount); return $this->buildResponse($txttoolsAccount); }
/** * @return void * @version 2015062901 * @since 2015062901 */ public function pollForBlacklistedRecipients() { $usAccounts = $this->accountDAO->getAccountByLocation(TxttoolsAccount::$US_LOCATION); foreach ($usAccounts as $account) { try { $phoneNumbers = $this->getAllPhoneNumbers(); $blacklistedNumbers = $this->xmlController->getOptOutStatusUpdates($phoneNumbers, $account); $this->syncDbWithResponse($blacklistedNumbers, $account); } catch (Exception $ex) { // XML request might throw exceptions in case of some errors // Ignored file_put_contents('C:\\moodle.log', time() . ': cron blacklist poll failed for account (' . $account->getUsername() . '@' . $account->getUrl() . ') -> ' . $ex->getMessage(), FILE_APPEND); } } }