From ea80f4b96c3b6f9ffab07f34eef34515b0967c5e Mon Sep 17 00:00:00 2001 From: bdmehedi Date: Mon, 4 Dec 2023 17:53:02 +0600 Subject: [PATCH 1/3] remove updater --- src/Client.php | 27 ----- src/Updater.php | 262 ------------------------------------------------ 2 files changed, 289 deletions(-) delete mode 100644 src/Updater.php diff --git a/src/Client.php b/src/Client.php index 33ea033..89b6192 100644 --- a/src/Client.php +++ b/src/Client.php @@ -85,13 +85,6 @@ class Client { */ private $insights; - /** - * The Object of Updater Class - * - * @var object - */ - private $updater; - /** * The Object of License Class * @@ -134,26 +127,6 @@ public function insights() { return $this->insights; } - /** - * Initialize plugin/theme updater - * - * @return Appsero\Updater - */ - public function updater() { - if ( ! class_exists( __NAMESPACE__ . '\Updater' ) ) { - require_once __DIR__ . '/Updater.php'; - } - - // if already instantiated, return the cached one - if ( $this->updater ) { - return $this->updater; - } - - $this->updater = new Updater( $this ); - - return $this->updater; - } - /** * Initialize license checker * diff --git a/src/Updater.php b/src/Updater.php deleted file mode 100644 index c98abd8..0000000 --- a/src/Updater.php +++ /dev/null @@ -1,262 +0,0 @@ -client = $client; - $this->cache_key = 'appsero_' . md5( $this->client->slug ) . '_version_info'; - - // Run hooks. - if ( $this->client->type === 'plugin' ) { - $this->run_plugin_hooks(); - } elseif ( $this->client->type === 'theme' ) { - $this->run_theme_hooks(); - } - } - - /** - * Set up WordPress filter to hooks to get update. - * - * @return void - */ - public function run_plugin_hooks() { - add_filter( 'pre_set_site_transient_update_plugins', [ $this, 'check_plugin_update' ] ); - add_filter( 'plugins_api', [ $this, 'plugins_api_filter' ], 10, 3 ); - } - - /** - * Set up WordPress filter to hooks to get update. - * - * @return void - */ - public function run_theme_hooks() { - add_filter( 'pre_set_site_transient_update_themes', [ $this, 'check_theme_update' ] ); - } - - /** - * Check for Update for this specific project - */ - public function check_plugin_update( $transient_data ) { - global $pagenow; - - if ( ! is_object( $transient_data ) ) { - $transient_data = new stdClass(); - } - - if ( 'plugins.php' === $pagenow && is_multisite() ) { - return $transient_data; - } - - if ( ! empty( $transient_data->response ) && ! empty( $transient_data->response[ $this->client->basename ] ) ) { - return $transient_data; - } - - $version_info = $this->get_version_info(); - - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { - unset( $version_info->sections ); - - // If new version available then set to `response` - if ( version_compare( $this->client->project_version, $version_info->new_version, '<' ) ) { - $transient_data->response[ $this->client->basename ] = $version_info; - } else { - // If new version is not available then set to `no_update` - $transient_data->no_update[ $this->client->basename ] = $version_info; - } - - $transient_data->last_checked = time(); - $transient_data->checked[ $this->client->basename ] = $this->client->project_version; - } - - return $transient_data; - } - - /** - * Get version info from database - * - * @return object or Boolean - */ - private function get_cached_version_info() { - global $pagenow; - - // If updater page then fetch from API now - if ( 'update-core.php' === $pagenow ) { - return false; // Force to fetch data - } - - $value = get_transient( $this->cache_key ); - - if ( ! $value && ! isset( $value->name ) ) { - return false; // Cache is expired - } - - // We need to turn the icons into an array - if ( isset( $value->icons ) ) { - $value->icons = (array) $value->icons; - } - - // We need to turn the banners into an array - if ( isset( $value->banners ) ) { - $value->banners = (array) $value->banners; - } - - if ( isset( $value->sections ) ) { - $value->sections = (array) $value->sections; - } - - return $value; - } - - /** - * Set version info to database - */ - private function set_cached_version_info( $value ) { - if ( ! $value ) { - return; - } - - set_transient( $this->cache_key, $value, 3 * HOUR_IN_SECONDS ); - } - - /** - * Get plugin info from Appsero - */ - private function get_project_latest_version() { - $license = $this->client->license()->get_license(); - - $params = [ - 'version' => $this->client->project_version, - 'name' => $this->client->name, - 'slug' => $this->client->slug, - 'basename' => $this->client->basename, - 'license_key' => ! empty( $license ) && isset( $license['key'] ) ? $license['key'] : '', - ]; - - $route = 'update/' . $this->client->hash . '/check'; - - $response = $this->client->send_request( $params, $route, true ); - - if ( is_wp_error( $response ) ) { - return false; - } - - $response = json_decode( wp_remote_retrieve_body( $response ) ); - - if ( ! isset( $response->slug ) ) { - return false; - } - - if ( isset( $response->icons ) ) { - $response->icons = (array) $response->icons; - } - - if ( isset( $response->banners ) ) { - $response->banners = (array) $response->banners; - } - - if ( isset( $response->sections ) ) { - $response->sections = (array) $response->sections; - } - - return $response; - } - - /** - * Updates information on the "View version x.x details" page with custom data. - * - * @param mixed $data - * @param string $action - * @param object $args - * - * @return object $data - */ - public function plugins_api_filter( $data, $action = '', $args = null ) { - if ( $action !== 'plugin_information' ) { - return $data; - } - - if ( ! isset( $args->slug ) || ( $args->slug !== $this->client->slug ) ) { - return $data; - } - - return $this->get_version_info(); - } - - /** - * Check theme upate - */ - public function check_theme_update( $transient_data ) { - global $pagenow; - - if ( ! is_object( $transient_data ) ) { - $transient_data = new stdClass(); - } - - if ( 'themes.php' === $pagenow && is_multisite() ) { - return $transient_data; - } - - if ( ! empty( $transient_data->response ) && ! empty( $transient_data->response[ $this->client->slug ] ) ) { - return $transient_data; - } - - $version_info = $this->get_version_info(); - - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { - // If new version available then set to `response` - if ( version_compare( $this->client->project_version, $version_info->new_version, '<' ) ) { - $transient_data->response[ $this->client->slug ] = (array) $version_info; - } else { - // If new version is not available then set to `no_update` - $transient_data->no_update[ $this->client->slug ] = (array) $version_info; - } - - $transient_data->last_checked = time(); - $transient_data->checked[ $this->client->slug ] = $this->client->project_version; - } - - return $transient_data; - } - - /** - * Get version information - */ - private function get_version_info() { - $version_info = $this->get_cached_version_info(); - - if ( false === $version_info ) { - $version_info = $this->get_project_latest_version(); - $this->set_cached_version_info( $version_info ); - } - - return $version_info; - } -} From 478b6000de9a1ca860c93981ac894447e261b387 Mon Sep 17 00:00:00 2001 From: Md Mehedi Hasan Date: Wed, 6 Dec 2023 12:19:00 +0600 Subject: [PATCH 2/3] Update wpcs.yml Updated the action to exclude deleted file --- .github/workflows/wpcs.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/wpcs.yml b/.github/workflows/wpcs.yml index d7c4fff..5c5221e 100644 --- a/.github/workflows/wpcs.yml +++ b/.github/workflows/wpcs.yml @@ -17,7 +17,7 @@ jobs: - name: Get Composer cache directory id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Setup cache uses: pat-s/always-upload-cache@v1.1.4 @@ -32,7 +32,8 @@ jobs: - id: changes run: | URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" - FILES=$(curl -s -X GET -G $URL | jq -r '.[] | .filename' | xargs) - echo "::set-output name=files::$FILES" + FILES=$(curl -s -X GET -G $URL | jq -r '.[] | select (.status!="removed") | .filename | select ( endswith(".php") )' | xargs) + echo "files=$FILES" >> $GITHUB_OUTPUT + - name: Detect coding standard violations run: vendor/bin/phpcs ${{ steps.changes.outputs.files }} -q --report=checkstyle | cs2pr --graceful-warnings From 79a774592a8dbb79cdc3a9e693b77d5b9d64669f Mon Sep 17 00:00:00 2001 From: Md Mehedi Hasan Date: Wed, 6 Dec 2023 12:27:40 +0600 Subject: [PATCH 3/3] Update wpcs.yml --- .github/workflows/wpcs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wpcs.yml b/.github/workflows/wpcs.yml index 5c5221e..b859c85 100644 --- a/.github/workflows/wpcs.yml +++ b/.github/workflows/wpcs.yml @@ -6,7 +6,7 @@ jobs: name: Run PHPCS inspection runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -20,7 +20,7 @@ jobs: run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Setup cache - uses: pat-s/always-upload-cache@v1.1.4 + uses: pat-s/always-upload-cache@v3.0.11 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}