<commit_before><?php

/**
 * @package         Billing
 * @copyright       Copyright (C) 2012-2015 S.D.O.C. LTD. All rights reserved.
 * @license         GNU Affero General Public License Version 3; see LICENSE.txt
 */

/**
 * Holds the logic for updating balances using the secret card number.
 *
 * @author tom
 */
class Billrun_ActionManagers_Balances_Updaters_Secret extends Billrun_ActionManagers_Balances_Updaters_ChargingPlan {
	
	/**
	 * Update the balances, based on the plans table
	 * @param type $query - Query to find row to update.
	 * @param type $recordToSet - Values to update.
	 * @param type $subscriberId - Id for the subscriber to update.
	 * @return The updated record, false if failed.
	 */
	public function update($query, $recordToSet, $subscriberId) {
		// Get the record.
		if (isset($query['secret'])) {
			$query['secret'] = hash('sha512',$query['secret']);
		} else {
			$error = "No secret input";
			$this->reportError($error, Zend_Log::ALERT);
			return false;
		}
		$dateQuery = array(
			'to' => array(
				'$gt' => new MongoDate()
			)
		);
		$finalQuery = array_merge($dateQuery, $query);
		$finalQuery['status'] = array('$eq' => 'Active');
		$cardsColl = Billrun_Factory::db()->cardsCollection();
		$cardRecord = $cardsColl->query($finalQuery)->cursor()->current();
		if($cardRecord->isEmpty()) {
			$error = "Invalid card received, might be cancelled";
			$this->reportError($error, Zend_Log::NOTICE);
			return false;
		}
		
		// Build the plan query from the card plan field.
		$planQuery = array('charging_plan_name' => $cardRecord['charging_plan_name']);
		
		$ret = parent::update($planQuery, $recordToSet, $subscriberId);
		if ($ret !== FALSE) {
			$this->signalCardAsUsed($cardRecord, $subscriberId);
		}
		return $ret;<commit_msg>Using the get date bound query function of the Billrun Util class<commit_after><?php

/**
 * @package         Billing
 * @copyright       Copyright (C) 2012-2015 S.D.O.C. LTD. All rights reserved.
 * @license         GNU Affero General Public License Version 3; see LICENSE.txt
 */

/**
 * Holds the logic for updating balances using the secret card number.
 *
 * @author tom
 */
class Billrun_ActionManagers_Balances_Updaters_Secret extends Billrun_ActionManagers_Balances_Updaters_ChargingPlan {
	
	/**
	 * Get the card record according to the received query
	 * @param array $query - Received query to get the record by.
	 * @return boolean
	 */
	protected function getCardRecord($query) {
		if (isset($query['secret'])) {
			$query['secret'] = hash('sha512',$query['secret']);
		} else {
			$error = "No secret input";
			$this->reportError($error, Zend_Log::ALERT);
			return false;
		}
		$dateQuery = Billrun_Util::getDateBoundQuery();
		$finalQuery = array_merge($dateQuery, $query);
		$finalQuery['status'] = array('$eq' => 'Active');
		$cardsColl = Billrun_Factory::db()->cardsCollection();
		return $cardsColl->query($finalQuery)->cursor()->current();
	}
	
	/**
	 * Update the balances, based on the plans table
	 * @param type $query - Query to find row to update.
	 * @param type $recordToSet - Values to update.
	 * @param type $subscriberId - Id for the subscriber to update.
	 * @return The updated record, false if failed.
	 */
	public function update($query, $recordToSet, $subscriberId) {
		// Get the record.
		$cardRecord = $this->getCardRecord($query);
		
		if($cardRecord === false) {
			return false;
		}
		
		if($cardRecord->isEmpty()) {
			$error = "Invalid card received, might be cancelled";
			$this->reportError($error, Zend_Log::NOTICE);
			return false;
		}
		
		// Build the plan query from the card plan field.
		$planQuery = array('charging_plan_name' => $cardRecord['charging_plan_name']);
		
		$ret = parent::update($planQuery, $recordToSet, $subscriberId);
		if ($ret !== FALSE) {
			$this->signalCardAsUsed($cardRecord, $subscriberId);
		}
		return $ret;
{'fraction_non_alphanumeric': 0.1430049133695371, 'fraction_numerical': 0.0062063615205585725, 'mean_word_length': 3.9399744572158366, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2889845', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1173, 'n_words': 337}