From 387b3cf3eaea69536ef8dc2c6bf1e0b5d754c8d4 Mon Sep 17 00:00:00 2001 From: Boro Sitnikovski Date: Tue, 5 Jun 2018 09:59:37 +0200 Subject: [PATCH 1/8] Use WordPress.org for downloading WooCommerce --- .../woocommerce-beta-tester/includes/class-wc-beta-tester.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php index 01a2a3fda39..51ddb2b9583 100644 --- a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php +++ b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php @@ -74,7 +74,7 @@ class WC_Beta_Tester { $this->config['new_version'] = $this->get_latest_prerelease(); $this->config['last_updated'] = $this->get_date(); $this->config['description'] = $this->get_description(); - $this->config['zip_url'] = 'https://github.com/woocommerce/woocommerce/zipball/' . $this->config['new_version']; + $this->config['zip_url'] = 'https://downloads.wordpress.org/plugin/woocommerce.' . $this->config['new_version'] . '.zip'; } /** From 29b0c483b881febdf02766a45da2f1ff39fa5500 Mon Sep 17 00:00:00 2001 From: Boro Sitnikovski Date: Tue, 5 Jun 2018 15:26:59 +0200 Subject: [PATCH 2/8] Use WPorg API to get data instead of GitHub --- .../includes/class-wc-beta-tester.php | 74 +++++++++++-------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php index 51ddb2b9583..8471df539d7 100644 --- a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php +++ b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php @@ -51,7 +51,7 @@ class WC_Beta_Tester { 'plugin_file' => 'woocommerce/woocommerce.php', 'slug' => 'woocommerce', 'proper_folder_name' => 'woocommerce', - 'api_url' => 'https://api.github.com/repos/woocommerce/woocommerce', + 'api_url' => 'https://api.wordpress.org/plugins/info/1.0/woocommerce.json', 'github_url' => 'https://github.com/woocommerce/woocommerce', 'requires' => '4.4', 'tested' => '4.9', @@ -87,7 +87,7 @@ class WC_Beta_Tester { } /** - * Get New Version from GitHub + * Get New Version from WPorg * * @since 1.0 * @return int $version the version number @@ -125,35 +125,35 @@ class WC_Beta_Tester { } /** - * Get GitHub Data from the specified repository. + * Get Data from .org API. * * @since 1.0 - * @return array $github_data The data. + * @return array $wporg_data The data. */ - public function get_github_data() { - if ( ! empty( $this->github_data ) ) { - $github_data = $this->github_data; - } else { - $github_data = get_site_transient( md5( $this->config['slug'] ) . '_github_data' ); - - if ( $this->overrule_transients() || ( ! isset( $github_data ) || ! $github_data || '' === $github_data ) ) { - $github_data = wp_remote_get( $this->config['api_url'] ); - - if ( is_wp_error( $github_data ) ) { - return false; - } - - $github_data = json_decode( $github_data['body'] ); - - // Refresh every 6 hours. - set_site_transient( md5( $this->config['slug'] ) . '_github_data', $github_data, 60 * 60 * 6 ); - } - - // Store the data in this class instance for future calls. - $this->github_data = $github_data; + public function get_wporg_data() { + if ( ! empty( $this->wporg_data ) ) { + return $this->wporg_data; } - return $github_data; + $wporg_data = get_site_transient( md5( $this->config['slug'] ) . '_wporg_data' ); + + if ( $this->overrule_transients() || ( ! isset( $wporg_data ) || ! $wporg_data || '' === $wporg_data ) ) { + $wporg_data = wp_remote_get( $this->config['api_url'] ); + + if ( is_wp_error( $wporg_data ) ) { + return false; + } + + $wporg_data = json_decode( $wporg_data['body'] ); + + // Refresh every 6 hours. + set_site_transient( md5( $this->config['slug'] ) . '_wporg_data', $wporg_data, 60 * 60 * 6 ); + } + + // Store the data in this class instance for future calls. + $this->wporg_data = $wporg_data; + + return $wporg_data; } /** * Get update date @@ -162,8 +162,8 @@ class WC_Beta_Tester { * @return string $date the date */ public function get_date() { - $_date = $this->get_github_data(); - return ! empty( $_date->updated_at ) ? date( 'Y-m-d', strtotime( $_date->updated_at ) ) : false; + $_date = $this->get_wporg_data(); + return ! empty( $_date->last_updated ) ? date( 'Y-m-d', strtotime( $_date->last_updated ) ) : false; } /** @@ -173,8 +173,20 @@ class WC_Beta_Tester { * @return string $description the description */ public function get_description() { - $_description = $this->get_github_data(); - return ! empty( $_description->description ) ? $_description->description : false; + $_description = $this->get_wporg_data(); + + if ( empty( $_description->sections->description ) ) { + return false; + } + + $_description = $_description->sections->description; + + if ( preg_match('%(]*>.*?

)%i', $_description, $regs ) ) { + $_description = strip_tags( $regs[1] ); + } + + + return $_description; } /** @@ -188,7 +200,7 @@ class WC_Beta_Tester { } /** - * Hook into the plugin update check and connect to GitHub. + * Hook into the plugin update check and connect to WPorg. * * @since 1.0 * @param object $transient The plugin data transient. From 10a3a8877d12378b751624483363e38e5b55737f Mon Sep 17 00:00:00 2001 From: Boro Sitnikovski Date: Tue, 5 Jun 2018 15:31:53 +0200 Subject: [PATCH 3/8] Use correct download URL --- .../includes/class-wc-beta-tester.php | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php index 8471df539d7..7f826993f6a 100644 --- a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php +++ b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php @@ -74,7 +74,7 @@ class WC_Beta_Tester { $this->config['new_version'] = $this->get_latest_prerelease(); $this->config['last_updated'] = $this->get_date(); $this->config['description'] = $this->get_description(); - $this->config['zip_url'] = 'https://downloads.wordpress.org/plugin/woocommerce.' . $this->config['new_version'] . '.zip'; + $this->config['zip_url'] = $this->get_download_url( $this->config['new_version'] ); } /** @@ -162,8 +162,8 @@ class WC_Beta_Tester { * @return string $date the date */ public function get_date() { - $_date = $this->get_wporg_data(); - return ! empty( $_date->last_updated ) ? date( 'Y-m-d', strtotime( $_date->last_updated ) ) : false; + $data = $this->get_wporg_data(); + return ! empty( $data->last_updated ) ? date( 'Y-m-d', strtotime( $data->last_updated ) ) : false; } /** @@ -173,20 +173,36 @@ class WC_Beta_Tester { * @return string $description the description */ public function get_description() { - $_description = $this->get_wporg_data(); + $data = $this->get_wporg_data(); - if ( empty( $_description->sections->description ) ) { + if ( empty( $data->sections->description ) ) { return false; } - $_description = $_description->sections->description; + $data = $data->sections->description; - if ( preg_match('%(]*>.*?

)%i', $_description, $regs ) ) { - $_description = strip_tags( $regs[1] ); + if ( preg_match('%(]*>.*?

)%i', $data, $regs ) ) { + $data = strip_tags( $regs[1] ); } - return $_description; + return $data; + } + + /** + * Get plugin download URL + * + * @since 1.0 + * @return string $description the description + */ + public function get_download_url( $version ) { + $data = $this->get_wporg_data(); + + if ( empty( $data->versions->$version ) ) { + return false; + } + + return $data->versions->$version; } /** From 1a74266309d0059c31b53a5351d16328062285da Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 5 Jun 2018 14:06:21 -0300 Subject: [PATCH 4/8] Fixed coding standards --- .../includes/class-wc-beta-tester.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php index 29f4f628bb3..4cd111c30fc 100644 --- a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php +++ b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php @@ -68,7 +68,7 @@ class WC_Beta_Tester { * Include any classes we need within admin. */ public function includes() { - include_once( dirname( __FILE__ ) . '/class-wc-beta-tester-admin-menus.php' ); + include_once dirname( __FILE__ ) . '/class-wc-beta-tester-admin-menus.php'; } /** @@ -190,19 +190,19 @@ class WC_Beta_Tester { $data = $data->sections->description; - if ( preg_match('%(]*>.*?

)%i', $data, $regs ) ) { + if ( preg_match( '%(]*>.*?

)%i', $data, $regs ) ) { $data = strip_tags( $regs[1] ); } - return $data; } /** - * Get plugin download URL + * Get plugin download URL. * * @since 1.0 - * @return string $description the description + * @param string $version The version. + * @return string */ public function get_download_url( $version ) { $data = $this->get_wporg_data(); From 6f95040c5e38fe6cdbadc20c8dd9c806f0b67ab6 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 5 Jun 2018 14:08:06 -0300 Subject: [PATCH 5/8] Removed GitHub URL --- .../woocommerce-beta-tester/includes/class-wc-beta-tester.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php index 4cd111c30fc..8ab3d70302f 100644 --- a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php +++ b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php @@ -52,7 +52,7 @@ class WC_Beta_Tester { 'slug' => 'woocommerce', 'proper_folder_name' => 'woocommerce', 'api_url' => 'https://api.wordpress.org/plugins/info/1.0/woocommerce.json', - 'github_url' => 'https://github.com/woocommerce/woocommerce', + 'repo_url' => 'https://wordpress.org/plugins/woocommerce/', 'requires' => '4.4', 'tested' => '4.9', ); @@ -252,7 +252,7 @@ class WC_Beta_Tester { $response->plugin = $this->config['slug']; $response->new_version = $this->config['new_version']; $response->slug = $this->config['slug']; - $response->url = $this->config['github_url']; + $response->url = $this->config['repo_url']; $response->package = $this->config['zip_url']; // If response is false, don't alter the transient. From c1c73611fd4c327ddd06d96d9a479cd2980a3dcc Mon Sep 17 00:00:00 2001 From: Boro Sitnikovski Date: Tue, 5 Jun 2018 23:18:07 +0200 Subject: [PATCH 6/8] Get latest pre-release by comparing against (beta/rc) versions higher than latest release --- .../includes/class-wc-beta-tester.php | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php index 8ab3d70302f..e48f21b54de 100644 --- a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php +++ b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php @@ -106,21 +106,17 @@ class WC_Beta_Tester { if ( $this->overrule_transients() || empty( $tagged_version ) ) { - $raw_response = wp_remote_get( trailingslashit( $this->config['api_url'] ) . 'releases' ); + $data = $this->get_wporg_data(); - if ( is_wp_error( $raw_response ) ) { - return false; - } + $latest_version = $data->version; + $versions = (array) $data->versions; - $releases = json_decode( $raw_response['body'] ); - $tagged_version = false; + foreach ( $versions as $version => $download_url ) { + if ( version_compare( $version, $latest_version, '>' ) + && preg_match( '/(.*)?-(beta|rc)(.*)/', $version ) ) { - if ( is_array( $releases ) ) { - foreach ( $releases as $release ) { - if ( $release->prerelease ) { - $tagged_version = $release->tag_name; - break; - } + $tagged_version = $version; + break; } } From b0bae55ce1b8768529840e4eee8c95263a976f32 Mon Sep 17 00:00:00 2001 From: Boro Sitnikovski Date: Tue, 5 Jun 2018 23:22:45 +0200 Subject: [PATCH 7/8] Don't break as we need to return the latest beta/rc candidate (assume the versions array is ordered) --- .../woocommerce-beta-tester/includes/class-wc-beta-tester.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php index e48f21b54de..d70dc6c283d 100644 --- a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php +++ b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php @@ -114,9 +114,7 @@ class WC_Beta_Tester { foreach ( $versions as $version => $download_url ) { if ( version_compare( $version, $latest_version, '>' ) && preg_match( '/(.*)?-(beta|rc)(.*)/', $version ) ) { - $tagged_version = $version; - break; } } From b750c96c2a1fb568806482437a2ad2ad6c690ba9 Mon Sep 17 00:00:00 2001 From: Boro Sitnikovski Date: Tue, 5 Jun 2018 23:46:34 +0200 Subject: [PATCH 8/8] Don't check against versions higher than latest version --- .../woocommerce-beta-tester/includes/class-wc-beta-tester.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php index d70dc6c283d..8b0592179de 100644 --- a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php +++ b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester.php @@ -112,8 +112,7 @@ class WC_Beta_Tester { $versions = (array) $data->versions; foreach ( $versions as $version => $download_url ) { - if ( version_compare( $version, $latest_version, '>' ) - && preg_match( '/(.*)?-(beta|rc)(.*)/', $version ) ) { + if ( preg_match( '/(.*)?-(beta|rc)(.*)/', $version ) ) { $tagged_version = $version; } }