<commit_before><?php

/**
 * @package         Billing
 * @copyright       Copyright (C) 2012-2016 BillRun Technologies Ltd. All rights reserved.
 * @license         GNU Affero General Public License Version 3; see LICENSE.txt
 */

/**
 * Receive action controller class
 *
 * @package     Controllers
 * @subpackage  Action
 * @since       1.0
 */
class ReceiveAction extends Action_Base {
	use Billrun_Traits_TypeAll;
	
	/**
	 * method to execute the receive process
	 * it's called automatically by the cli main controller
	 */
	public function execute() {
		if (!$this->isOn()) {
			$this->getController()->addOutput(ucfirst($this->getRequest()->action) . " is off");
			return;
		}

		$possibleOptions = array(
			'type' => false,
			'path' => true,
			'workspace' => true,
		);

		if (($options = $this->_controller->getInstanceOptions($possibleOptions)) === FALSE) {
			return;
		}
		$extraParams = $this->_controller->getParameters();
		if (!empty($extraParams)) {
			$options = array_merge($extraParams, $options);
		}

		// If not type all process normaly.
		if(!$this->handleTypeAll($options)) {
			$connectionsPerReceiverType = array();
			if (isset($options['payment_gateway'])) {
				$paymentGatewayReceiver = Billrun_Receiver_NonCDRs_PaymentGateway::getReceiverSettings($options);
				$pgConnections = isset($paymentGatewayReceiver['connections']) ? $paymentGatewayReceiver['connections'] : [];
				foreach ($pgConnections as $pgConnection) {
					$pgOptions = $options;
					$pgOptions['file_type'] = $options['type'];
					$pgOptions['receiver']['connection'] = $pgConnection;
					$pgOptions['receiver']['receiver_type'] = 'PaymentGateway_' . $options['payment_gateway'] . '_' . ucfirst($options['type']);
					$this->loadReceiver($pgOptions);
				}
				if (empty($paymentGatewayReceiver)) {
					$customPaymentGateways = Billrun_PaymentGateway_Connection::getReceiverSettings($options);
					foreach ($customPaymentGateways as $fileType => $fileTypeSettings) {
						foreach ($fileTypeSettings['connections'] as $connectionDetails) {
							$connectionDetails['file_type'] = $fileType;
							$connectionDetails['type'] = str_replace('_', '', ucwords($options['payment_gateway'], '_')) . str_replace('_', '', ucwords($options['type'], '_'));
							$connection = Billrun_Factory::paymentGatewayConnection($connectionDetails);
							$connection->receive();
						}
					}
				}
			}
			$inputProcessor = Billrun_Factory::config()->getFileTypeSettings($options['type'], true);
			$connections = isset($inputProcessor['receiver']['connections']) ? $inputProcessor['receiver']['connections'] : [];
			foreach ($connections as $connection) {
				$connectionsPerReceiverType[$connection['receiver_type']][] = $connection;
			}
			foreach ($connectionsPerReceiverType as $receiverType => $receiverTypeConnections) {
				$inputProcessor['receiver']['connections'] = $receiverTypeConnections;
				$inputProcessor['receiver']['receiver_type'] = $receiverType;
				$options = $inputProcessor;
				$this->loadReceiver($options);<commit_msg>BRCD-2558:Added "file_type" check - so only the wanted file_type configuration will be taken into account<commit_after><?php

/**
 * @package         Billing
 * @copyright       Copyright (C) 2012-2016 BillRun Technologies Ltd. All rights reserved.
 * @license         GNU Affero General Public License Version 3; see LICENSE.txt
 */

/**
 * Receive action controller class
 *
 * @package     Controllers
 * @subpackage  Action
 * @since       1.0
 */
class ReceiveAction extends Action_Base {
	use Billrun_Traits_TypeAll;
	
	/**
	 * method to execute the receive process
	 * it's called automatically by the cli main controller
	 */
	public function execute() {
		if (!$this->isOn()) {
			$this->getController()->addOutput(ucfirst($this->getRequest()->action) . " is off");
			return;
		}

		$possibleOptions = array(
			'type' => false,
			'path' => true,
			'workspace' => true,
		);

		if (($options = $this->_controller->getInstanceOptions($possibleOptions)) === FALSE) {
			return;
		}
		$extraParams = $this->_controller->getParameters();
		if (!empty($extraParams)) {
			$options = array_merge($extraParams, $options);
		}

		// If not type all process normaly.
		if(!$this->handleTypeAll($options)) {
			$connectionsPerReceiverType = array();
			if (isset($options['payment_gateway'])) {
				$paymentGatewayReceiver = Billrun_Receiver_NonCDRs_PaymentGateway::getReceiverSettings($options);
				$pgConnections = isset($paymentGatewayReceiver['connections']) ? $paymentGatewayReceiver['connections'] : [];
				foreach ($pgConnections as $pgConnection) {
					$pgOptions = $options;
					$pgOptions['file_type'] = $options['type'];
					$pgOptions['receiver']['connection'] = $pgConnection;
					$pgOptions['receiver']['receiver_type'] = 'PaymentGateway_' . $options['payment_gateway'] . '_' . ucfirst($options['type']);
					$this->loadReceiver($pgOptions);
				}
				if (empty($paymentGatewayReceiver)) {
					$customPaymentGateways = Billrun_PaymentGateway_Connection::getReceiverSettings($options);
					foreach ($customPaymentGateways as $fileType => $fileTypeSettings) {
						foreach ($fileTypeSettings['connections'] as $connectionDetails) {
							if ($fileType === $options['file_type']) {
								$connectionDetails['file_type'] = $fileType;
								$connectionDetails['type'] = str_replace('_', '', ucwords($options['payment_gateway'], '_')) . str_replace('_', '', ucwords($options['type'], '_'));
								$connection = Billrun_Factory::paymentGatewayConnection($connectionDetails);
								$connection->receive();
							}
						}
					}
				}
			}
			$inputProcessor = Billrun_Factory::config()->getFileTypeSettings($options['type'], true);
			$connections = isset($inputProcessor['receiver']['connections']) ? $inputProcessor['receiver']['connections'] : [];
			foreach ($connections as $connection) {
				$connectionsPerReceiverType[$connection['receiver_type']][] = $connection;
			}
			foreach ($connectionsPerReceiverType as $receiverType => $receiverTypeConnections) {
				$inputProcessor['receiver']['connections'] = $receiverTypeConnections;
				$inputProcessor['receiver']['receiver_type'] = $receiverType;
				$options = $inputProcessor;
				$this->loadReceiver($options);
{'fraction_non_alphanumeric': 0.15714514322291567, 'fraction_numerical': 0.004160665706513042, 'mean_word_length': 4.718206770356816, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '3094706', 'n_tokens_mistral': 2083, 'n_tokens_neox': 1740, 'n_words': 335}