From 768fb15e2c1f360ab3e93063149fd192f3797189 Mon Sep 17 00:00:00 2001 From: Paul Kilmurray Date: Wed, 20 Dec 2023 22:06:59 +0100 Subject: [PATCH] fix pro updater --- includes/Admin/Updaters/Pro_Plugin_Updater.php | 16 ++++++++-------- package.json | 2 +- tests/includes/Test_Wcpos_Functions.php | 2 +- woocommerce-pos.php | 5 ++--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/includes/Admin/Updaters/Pro_Plugin_Updater.php b/includes/Admin/Updaters/Pro_Plugin_Updater.php index 45e5a50..5ffb777 100644 --- a/includes/Admin/Updaters/Pro_Plugin_Updater.php +++ b/includes/Admin/Updaters/Pro_Plugin_Updater.php @@ -86,9 +86,13 @@ public function __construct() { $this->active = $status['active']; $this->current_version = $status['version']; + // Allow the update server to be overridden for development. + if ( isset( $_ENV['WCPOS_PRO_UPDATE_SERVER'] ) ) { + $this->update_server = $_ENV['WCPOS_PRO_UPDATE_SERVER']; + } + if ( $this->installed ) { add_filter( 'update_plugins_updates.wcpos.com', array( $this, 'update_plugins' ), 10, 4 ); - // add_filter( 'site_transient_update_plugins', array( $this, 'modify_plugin_update_transient' ) ); add_action( 'upgrader_process_complete', array( $this, 'after_plugin_update' ), 10, 2 ); add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 ); add_action( 'in_plugin_update_message-' . $this->pro_plugin_path, array( $this, 'plugin_update_message' ), 10, 2 ); @@ -207,12 +211,10 @@ public function update_plugins( $update, $plugin_data, $plugin_file, $locales ) */ public function check_pro_plugin_updates( $force = false ) { $update_data = get_transient( $this->update_data_transient_key ); - $is_development = isset( $_ENV['DEVELOPMENT'] ) && $_ENV['DEVELOPMENT']; if ( empty( $update_data ) || $force ) { $expiration = 60 * 60 * 12; // 12 hours. - $endpoint = $is_development ? 'http://localhost:8080/pro' : $this->update_server; - $url = $endpoint . '/update/' . $this->current_version; + $url = $this->update_server . '/update/' . $this->current_version; // make the api call. $response = wp_remote_get( @@ -256,9 +258,7 @@ public function check_pro_plugin_updates( $force = false ) { */ private function check_license_status( $force = false ) { $license_status = get_transient( $this->license_status_transient_key ); - $is_development = isset( $_ENV['DEVELOPMENT'] ) && $_ENV['DEVELOPMENT']; $expiration = 60 * 60 * 12; // 12 hours. - $endpoint = $is_development ? 'http://localhost:8080/pro' : $this->update_server; /** * TODO: How to allow for multisite? @@ -287,7 +287,7 @@ private function check_license_status( $force = false ) { 'key' => $license_settings['key'], 'instance' => $license_settings['instance'], ), - $endpoint . '/license/status' + $this->update_server . '/license/status' ); // make the api call. @@ -305,7 +305,7 @@ private function check_license_status( $force = false ) { if ( is_wp_error( $data ) ) { Logger::log( $data ); - $expiration = $is_development ? 1 : 60 * 60 * 1; // try again in an hour if error. + $expiration = 60 * 60 * 1; // try again in an hour if error. } set_transient( $this->license_status_transient_key, $data, $expiration ); diff --git a/package.json b/package.json index 5e866a7..5eb2552 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@wcpos/woocommerce-pos", - "version": "1.4.0-beta.3", + "version": "1.4.0-beta.4", "description": "A simple front-end for taking WooCommerce orders at the Point of Sale.", "main": "index.js", "workspaces": { diff --git a/tests/includes/Test_Wcpos_Functions.php b/tests/includes/Test_Wcpos_Functions.php index fe84509..82dff0c 100644 --- a/tests/includes/Test_Wcpos_Functions.php +++ b/tests/includes/Test_Wcpos_Functions.php @@ -9,7 +9,7 @@ * * @coversNothing */ -class Test_WCPOS_Functions extends WP_UnitTestCase { +class Test_Wcpos_Functions extends WP_UnitTestCase { public function setup(): void { parent::setup(); } diff --git a/woocommerce-pos.php b/woocommerce-pos.php index 0cf9a84..ba3d0d7 100644 --- a/woocommerce-pos.php +++ b/woocommerce-pos.php @@ -3,10 +3,9 @@ * Plugin Name: WooCommerce POS * Plugin URI: https://wordpress.org/plugins/woocommerce-pos/ * Description: A simple front-end for taking WooCommerce orders at the Point of Sale. Requires WooCommerce. - * Version: 1.4.0-beta.3 + * Version: 1.4.0-beta.4 * Author: kilbot * Author URI: http://wcpos.com - * Update URI: https://updates.wcpos.com/pro/ * Text Domain: woocommerce-pos * License: GPL-3.0+ * License URI: http://www.gnu.org/licenses/gpl-3.0.txt @@ -23,7 +22,7 @@ namespace WCPOS\WooCommercePOS; // Define plugin constants. -const VERSION = '1.4.0-beta.3'; +const VERSION = '1.4.0-beta.4'; const PLUGIN_NAME = 'woocommerce-pos'; const SHORT_NAME = 'wcpos'; \define( __NAMESPACE__ . '\PLUGIN_FILE', plugin_basename( __FILE__ ) ); // 'woocommerce-pos/woocommerce-pos.php'