<commit_before><?php
	/**
	 * @package     Freemius Migration
	 * @copyright   Copyright (c) 2016, Freemius, Inc.
	 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
	 * @since       1.0.3
	 */

	if ( ! defined( 'ABSPATH' ) ) {
		exit;
	}

	if ( class_exists( 'FS_Client_Migration_Abstract_v1' ) ) {
		return;
	}

	abstract class FS_Client_Migration_Abstract_v1 {
		/**
		 * @var \Freemius Freemius instance manager.
		 */
		protected $_fs;

		/**
		 * @var string Store URL.
		 */
		protected $_store_url;

		/**
		 * @var string Product ID.
		 */
		protected $_product_id;

		/**
		 * @var string License Key.
		 */
		protected $_license_key;

		/**
		 * @var FS_Client_License_Abstract_v1
		 */
		protected $_license_accessor;

		/**
		 * @var string Migration namespace.
		 */
		protected $_namespace;

		/**
		 * @param string                        $namespace        Migration namespace (e.g. EDD, WC)
		 * @param Freemius                      $freemius
		 * @param string                        $store_url        Store URL.
		 * @param string                        $product_id       Product ID.
		 * @param FS_Client_License_Abstract_v1 $license_accessor License accessor.
		 */
		protected function init(
			$namespace,
			Freemius $freemius,
			$store_url,
			$product_id,
			FS_Client_License_Abstract_v1 $license_accessor
		) {
			$this->_namespace        = strtolower( $namespace );
			$this->_fs               = $freemius;
			$this->_store_url        = $store_url;
			$this->_product_id       = $product_id;
			$this->_license_accessor = $license_accessor;
			$this->_license_key      = $license_accessor->get();

			/**
			 * If no license is set it might be one of the following:
			 *  1. User purchased module directly from Freemius.
			 *  2. User did purchase from store, but has never activated the license on this site.
			 *  3. User got access to the code without ever purchasing.
			 *
			 * In case it's reason #2 or if the license key is wrong, the migration will not work.
			 * Since we do want to support store licenses, hook to Freemius `after_install_failure`
			 * event. That way, if a license activation fails, try activating the license on store
			 * first, and if works, migrate to Freemius right after.
			 */
			$this->_fs->add_filter( 'after_install_failure', array( &$this, 'try_migrate_on_activation' ), 10, 2 );

			if ( ! empty( $this->_license_key ) ) {
				if ( ! defined( 'DOING_AJAX' ) ) {
					$this->non_blocking_license_migration();
				}
			}
		}

		/**
		 * @author   <NAME> (@svovaf)
		 * @since    1.0.3
		 *
		 * @return string
		 */
		protected function get_migration_endpoint() {
			return sprintf(
				'%s/fs-api/%s/migrate-license.json',
				$this->_store_url,
				$this->_namespace
			);
		}

		/**
		 * The license migration script.
		 *
		 * IMPORTANT:
		 *  You should use your own function name, and be sure to replace it throughout this file.
		 *
		 * @author   <NAME> (@svovaf)
		 * @since    1.0.0
		 *
		 * @param bool $redirect
		 *
		 * @return bool
		 */
		protected function do_license_migration( $redirect = false ) {
			$install_details = $this->_fs->get_opt_in_params();

			// Override is_premium flat because it's a paid license migration.
			$install_details['is_premium'] = true;
			// The plugin is active for sure and not uninstalled.
			$install_details['is_active']      = true;
			$install_details['is_uninstalled'] = false;

			// Clean unnecessary arguments.
			unset( $install_details['return_url'] );
			unset( $install_details['account_url'] );


			// Call the custom license and account migration endpoint.
			$transient_key = 'fs_license_migration_' . $this->_product_id . '_' . md5( $this->_license_key );
			$response      = get_transient( $transient_key );

			if ( false === $response ) {
				$response = wp_remote_post(
					$this->get_migration_endpoint(),
					array_merge( $install_details, array(
						'timeout'   => 15,
						'sslverify' => false,
						'body'      => json_encode( array_merge( $install_details, array(
							'module_id'   => $this->_product_id,
							'license_key' => $this->_license_key,
							'url'         => home_url()
						) ) ),
					) )
				);

				// Cache result (5-min).
				set_transient( $transient_key, $response, 5 * MINUTE_IN_SECONDS );
			}

			// make sure the response came back okay<commit_msg>[minor] [bug-fix] Redundant params merge.<commit_after><?php
	/**
	 * @package     Freemius Migration
	 * @copyright   Copyright (c) 2016, Freemius, Inc.
	 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
	 * @since       1.0.3
	 */

	if ( ! defined( 'ABSPATH' ) ) {
		exit;
	}

	if ( class_exists( 'FS_Client_Migration_Abstract_v1' ) ) {
		return;
	}

	abstract class FS_Client_Migration_Abstract_v1 {
		/**
		 * @var \Freemius Freemius instance manager.
		 */
		protected $_fs;

		/**
		 * @var string Store URL.
		 */
		protected $_store_url;

		/**
		 * @var string Product ID.
		 */
		protected $_product_id;

		/**
		 * @var string License Key.
		 */
		protected $_license_key;

		/**
		 * @var FS_Client_License_Abstract_v1
		 */
		protected $_license_accessor;

		/**
		 * @var string Migration namespace.
		 */
		protected $_namespace;

		/**
		 * @param string                        $namespace        Migration namespace (e.g. EDD, WC)
		 * @param Freemius                      $freemius
		 * @param string                        $store_url        Store URL.
		 * @param string                        $product_id       Product ID.
		 * @param FS_Client_License_Abstract_v1 $license_accessor License accessor.
		 */
		protected function init(
			$namespace,
			Freemius $freemius,
			$store_url,
			$product_id,
			FS_Client_License_Abstract_v1 $license_accessor
		) {
			$this->_namespace        = strtolower( $namespace );
			$this->_fs               = $freemius;
			$this->_store_url        = $store_url;
			$this->_product_id       = $product_id;
			$this->_license_accessor = $license_accessor;
			$this->_license_key      = $license_accessor->get();

			/**
			 * If no license is set it might be one of the following:
			 *  1. User purchased module directly from Freemius.
			 *  2. User did purchase from store, but has never activated the license on this site.
			 *  3. User got access to the code without ever purchasing.
			 *
			 * In case it's reason #2 or if the license key is wrong, the migration will not work.
			 * Since we do want to support store licenses, hook to Freemius `after_install_failure`
			 * event. That way, if a license activation fails, try activating the license on store
			 * first, and if works, migrate to Freemius right after.
			 */
			$this->_fs->add_filter( 'after_install_failure', array( &$this, 'try_migrate_on_activation' ), 10, 2 );

			if ( ! empty( $this->_license_key ) ) {
				if ( ! defined( 'DOING_AJAX' ) ) {
					$this->non_blocking_license_migration();
				}
			}
		}

		/**
		 * @author   <NAME> (@svovaf)
		 * @since    1.0.3
		 *
		 * @return string
		 */
		protected function get_migration_endpoint() {
			return sprintf(
				'%s/fs-api/%s/migrate-license.json',
				$this->_store_url,
				$this->_namespace
			);
		}

		/**
		 * The license migration script.
		 *
		 * IMPORTANT:
		 *  You should use your own function name, and be sure to replace it throughout this file.
		 *
		 * @author   <NAME> (@svovaf)
		 * @since    1.0.0
		 *
		 * @param bool $redirect
		 *
		 * @return bool
		 */
		protected function do_license_migration( $redirect = false ) {
			$install_details = $this->_fs->get_opt_in_params();

			// Override is_premium flat because it's a paid license migration.
			$install_details['is_premium'] = true;
			// The plugin is active for sure and not uninstalled.
			$install_details['is_active']      = true;
			$install_details['is_uninstalled'] = false;

			// Clean unnecessary arguments.
			unset( $install_details['return_url'] );
			unset( $install_details['account_url'] );


			// Call the custom license and account migration endpoint.
			$transient_key = 'fs_license_migration_' . $this->_product_id . '_' . md5( $this->_license_key );
			$response      = get_transient( $transient_key );

			if ( false === $response ) {
				$response = wp_remote_post(
					$this->get_migration_endpoint(),
					array(
						'timeout'   => 15,
						'sslverify' => false,
						'body'      => json_encode( array_merge( $install_details, array(
							'module_id'   => $this->_product_id,
							'license_key' => $this->_license_key,
							'url'         => home_url(),
						) ) ),
					)
				);

				// Cache result (5-min).
				set_transient( $transient_key, $response, 5 * MINUTE_IN_SECONDS );
			}

			// make sure the response came back okay
{'fraction_non_alphanumeric': 0.12127805771873569, 'fraction_numerical': 0.007329363261566651, 'mean_word_length': 2.5185334407735698, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 59, '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': '1213458', 'n_tokens_mistral': 3344, 'n_tokens_neox': 2707, 'n_words': 723}