From 15bb7476263590bde363c5f1418512d4fc1b5482 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Mon, 29 May 2023 19:09:14 +0530 Subject: [PATCH 1/4] Refactor onboarding to use the installer module --- composer.json | 10 +- composer.lock | 41 +- includes/Application.php | 3 - includes/Data/Data.php | 4 +- includes/Data/Flows.php | 2 +- includes/Data/Options.php | 5 - includes/Data/Plugins.php | 197 --------- includes/Data/Preview.php | 5 +- includes/Data/Themes.php | 48 --- includes/Models/PriorityQueue.php | 35 -- .../Mustache/Templates/aboutPage.mustache | 11 - .../Mustache/Templates/contactPage.mustache | 5 - includes/Mustache/Templates/homePage.mustache | 33 -- includes/Permissions.php | 27 +- includes/RestApi/PluginsController.php | 253 +----------- .../Themes/ThemeInstallerController.php | 175 +------- includes/Services/FlowService.php | 4 +- includes/Services/PluginInstaller.php | 378 ------------------ includes/Services/PluginService.php | 93 +++++ includes/Services/PluginUninstaller.php | 154 ------- includes/Services/ThemeInstaller.php | 195 --------- includes/Services/ThemeService.php | 46 +++ .../TaskManagers/PluginInstallTaskManager.php | 250 ------------ .../PluginUninstallTaskManager.php | 183 --------- includes/TaskManagers/TaskManager.php | 32 -- .../TaskManagers/ThemeInstallTaskManager.php | 204 ---------- includes/Tasks/PluginInstallTask.php | 121 ------ includes/Tasks/PluginUninstallTask.php | 103 ----- includes/Tasks/Task.php | 22 - includes/Tasks/ThemeInstallTask.php | 125 ------ includes/WP_Admin.php | 8 +- src/OnboardingSPA/utils/api/common.js | 8 +- src/OnboardingSPA/utils/api/plugins.js | 7 +- src/OnboardingSPA/utils/api/themes.js | 5 +- src/constants.js | 2 + 35 files changed, 238 insertions(+), 2556 deletions(-) delete mode 100644 includes/Models/PriorityQueue.php delete mode 100644 includes/Mustache/Templates/aboutPage.mustache delete mode 100644 includes/Mustache/Templates/contactPage.mustache delete mode 100644 includes/Mustache/Templates/homePage.mustache delete mode 100644 includes/Services/PluginInstaller.php create mode 100644 includes/Services/PluginService.php delete mode 100644 includes/Services/PluginUninstaller.php delete mode 100644 includes/Services/ThemeInstaller.php create mode 100644 includes/Services/ThemeService.php delete mode 100644 includes/TaskManagers/PluginInstallTaskManager.php delete mode 100644 includes/TaskManagers/PluginUninstallTaskManager.php delete mode 100644 includes/TaskManagers/TaskManager.php delete mode 100644 includes/TaskManagers/ThemeInstallTaskManager.php delete mode 100644 includes/Tasks/PluginInstallTask.php delete mode 100644 includes/Tasks/PluginUninstallTask.php delete mode 100644 includes/Tasks/Task.php delete mode 100644 includes/Tasks/ThemeInstallTask.php diff --git a/composer.json b/composer.json index 8bfb14dca..6ee66cbf5 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,13 @@ } }, "repositories": [ + { + "type": "path", + "url": "../wp-module-installer", + "options": { + "symlink": true + } + }, { "type": "composer", "url": "https://newfold-labs.github.io/satis/", @@ -38,7 +45,8 @@ "require-dev": { "wp-phpunit/wp-phpunit": "^5.9", "yoast/phpunit-polyfills": "^1.0", - "newfold-labs/wp-php-standards": "^1.2" + "newfold-labs/wp-php-standards": "^1.2", + "newfold-labs/wp-module-installer": "@dev" }, "scripts": { "lint": [ diff --git a/composer.lock b/composer.lock index 17b0eed0a..cf4240087 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "06d71429f830805afb16aca0971b0864", + "content-hash": "70cec6682ff6fda0c8aec4c3889f5158", "packages": [ { "name": "mustache/mustache", @@ -309,6 +309,41 @@ ], "time": "2022-03-03T13:19:32+00:00" }, + { + "name": "newfold-labs/wp-module-installer", + "version": "dev-enhance/code-improvements", + "dist": { + "type": "path", + "url": "../wp-module-installer", + "reference": "38187ec26c412fafdff23e8006af78da6f3cac7e" + }, + "require-dev": { + "newfold-labs/wp-php-standards": "^1.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "NewfoldLabs\\WP\\Module\\Installer\\": "includes" + }, + "files": [ + "bootstrap.php" + ] + }, + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "Micah Wood", + "email": "micah.wood@newfold.com" + } + ], + "description": "An installer for WordPress plugins and themes.", + "transport-options": { + "symlink": true, + "relative": true + } + }, { "name": "newfold-labs/wp-php-standards", "version": "1.2.2", @@ -2625,7 +2660,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "newfold-labs/wp-module-installer": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": [], diff --git a/includes/Application.php b/includes/Application.php index 598d9238c..1dd68ea45 100644 --- a/includes/Application.php +++ b/includes/Application.php @@ -6,7 +6,6 @@ use NewfoldLabs\WP\ModuleLoader\Container; use NewfoldLabs\WP\Module\Onboarding\Data\Options; use function NewfoldLabs\WP\ModuleLoader\container; -use NewfoldLabs\WP\Module\Onboarding\TaskManagers\TaskManager; /** * Primary instantiation of Onboarding Application. @@ -64,8 +63,6 @@ public function __construct( Container $container ) { new RestAPI(); - new TaskManager(); - if ( defined( '\\WP_CLI' ) && \WP_CLI ) { new WP_CLI(); } diff --git a/includes/Data/Data.php b/includes/Data/Data.php index 49f63e57a..b1caa434c 100644 --- a/includes/Data/Data.php +++ b/includes/Data/Data.php @@ -1,8 +1,8 @@ self::current_brand(), 'currentPlan' => self::current_plan(), 'currentFlow' => self::current_flow(), - 'pluginInstallHash' => Permissions::rest_get_plugin_install_hash(), + 'pluginInstallHash' => PluginInstaller::rest_get_plugin_install_hash(), 'previewSettings' => array( 'settings' => Preview::get_settings(), 'stepPreviewData' => Themes::step_preview_data(), diff --git a/includes/Data/Flows.php b/includes/Data/Flows.php index 3e60bb629..69edec603 100644 --- a/includes/Data/Flows.php +++ b/includes/Data/Flows.php @@ -2,7 +2,7 @@ namespace NewfoldLabs\WP\Module\Onboarding\Data; use NewfoldLabs\WP\Module\Onboarding\Services\FlowService; -use NewfoldLabs\WP\Module\Onboarding\Services\PluginInstaller; +use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller; /** * Contains Onboarding Flow information. diff --git a/includes/Data/Options.php b/includes/Data/Options.php index 085debc80..f4fc39486 100644 --- a/includes/Data/Options.php +++ b/includes/Data/Options.php @@ -33,12 +33,7 @@ final class Options { 'auto_update_theme' => 'auto_update_theme', 'permalink_structure' => 'permalink_structure', 'settings_initialized' => 'settings_initialized', - 'plugins_init_status' => 'plugins_init_status', - 'plugin_install_queue' => 'plugin_install_queue', - 'plugin_uninstall_queue' => 'plugin_uninstall_queue', 'flow' => 'flow', - 'theme_init_status' => 'theme_init_status', - 'theme_install_queue' => 'theme_install_queue', 'blog_name' => 'blogname', 'blog_description' => 'blogdescription', 'site_icon' => 'site_icon', diff --git a/includes/Data/Plugins.php b/includes/Data/Plugins.php index 68b2082ef..2a42b3977 100644 --- a/includes/Data/Plugins.php +++ b/includes/Data/Plugins.php @@ -5,107 +5,6 @@ * List of Plugin Slugs/URLs/Domains */ final class Plugins { - /** - * A value of true indicates that the slug/url/domain has been approved. - * A value of null indicates that the slug/url/domain has not been approved - * (or) has been temporarily deactivated. - * - * @var array - */ - protected static $wp_slugs = array( - 'jetpack' => array( - 'approved' => true, - 'path' => 'jetpack/jetpack.php', - ), - 'woocommerce' => array( - 'approved' => true, - 'path' => 'woocommerce/woocommerce.php', - 'post_install_callback' => array( __CLASS__, 'wc_prevent_redirect_on_activation' ), - ), - 'wordpress-seo' => array( - 'approved' => true, - 'path' => 'wordpress-seo/wp-seo.php', - ), - 'wpforms-lite' => array( - 'approved' => true, - 'path' => 'wpforms-lite/wpforms.php', - ), - 'google-analytics-for-wordpress' => array( - 'approved' => true, - 'path' => 'google-analytics-for-wordpress/googleanalytics.php', - ), - 'optinmonster' => array( - 'approved' => true, - 'path' => 'optinmonster/optin-monster-wp-api.php', - ), - 'yith-woocommerce-ajax-search' => array( - 'approved' => true, - 'path' => 'yith-woocommerce-ajax-search/init.php', - ), - 'creative-mail-by-constant-contact' => array( - 'approved' => true, - 'path' => 'creative-mail-by-constant-contact/creative-mail-plugin.php', - ), - ); - - /** - * Contains a list of zip url's with a unique "nfd_slug" for each. - * - * @var array - */ - protected static $nfd_slugs = array( - 'nfd_slug_endurance_page_cache' => array( - 'approved' => true, - 'url' => 'https://raw.githubusercontent.com/bluehost/endurance-page-cache/production/endurance-page-cache.php', - 'path' => WP_CONTENT_DIR . '/mu-plugins/endurance-page-cache.php', - ), - 'nfd_slug_yith_woocommerce_customize_myaccount_page' => array( - 'approved' => true, - 'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-customize-myaccount-page', - 'path' => 'yith-woocommerce-customize-myaccount-page-extended/init.php', - ), - 'nfd_slug_yith_woocommerce_gift_cards' => array( - 'approved' => true, - 'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-gift-cards', - 'path' => 'yith-woocommerce-gift-cards-extended/init.php', - ), - 'nfd_slug_ecomdash_wordpress_plugin' => array( - 'approved' => true, - 'url' => 'https://hiive.cloud/workers/plugin-downloads/ecomdash-wordpress-plugin', - 'path' => 'ecomdash-wordpress-plugin/ecomdash-plugin.php', - ), - 'nfd_slug_yith_paypal_payments_for_woocommerce' => array( - 'approved' => true, - 'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-paypal-payments-for-woocommerce', - 'path' => 'yith-paypal-payments-for-woocommerce-extended/init.php', - ), - 'nfd_slug_yith_shippo_shippings_for_woocommerce' => array( - 'approved' => true, - 'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-shippo-shippings-for-woocommerce', - 'path' => 'yith-shippo-shippings-for-woocommerce-extended/init.php', - ), - 'nfd_slug_yith_woocommerce_ajax_product_filter' => array( - 'approved' => true, - 'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-ajax-product-filter', - 'path' => 'yith-woocommerce-ajax-product-filter-extended/init.php', - ), - 'nfd_slug_yith_woocommerce_booking' => array( - 'approved' => true, - 'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-booking', - 'path' => 'yith-woocommerce-booking-extended/init.php', - ), - 'nfd_slug_yith_woocommerce_wishlist' => array( - 'approved' => true, - 'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-wishlist', - 'path' => 'yith-woocommerce-wishlist-extended/init.php', - ), - 'nfd_slug_woo_razorpay' => array( - 'approved' => true, - 'url' => 'https://hiive.cloud/workers/plugin-downloads/razorpay', - 'path' => 'woo-razorpay/woo-razorpay.php', - ), - ); - /** * Initial plugins to be installed classified based on the hosting plan. * Key 'default' contains a list of default plugins to be installed irrespective of the plan. @@ -302,102 +201,6 @@ final class Plugins { ), ); - // [TODO] Think about deprecating this approach and move to nfd_slugs for url based installs. - /** - * Contains a whitelist of zip url's. - * - * @var array - */ - protected static $urls = array( - 'https://downloads.wordpress.org/plugin/google-analytics-for-wordpress.8.5.3.zip' => true, - ); - /** - * Contains a list of approved domains for zip based installs. - * - * @var array - */ - protected static $domains = array( - 'downloads.wordpress.org' => true, - 'nonapproveddomain.com' => null, - ); - - /** - * Returns a list of whitelisted WordPress Plugin slugs. - * - * @return array - */ - public static function get_wp_slugs() { - return self::$wp_slugs; - } - - /** - * Returns a list of whitelisted Plugin URL's. - * - * @return array - */ - public static function get_urls() { - return self::$urls; - } - - /** - * Returns a list of whitelisted Plugin URL domains. - * - * @return array - */ - public static function get_domains() { - return self::$domains; - } - - /** - * Use this return value for a faster search of slug/url/domain. - * - * @return array - */ - public static function get() { - return array( - 'wp_slugs' => self::$wp_slugs, - 'nfd_slugs' => self::$nfd_slugs, - 'urls' => self::$urls, - 'domains' => self::$domains, - ); - } - - /** - * Use this for finding the path for installed plugins. - * - * @return array - */ - public static function get_squashed() { - return array_merge( - array_filter( self::$wp_slugs, array( __CLASS__, 'check_approved' ) ), - array_filter( self::$nfd_slugs, array( __CLASS__, 'check_approved' ) ) - ); - } - - /** - * Get approved slugs/urls/domains - * - * @return array - */ - public static function get_approved() { - return array( - 'wp_slugs' => array_keys( array_filter( self::$wp_slugs, array( __CLASS__, 'check_approved' ) ) ), - 'nfd_slugs' => array_keys( array_filter( self::$nfd_slugs, array( __CLASS__, 'check_approved' ) ) ), - 'urls' => array_keys( self::$urls, true, true ), - 'domains' => array_keys( self::$domains, true, true ), - ); - } - - /** - * Checks if a Plugin slug has been approved. - * - * @param array $value The Plugin slug that will be checked. - * @return boolean - */ - private static function check_approved( $value ) { - return true === $value['approved']; - } - /** * Get the list of initial plugins to be installed for a particular hosting plan. * diff --git a/includes/Data/Preview.php b/includes/Data/Preview.php index 886994f35..7486f5b09 100644 --- a/includes/Data/Preview.php +++ b/includes/Data/Preview.php @@ -1,8 +1,9 @@ array( - 'approved' => true, - 'url' => 'https://hiive.cloud/workers/plugin-downloads/yith-wonder-theme', - 'stylesheet' => 'yith-wonder', - ), - ); - /** * Flow to necessary theme map. * This is temporary, as we implement theme selections we can remove this. @@ -66,38 +50,6 @@ final class Themes { ), ); - /** - * Returns the list of themes in a data structure that is faster to search. - * - * @return array - */ - public static function get() { - return array( - 'nfd_slugs' => self::$nfd_slugs, - ); - } - - /** - * Get all the approved theme slugs. - * - * @return array - */ - public static function get_approved() { - return array( - 'nfd_slugs' => array_keys( array_filter( self::$nfd_slugs, array( __CLASS__, 'check_approved' ) ) ), - ); - } - - /** - * Checks if a slug has been approved. - * - * @param string $value The slug to check for - * @return boolean - */ - private static function check_approved( $value ) { - return true === $value['approved']; - } - /** * Get the number of previews that will be fetched in each step. * This helps us show the number of necessary skeletons in the front end. diff --git a/includes/Models/PriorityQueue.php b/includes/Models/PriorityQueue.php deleted file mode 100644 index c0fc47d08..000000000 --- a/includes/Models/PriorityQueue.php +++ /dev/null @@ -1,35 +0,0 @@ -valid() ) { - array_push( $array, $this->extract() ); - } - return $array; - } -} diff --git a/includes/Mustache/Templates/aboutPage.mustache b/includes/Mustache/Templates/aboutPage.mustache deleted file mode 100644 index 251026876..000000000 --- a/includes/Mustache/Templates/aboutPage.mustache +++ /dev/null @@ -1,11 +0,0 @@ - -

Welcome to organization name. We're dedicated to giving you the very best in topic/product, with a focus on brand differentiator 1, brand differentiator 2, and brand differentiator 3.

- - - -

When we started in founding date our passion for product or service type drove us to an action: create a product, start a community, etc. Now we serve customers all over your target market area: this could be a city, state, or the whole world, and are thrilled to share our passion with you.

- - - -

We hope you enjoy our products/services. If you have any questions or comments, please contact us phone number, email, or link to contact form.

- \ No newline at end of file diff --git a/includes/Mustache/Templates/contactPage.mustache b/includes/Mustache/Templates/contactPage.mustache deleted file mode 100644 index 04a9410f3..000000000 --- a/includes/Mustache/Templates/contactPage.mustache +++ /dev/null @@ -1,5 +0,0 @@ - -

Please fill out the form below and we'll be in touch.

- - - \ No newline at end of file diff --git a/includes/Mustache/Templates/homePage.mustache b/includes/Mustache/Templates/homePage.mustache deleted file mode 100644 index c328262f9..000000000 --- a/includes/Mustache/Templates/homePage.mustache +++ /dev/null @@ -1,33 +0,0 @@ - -
-
- -
-
Placeholder image
-
- -
-
- - - -

Name/Company Name

- - - -

We're dedicated to giving you the very best in topic/product, topic/product, and topic/product. Please reach out if you want to know more!

- - - -
- - - -
- - - -

News

- - - \ No newline at end of file diff --git a/includes/Permissions.php b/includes/Permissions.php index e014b657c..6e9a4f77e 100644 --- a/includes/Permissions.php +++ b/includes/Permissions.php @@ -5,7 +5,6 @@ * Permissions and Authorization constants and utilities. */ final class Permissions { - /** * WordPress Admin capability string */ @@ -13,25 +12,6 @@ final class Permissions { const INSTALL_THEMES = 'install_themes'; const EDIT_THEMES = 'edit_themes'; - /** - * Retrieve Plugin Install Hash Value. - * - * @return string - */ - public static function rest_get_plugin_install_hash() { - return 'NFD_ONBOARDING_' . hash( 'sha256', NFD_ONBOARDING_VERSION . wp_salt( 'nonce' ) . site_url() ); - } - - /** - * Verify Plugin Install Hash Value. - * - * @param string $hash Hash Value. - * @return boolean - */ - public static function rest_verify_plugin_install_hash( $hash ) { - return self::rest_get_plugin_install_hash() === $hash; - } - /** * Confirm REST API caller has ADMIN user capabilities. * @@ -57,8 +37,8 @@ public static function is_authorized_admin() { */ public static function rest_can_manage_themes() { return \is_user_logged_in() && - \current_user_can( self::INSTALL_THEMES ) && - \current_user_can( self::EDIT_THEMES ); + \current_user_can( self::INSTALL_THEMES ) && + \current_user_can( self::EDIT_THEMES ); } /** @@ -69,5 +49,4 @@ public static function rest_can_manage_themes() { public static function custom_post_authorized_admin() { return \current_user_can( 'edit_posts' ) && \current_user_can( self::ADMIN ); } - -} // END \NewfoldLabs\WP\Module\Onboarding\Permissions() +} diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index 750f5ae91..177b94dbb 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -1,15 +1,10 @@ namespace, - $this->rest_base . '/approved', - array( - array( - 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_approved_plugins' ), - 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), - ), - ) - ); \register_rest_route( $this->namespace, @@ -54,33 +38,7 @@ public function register_routes() { array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'initialize' ), - 'permission_callback' => array( $this, 'check_install_permissions' ), - ), - ) - ); - - \register_rest_route( - $this->namespace, - $this->rest_base . '/install', - array( - array( - 'methods' => \WP_REST_Server::CREATABLE, - 'callback' => array( $this, 'install' ), - 'args' => $this->get_install_plugin_args(), - 'permission_callback' => array( $this, 'check_install_permissions' ), - ), - ) - ); - - \register_rest_route( - $this->namespace, - $this->rest_base . '/status', - array( - array( - 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_status' ), - 'args' => $this->get_status_args(), - 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + 'permission_callback' => array( PluginInstaller::class, 'check_install_permissions' ), ), ) ); @@ -98,69 +56,12 @@ public function register_routes() { 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'set_site_features' ), 'args' => $this->set_site_features_args(), - 'permission_callback' => array( $this, 'check_install_permissions' ), + 'permission_callback' => array( PluginInstaller::class, 'check_install_permissions' ), ), ) ); } - /** - * Get approved plugin slugs, urls and domains. - * - * @return \WP_REST_Response - */ - public function get_approved_plugins() { - - return new \WP_REST_Response( - Plugins::get_approved(), - 200 - ); - } - - /** - * Get args for the install route. - * - * @return array - */ - public function get_install_plugin_args() { - return array( - 'plugin' => array( - 'type' => 'string', - 'required' => true, - ), - 'activate' => array( - 'type' => 'boolean', - 'default' => false, - ), - 'queue' => array( - 'type' => 'boolean', - 'default' => true, - ), - 'priority' => array( - 'type' => 'integer', - 'default' => 0, - ), - ); - } - - /** - * Get the plugin status check arguments. - * - * @return array - */ - public function get_status_args() { - return array( - 'plugin' => array( - 'type' => 'string', - 'required' => true, - ), - 'activated' => array( - 'type' => 'boolean', - 'default' => true, - ), - ); - } - /** * Get the set site features arguments. * @@ -175,19 +76,6 @@ public function set_site_features_args() { ); } - /** - * Verify caller has permissions to install plugins. - * - * @param \WP_REST_Request $request the incoming request object. - * - * @return boolean - */ - public function check_install_permissions( \WP_REST_Request $request ) { - $install_hash = $request->get_header( 'X-NFD-ONBOARDING' ); - return Permissions::rest_verify_plugin_install_hash( $install_hash ) - && Permissions::rest_is_authorized_admin(); - } - /** * Queue in the initial list of plugins to be installed. * @@ -195,7 +83,7 @@ public function check_install_permissions( \WP_REST_Request $request ) { */ public function initialize() { - if ( PluginInstallTaskManager::queue_initial_installs() ) { + if ( PluginService::queue_initial_installs() ) { return new \WP_REST_Response( array(), 202 @@ -208,108 +96,13 @@ public function initialize() { ); } - /** - * Install the requested plugin via a zip url (or) slug. - * - * @param \WP_REST_Request $request the incoming request object. - * - * @return \WP_REST_Response|\WP_Error - */ - public function install( \WP_REST_Request $request ) { - $plugin = $request->get_param( 'plugin' ); - $activate = $request->get_param( 'activate' ); - $queue = $request->get_param( 'queue' ); - $priority = $request->get_param( 'priority' ); - - // Checks if a plugin with the given slug and activation criteria already exists. - if ( PluginInstaller::exists( $plugin, $activate ) ) { - return new \WP_REST_Response( - array(), - 200 - ); - } - - // Queue the plugin install if specified in the request. - if ( $queue ) { - // Add a new PluginInstallTask to the Plugin install queue. - PluginInstallTaskManager::add_to_queue( - new PluginInstallTask( - $plugin, - $activate, - $priority - ) - ); - - return new \WP_REST_Response( - array(), - 202 - ); - } - - // Execute the task if it need not be queued. - $plugin_install_task = new PluginInstallTask( $plugin, $activate ); - - return $plugin_install_task->execute(); - } - - /** - * Returns the status of a given plugin slug. - * - * @param \WP_REST_Request $request the incoming request object. - * @return \WP_REST_Response - */ - public function get_status( \WP_REST_Request $request ) { - $plugin = $request->get_param( 'plugin' ); - $activated = $request->get_param( 'activated' ); - - if ( PluginInstaller::exists( $plugin, $activated ) ) { - return new \WP_REST_Response( - array( - 'status' => $activated ? 'activated' : 'installed', - ), - 200 - ); - } - - $position_in_queue = PluginInstallTaskManager::status( $plugin ); - - if ( false !== $position_in_queue ) { - return new \WP_REST_Response( - array( - 'status' => 'installing', - 'estimate' => ( ( $position_in_queue + 1 ) * 30 ), - ), - 200 - ); - } - - $in_progress_plugin = \get_option( Options::get_option_name( 'plugins_init_status' ), '' ); - if ( $in_progress_plugin === $plugin ) { - return new \WP_REST_Response( - array( - 'status' => 'installing', - 'estimate' => 30, - ), - 200 - ); - } - - return new \WP_REST_Response( - array( - 'status' => 'inactive', - ), - 200 - ); - - } - /** * Retrieves all the site features. * * @return array|\WP_Error */ public function get_site_features() { - return SiteFeatures::get_with_selections(); + return SiteFeatures::get_with_selections(); } /** @@ -320,9 +113,8 @@ public function get_site_features() { * @return \WP_REST_Response|\WP_Error */ public function set_site_features( \WP_REST_Request $request ) { - - $plugin_body = json_decode( $request->get_body(), true ); - $plugins = isset( $plugin_body['plugins'] ) ? $plugin_body['plugins'] : false; + $plugin_body = json_decode( $request->get_body(), true ); + $plugins = isset( $plugin_body['plugins'] ) ? $plugin_body['plugins'] : false; if ( ! $plugins ) { return new \WP_Error( @@ -332,31 +124,6 @@ public function set_site_features( \WP_REST_Request $request ) { ); } - foreach ( $plugins as $plugin => $decision ) { - if ( $decision ) { - // If the Plugin exists and is activated - if ( PluginInstaller::exists( $plugin, $decision ) ) { - continue; - } - - PluginInstallTaskManager::add_to_queue( - new PluginInstallTask( - $plugin, - true - ) - ); - } else { - PluginUninstallTaskManager::add_to_queue( - new PluginUninstallTask( - $plugin - ) - ); - } - } - - return new \WP_REST_Response( - array(), - 202 - ); + return PluginService::set_site_features( $plugins ); } } diff --git a/includes/RestApi/Themes/ThemeInstallerController.php b/includes/RestApi/Themes/ThemeInstallerController.php index d7842dbe1..dccbaf02a 100644 --- a/includes/RestApi/Themes/ThemeInstallerController.php +++ b/includes/RestApi/Themes/ThemeInstallerController.php @@ -2,18 +2,17 @@ namespace NewfoldLabs\WP\Module\Onboarding\RestApi\Themes; use NewfoldLabs\WP\Module\Onboarding\Permissions; -use NewfoldLabs\WP\Module\Onboarding\Services\ThemeInstaller; -use NewfoldLabs\WP\Module\Onboarding\TaskManagers\ThemeInstallTaskManager; -use NewfoldLabs\WP\Module\Onboarding\Tasks\ThemeInstallTask; +use NewfoldLabs\WP\Module\Onboarding\Services\ThemeService; + /** * Controller defining API's for theme install related functionalities. */ class ThemeInstallerController extends \WP_REST_Controller { - /** - * The namespace of this controller's route. - * - * @var string - */ + /** + * The namespace of this controller's route. + * + * @var string + */ protected $namespace = 'newfold-onboarding/v1'; /** @@ -38,85 +37,15 @@ public function register_routes() { ), ) ); - - \register_rest_route( - $this->namespace, - $this->rest_base . '/install', - array( - array( - 'methods' => \WP_REST_Server::CREATABLE, - 'callback' => array( $this, 'install' ), - 'args' => $this->get_install_theme_args(), - 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), - ), - ) - ); - - \register_rest_route( - $this->namespace, - $this->rest_base . '/status', - array( - array( - 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_status' ), - 'args' => $this->get_status_args(), - 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), - ), - ) - ); - } - - /** - * Get args for the install route. - * - * @return array - */ - public function get_install_theme_args() { - return array( - 'theme' => array( - 'type' => 'string', - 'required' => true, - ), - 'activate' => array( - 'type' => 'boolean', - 'default' => false, - ), - 'queue' => array( - 'type' => 'boolean', - 'default' => true, - ), - 'priority' => array( - 'type' => 'integer', - 'default' => 0, - ), - ); } /** - * Get the theme status check arguments. + * Queue in the initial list of themes to be installed. * - * @return array + * @return \WP_REST_Response */ - public function get_status_args() { - return array( - 'theme' => array( - 'type' => 'string', - 'required' => true, - ), - 'activated' => array( - 'type' => 'boolean', - 'default' => true, - ), - ); - } - - /** - * Queue in the initial list of themes to be installed. - * - * @return \WP_REST_Response - */ public static function initialize() { - if ( ThemeInstallTaskManager::queue_initial_installs() ) { + if ( ThemeService::queue_initial_installs() ) { return new \WP_REST_Response( array(), 202 @@ -128,88 +57,4 @@ public static function initialize() { 500 ); } - - /** - * Install the requested theme via a slug (theme). - * - * @param \WP_REST_Request $request The request object. - * - * @return \WP_REST_Response|\WP_Error - */ - public static function install( \WP_REST_Request $request ) { - $theme = $request->get_param( 'theme' ); - $activate = $request->get_param( 'activate' ); - $queue = $request->get_param( 'queue' ); - $priority = $request->get_param( 'priority' ); - - // Checks if a theme with the given slug and activation criteria already exists. - if ( ThemeInstaller::exists( $theme, $activate ) ) { - return new \WP_REST_Response( - array(), - 200 - ); - } - - // Queue the theme install if specified in the request. - if ( $queue ) { - ThemeInstallTaskManager::add_to_queue( - new ThemeInstallTask( - $theme, - $activate, - $priority - ) - ); - - return new \WP_REST_Response( - array(), - 202 - ); - } - - // Execute the task if it need not be queued. - $theme_install_task = new ThemeInstallTask( $theme, $activate ); - - return $theme_install_task->execute(); - } - - /** - * Returns the status of a given theme slug. - * - * @param \WP_REST_Request $request The request object - * - * @return \WP_REST_Response - */ - public function get_status( \WP_REST_Request $request ) { - $theme = $request->get_param( 'theme' ); - $activated = $request->get_param( 'activated' ); - - if ( ThemeInstaller::exists( $theme, $activated ) ) { - return new \WP_REST_Response( - array( - 'status' => $activated ? 'activated' : 'installed', - ), - 200 - ); - } - - $position_in_queue = ThemeInstallTaskManager::status( $theme ); - - if ( false !== $position_in_queue ) { - return new \WP_REST_Response( - array( - 'status' => 'installing', - 'estimate' => ( ( $position_in_queue + 1 ) * 10 ), - ), - 200 - ); - } - - return new \WP_REST_Response( - array( - 'status' => 'inactive', - ), - 200 - ); - - } } diff --git a/includes/Services/FlowService.php b/includes/Services/FlowService.php index eb773e8c7..29311c09b 100644 --- a/includes/Services/FlowService.php +++ b/includes/Services/FlowService.php @@ -5,8 +5,8 @@ use NewfoldLabs\WP\Module\Onboarding\Data\Flows; use NewfoldLabs\WP\Module\Onboarding\Data\Options; use NewfoldLabs\WP\Module\Onboarding\Data\Preview; -use NewfoldLabs\WP\Module\Onboarding\TaskManagers\PluginInstallTaskManager; -use NewfoldLabs\WP\Module\Onboarding\Tasks\PluginInstallTask; +use NewfoldLabs\WP\Module\Installer\TaskManagers\PluginInstallTaskManager; +use NewfoldLabs\WP\Module\Installer\Tasks\PluginInstallTask; use NewfoldLabs\WP\Module\Data\SiteClassification\PrimaryType; use NewfoldLabs\WP\Module\Data\SiteClassification\SecondaryType; diff --git a/includes/Services/PluginInstaller.php b/includes/Services/PluginInstaller.php deleted file mode 100644 index 89d2eb497..000000000 --- a/includes/Services/PluginInstaller.php +++ /dev/null @@ -1,378 +0,0 @@ - 400 ) - ); - } - - $status = self::install_from_zip( $plugin, $activate ); - if ( \is_wp_error( $status ) ) { - return $status; - } - - return new \WP_REST_Response( - array(), - 201 - ); - } - - // If it is not a zip URL then check if it is an approved slug. - $plugin = \sanitize_text_field( $plugin ); - if ( self::is_nfd_slug( $plugin ) ) { - // [TODO] Better handle mu-plugins and direct file downloads. - if ( 'nfd_slug_endurance_page_cache' === $plugin ) { - return self::install_endurance_page_cache(); - } - $plugin_path = $plugins_list['nfd_slugs'][ $plugin ]['path']; - if ( ! self::is_plugin_installed( $plugin_path ) ) { - $status = self::install_from_zip( $plugins_list['nfd_slugs'][ $plugin ]['url'], $activate ); - if ( \is_wp_error( $status ) ) { - return $status; - } - } - if ( $activate && ! \is_plugin_active( $plugin_path ) ) { - $status = \activate_plugin( $plugin_path ); - if ( \is_wp_error( $status ) ) { - $status->add_data( array( 'status' => 500 ) ); - - return $status; - } - } - return new \WP_REST_Response( - array(), - 201 - ); - } - - if ( ! isset( $plugins_list['wp_slugs'][ $plugin ] ) ) { - return new \WP_Error( - 'plugin-error', - "You do not have permission to install {$plugin}.", - array( 'status' => 400 ) - ); - } - - $plugin_path = $plugins_list['wp_slugs'][ $plugin ]['path']; - $plugin_post_install_callback = isset( $plugins_list['wp_slugs'][ $plugin ]['post_install_callback'] ) - ? $plugins_list['wp_slugs'][ $plugin ]['post_install_callback'] - : false; - if ( ! self::is_plugin_installed( $plugin_path ) ) { - $status = self::install_from_wordpress( $plugin, $activate ); - if ( \is_wp_error( $status ) ) { - return $status; - } - if ( is_callable( $plugin_post_install_callback ) ) { - $plugin_post_install_callback(); - } - } - - if ( $activate && ! \is_plugin_active( $plugin_path ) ) { - $status = \activate_plugin( $plugin_path ); - if ( \is_wp_error( $status ) ) { - $status->add_data( array( 'status' => 500 ) ); - - return $status; - } - } - - return new \WP_REST_Response( - array(), - 201 - ); - } - - /** - * Install a plugin from wordpress.org. - * - * @param string $plugin The wp_slug to install. - * @param boolean $activate Whether to activate the plugin after install. - * @return \WP_REST_Response|\WP_Error - */ - public static function install_from_wordpress( $plugin, $activate ) { - require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; - - $api = \plugins_api( - 'plugin_information', - array( - 'slug' => $plugin, - 'fields' => array( - 'sections' => false, - 'language_packs' => true, - ), - ) - ); - - if ( is_wp_error( $api ) ) { - if ( false !== strpos( $api->get_error_message(), 'Plugin not found.' ) ) { - $api->add_data( array( 'status' => 404 ) ); - } else { - $api->add_data( array( 'status' => 500 ) ); - } - - return $api; - } - - $status = self::install_from_zip( $api->download_link, $activate ); - if ( \is_wp_error( $status ) ) { - return $status; - } - - return new \WP_REST_Response( - array(), - 200 - ); - } - - /** - * Install the plugin from a custom ZIP. - * - * @param string $url The ZIP URL to install from. - * @param boolean $activate Whether to activate the plugin after install. - * @return \WP_REST_Response|\WP_Error - */ - public static function install_from_zip( $url, $activate ) { - require_once ABSPATH . 'wp-admin/includes/file.php'; - require_once ABSPATH . 'wp-admin/includes/misc.php'; - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; - - \wp_cache_flush(); - $skin = new \WP_Ajax_Upgrader_Skin(); - $upgrader = new \Plugin_Upgrader( $skin ); - - $result = $upgrader->install( $url ); - if ( \is_wp_error( $result ) ) { - $result->add_data( array( 'status' => 500 ) ); - - return $result; - } - if ( \is_wp_error( $skin->result ) ) { - $skin->result->add_data( array( 'status' => 500 ) ); - - return $skin->result; - } - if ( $skin->get_errors()->has_errors() ) { - $error = $skin->get_errors(); - $error->add_data( array( 'status' => 500 ) ); - - return $error; - } - if ( is_null( $result ) ) { - // Pass through the error from WP_Filesystem if one was raised. - if ( $wp_filesystem instanceof \WP_Filesystem_Base - && \is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() - ) { - return new \WP_Error( - 'unable_to_connect_to_filesystem', - $wp_filesystem->errors->get_error_message(), - array( 'status' => 500 ) - ); - } - - return new \WP_Error( - 'unable_to_connect_to_filesystem', - 'Unable to connect to the filesystem.', - array( 'status' => 500 ) - ); - } - - $plugin_file = $upgrader->plugin_info(); - if ( ! $plugin_file ) { - return new \WP_Error( - 'unable_to_determine_installed_plugin', - 'Unable to determine what plugin was installed.', - array( 'status' => 500 ) - ); - } - - if ( $activate && ! \is_plugin_active( $plugin_file ) ) { - $status = \activate_plugin( $plugin_file ); - if ( \is_wp_error( $status ) ) { - $status->add_data( array( 'status' => 500 ) ); - - return $status; - } - } - - return new \WP_REST_Response( - array(), - 200 - ); - } - - /** - * Checks if a given slug is a valid nfd_slug. Ref: includes/Data/Plugins.php for nfd_slug. - * - * @param string $plugin Slug of the plugin. - * @return boolean - */ - public static function is_nfd_slug( $plugin ) { - $plugins_list = Plugins::get(); - if ( isset( $plugins_list['nfd_slugs'][ $plugin ]['approved'] ) ) { - return true; - } - return false; - } - - /** - * Determines if a plugin has already been installed. - * - * @param string $plugin_path Path to the plugin's header file. - * @return boolean - */ - public static function is_plugin_installed( $plugin_path ) { - if ( ! function_exists( 'get_plugins' ) ) { - require_once ABSPATH . 'wp-admin/includes/plugin.php'; - } - $all_plugins = \get_plugins(); - if ( ! empty( $all_plugins[ $plugin_path ] ) ) { - return true; - } else { - return false; - } - } - - /** - * Get the type of plugin slug. Ref: includes/Data/Plugins.php for the different types. - * - * @param string $plugin The plugin slug to retrieve the type. - * @return string - */ - public static function get_plugin_type( $plugin ) { - if ( \wp_http_validate_url( $plugin ) ) { - return 'urls'; - } - if ( self::is_nfd_slug( $plugin ) ) { - return 'nfd_slugs'; - } - return 'wp_slugs'; - } - - /** - * Get the path to the Plugin's header file. - * - * @param string $plugin The slug of the plugin. - * @param string $plugin_type The type of plugin. - * @return string - */ - public static function get_plugin_path( $plugin, $plugin_type ) { - $plugin_list = Plugins::get(); - return $plugin_list[ $plugin_type ][ $plugin ]['path']; - } - - /** - * Checks if a plugin with the given slug and activation criteria already exists. - * - * @param string $plugin The slug of the plugin to check for - * @param boolean $activate The activation criteria. - * @return boolean - */ - public static function exists( $plugin, $activate ) { - $plugin_type = self::get_plugin_type( $plugin ); - $plugin_path = self::get_plugin_path( $plugin, $plugin_type ); - if ( ! self::is_plugin_installed( $plugin_path ) ) { - return false; - } - - if ( $activate && ! \is_plugin_active( $plugin_path ) ) { - return false; - } - return true; - } - - /** - * Install the Endurance Page Cache Plugin - * - * [TODO] Make this generic for mu-plugins and direct file downloads. - * - * @return \WP_REST_Response|\WP_Error - */ - public static function install_endurance_page_cache() { - if ( ! self::connect_to_filesystem() ) { - return new \WP_Error( - 'nfd_onboarding_error', - 'Could not connect to the filesystem.', - array( 'status' => 500 ) - ); - } - - global $wp_filesystem; - - $plugin_list = Plugins::get(); - $plugin_url = $plugin_list['nfd_slugs']['nfd_slug_endurance_page_cache']['url']; - $plugin_path = $plugin_list['nfd_slugs']['nfd_slug_endurance_page_cache']['path']; - - if ( $wp_filesystem->exists( $plugin_path ) ) { - return new \WP_REST_Response( - array(), - 200 - ); - } - - if ( ! $wp_filesystem->is_dir( WP_CONTENT_DIR . '/mu-plugins' ) ) { - $wp_filesystem->mkdir( WP_CONTENT_DIR . '/mu-plugins' ); - } - - $request = \wp_remote_get( $plugin_url ); - if ( \is_wp_error( $request ) ) { - return $request; - } - - $wp_filesystem->put_contents( $plugin_path, $request['body'], FS_CHMOD_FILE ); - - return new \WP_REST_Response( - array(), - 200 - ); - } - - /** - * Establishes a connection to the wp_filesystem. - * - * @return boolean - */ - protected static function connect_to_filesystem() { - require_once ABSPATH . 'wp-admin/includes/file.php'; - - // We want to ensure that the user has direct access to the filesystem. - $access_type = \get_filesystem_method(); - if ( 'direct' !== $access_type ) { - return false; - } - - $creds = \request_filesystem_credentials( site_url() . '/wp-admin', '', false, false, array() ); - - if ( ! \WP_Filesystem( $creds ) ) { - return false; - } - - return true; - } - -} diff --git a/includes/Services/PluginService.php b/includes/Services/PluginService.php new file mode 100644 index 000000000..69fb05595 --- /dev/null +++ b/includes/Services/PluginService.php @@ -0,0 +1,93 @@ + $decision ) { + if ( $decision ) { + // If the Plugin exists and is activated + if ( PluginInstaller::exists( $plugin, $decision ) ) { + continue; + } + + PluginInstallTaskManager::add_to_queue( + new PluginInstallTask( + $plugin, + true + ) + ); + } else { + PluginUninstallTaskManager::add_to_queue( + new PluginUninstallTask( + $plugin + ) + ); + } + } + + return new \WP_REST_Response( + array(), + 202 + ); + } +} diff --git a/includes/Services/PluginUninstaller.php b/includes/Services/PluginUninstaller.php deleted file mode 100644 index f24ffe623..000000000 --- a/includes/Services/PluginUninstaller.php +++ /dev/null @@ -1,154 +0,0 @@ - 500 ) - ); - } - - // Removes directory and files of a plugin - $deleted = \delete_plugins( array( $plugin_path ) ); - if ( ! $deleted || is_wp_error( $deleted ) ) { - return new \WP_Error( - 'nfd_onboarding_error', - 'Unable to Delete the Plugin', - array( 'status' => 500 ) - ); - } - - return true; - } - -} diff --git a/includes/Services/ThemeInstaller.php b/includes/Services/ThemeInstaller.php deleted file mode 100644 index d4b8ed579..000000000 --- a/includes/Services/ThemeInstaller.php +++ /dev/null @@ -1,195 +0,0 @@ -exists() ) { - $status = self::install_from_zip( - $theme_list['nfd_slugs'][ $theme ]['url'], - $activate, - $stylesheet - ); - if ( \is_wp_error( $status ) ) { - return $status; - } - - return new \WP_REST_Response( - array(), - 201 - ); - } - - // If specified then activate the theme even if it already installed. - if ( $activate && ( ( \wp_get_theme() )->get( 'TextDomain' ) !== $stylesheet ) ) { - $status = \switch_theme( $stylesheet ); - } - } - - return new \WP_REST_Response( - array(), - 201 - ); - } - - /** - * Install theme from an custom zip url if not already installed. Activate and switch to the theme, if specified. - * - * @param string $url The ZIP URL to install the theme from. - * @param boolean $activate Whether to activate the plugin after install. - * @param string $stylesheet Theme Stylesheet Name. - * @return \WP_REST_Response|\WP_Error - */ - public static function install_from_zip( $url, $activate, $stylesheet ) { - require_once ABSPATH . 'wp-admin/includes/file.php'; - require_once ABSPATH . 'wp-admin/includes/misc.php'; - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; - - $skin = new \WP_Ajax_Upgrader_Skin(); - $upgrader = new \Theme_Upgrader( $skin ); - $result = $upgrader->install( $url ); - - if ( is_wp_error( $result ) ) { - return $result; - } - - if ( is_wp_error( $skin->result ) ) { - return $skin->result; - } - - if ( $skin->get_errors()->has_errors() ) { - return new \WP_Error( - 'unable_to_install_theme', - $skin->get_error_messages(), - array( 'status' => 500 ) - ); - } - - if ( is_null( $result ) ) { - // Pass through the error from WP_Filesystem if one was raised. - if ( $wp_filesystem instanceof \WP_Filesystem_Base - && \is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() - ) { - return new \WP_Error( - 'unable_to_connect_to_filesystem', - $wp_filesystem->errors->get_error_message(), - array( 'status' => 500 ) - ); - } - - return new \WP_Error( - 'unable_to_connect_to_filesystem', - 'Unable to connect to the filesystem.', - array( 'status' => 500 ) - ); - } - - // Activate the theme if specified. - if ( $activate && ( ( \wp_get_theme() )->get( 'TextDomain' ) !== $stylesheet ) ) { - \switch_theme( $stylesheet ); - } - - return new \WP_REST_Response( - array(), - 201 - ); - - } - - /** - * Checks if a given slug is a valid nfd_slug. Ref: includes/Data/Themes.php for nfd_slug. - * - * @param string $theme Slug of the theme. - * @return boolean - */ - public static function is_nfd_slug( $theme ) { - $theme_list = Themes::get(); - if ( isset( $theme_list['nfd_slugs'][ $theme ]['approved'] ) ) { - return true; - } - return false; - } - - /** - * Retrieve Theme Stylesheet Name for a specified theme name and theme type. - * - * @param mixed $theme Slug of the theme present under includes/Data/Themes.php. - * @param mixed $theme_type Type of theme Ref: includes/Data/Themes.php for types of theme slugs. - * @return string|boolean - */ - public static function get_theme_stylesheet( $theme, $theme_type ) { - $theme_list = Themes::get(); - return isset( $theme_list[ $theme_type ][ $theme ]['stylesheet'] ) ? $theme_list[ $theme_type ][ $theme ]['stylesheet'] : false; - } - - /** - * Retrieve Theme Type - approved NFD Slug/WP Slug. - * - * @param string $theme Theme name - * @return string Type of theme. Ref: includes/Data/Themes.php for the different types. - */ - public static function get_theme_type( $theme ) { - if ( self::is_nfd_slug( $theme ) ) { - return 'nfd_slugs'; - } - return 'wp_slugs'; - } - - /** - * Determines if a theme has already been installed. - * - * @param string $stylesheet The stylesheet of the theme. - * @return boolean - */ - public static function is_theme_installed( $stylesheet ) { - return ( \wp_get_theme( $stylesheet ) )->exists(); - } - - /** - * Determines if a theme is already active. - * - * @param string $stylesheet The stylesheet of the theme. - * @return boolean - */ - public static function is_theme_active( $stylesheet ) { - return ( ( \wp_get_theme() )->get( 'TextDomain' ) ) === $stylesheet; - } - - /** - * Checks if a theme with the given slug and activation criteria already exists. - * - * @param string $theme Theme name - * @param string $activate Activation Criteria - * @return boolean - */ - public static function exists( $theme, $activate ) { - $theme_type = self::get_theme_type( $theme ); - $theme_stylesheet = self::get_theme_stylesheet( $theme, $theme_type ); - if ( ! self::is_theme_installed( $theme_stylesheet ) ) { - return false; - } - if ( $activate && ! self::is_theme_active( $theme_stylesheet ) ) { - return false; - } - return true; - } -} diff --git a/includes/Services/ThemeService.php b/includes/Services/ThemeService.php new file mode 100644 index 000000000..818adc528 --- /dev/null +++ b/includes/Services/ThemeService.php @@ -0,0 +1,46 @@ + 30, - 'display' => __( 'Once Every Thirty Seconds' ), - ); - } - - return $schedules; - } - - /** - * Queues the initial list of Plugin Installs for a flow. - * - * @return boolean - */ - public static function queue_initial_installs() { - - // Checks if the init_list of plugins have already been queued. - if ( \get_option( Options::get_option_name( 'plugins_init_status' ), 'init' ) !== 'init' ) { - return true; - } - - // Set option to installing to prevent re-queueing the init_list again on page load. - \update_option( Options::get_option_name( 'plugins_init_status' ), 'installing' ); - - // Get the initial list of plugins to be installed based on the plan. - $init_plugins = Plugins::get_init(); - - foreach ( $init_plugins as $init_plugin ) { - // Checks if a plugin with the given slug and activation criteria already exists. - if ( ! PluginInstaller::exists( $init_plugin['slug'], $init_plugin['activate'] ) ) { - // Add a new PluginInstallTask to the Plugin install queue. - self::add_to_queue( - new PluginInstallTask( - $init_plugin['slug'], - $init_plugin['activate'], - $init_plugin['priority'] - ) - ); - } - } - - return true; - } - - /** - * Queue out a PluginInstallTask with the highest priority in the plugin install queue and execute it. - * - * @return array|false - */ - public function install() { - /* - Get the plugins queued up to be installed, the PluginInstall task gets - converted to an associative array before storing it in the option. - */ - $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); - - /* - Conversion of the max heap to an array will always place the PluginInstallTask with the highest - priority at the beginning of the array - */ - $plugin_to_install = array_shift( $plugins ); - - // Update the plugin install queue. - \update_option( Options::get_option_name( self::$queue_name ), $plugins ); - - // Recreate the PluginInstall task from the associative array. - $plugin_install_task = new PluginInstallTask( - $plugin_to_install['slug'], - $plugin_to_install['activate'], - $plugin_to_install['priority'], - $plugin_to_install['retries'] - ); - - // Update status to the current slug being installed. - \update_option( Options::get_option_name( 'plugins_init_status' ), $plugin_install_task->get_slug() ); - - // Execute the PluginInstall Task. - $status = $plugin_install_task->execute(); - if ( \is_wp_error( $status ) ) { - - // If there is an error, then increase the retry count for the task. - $plugin_install_task->increment_retries(); - - // Get Latest Value of the install queue - $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); - - /* - If the number of retries have not exceeded the limit - then re-queue the task at the end of the queue to be retried. - */ - if ( $plugin_install_task->get_retries() <= self::$retry_limit ) { - array_push( $plugins, $plugin_install_task->to_array() ); - - // Update the plugin install queue. - \update_option( Options::get_option_name( self::$queue_name ), $plugins ); - } - } - - // If there are no more plugins to be installed then change the status to completed. - if ( empty( $plugins ) ) { - return \update_option( Options::get_option_name( 'plugins_init_status' ), 'completed' ); - } - - return true; - } - - /** - * Adds a new PluginInstallTask to the Plugin Install queue. - * The Task will be inserted at an appropriate position in the queue based on it's priority. - * - * @param PluginInstallTask $plugin_install_task The task to be inserted. - * @return array|false - */ - public static function add_to_queue( PluginInstallTask $plugin_install_task ) { - /* - Get the plugins queued up to be installed, the PluginInstall task gets - converted to an associative array before storing it in the option. - */ - $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); - - $queue = new PriorityQueue(); - foreach ( $plugins as $queued_plugin ) { - /* - Check if there is an already existing PluginInstallTask in the queue - for a given slug and activation criteria. - */ - if ( $queued_plugin['slug'] === $plugin_install_task->get_slug() - && $queued_plugin['activate'] === $plugin_install_task->get_activate() ) { - return false; - } - $queue->insert( $queued_plugin, $queued_plugin['priority'] ); - } - - // Insert a new PluginInstallTask at the appropriate position in the queue. - $queue->insert( - $plugin_install_task->to_array(), - $plugin_install_task->get_priority() - ); - - return \update_option( Options::get_option_name( self::$queue_name ), $queue->to_array() ); - } - - /** - * Removes a PluginInstallTask from the queue. - * - * @param string $plugin The slug of the task to remove. - * @return array - */ - public static function remove_from_queue( $plugin ) { - /* - Get the plugins queued up to be installed, the PluginInstall task gets - converted to an associative array before storing it in the option. - */ - $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); - - $queue = new PriorityQueue(); - foreach ( $plugins as $queued_plugin ) { - /* - If the Plugin slug does not match add it back to the queue. - */ - if ( $queued_plugin['slug'] !== $plugin ) { - $queue->insert( $queued_plugin, $queued_plugin['priority'] ); - } - } - - return \update_option( Options::get_option_name( self::$queue_name ), $queue->to_array() ); - } - - /** - * Get the status of a given plugin slug from the queue. - * - * @param string $plugin The slug of the plugin. - * @return boolean - */ - public static function status( $plugin ) { - $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); - return array_search( $plugin, array_column( $plugins, 'slug' ), true ); - } - - /** - * Reset the Plugin install status and the queue. - * - * @return void - */ - public static function reset_install_status() { - \delete_option( Options::get_option_name( 'plugins_init_status' ) ); - \delete_option( Options::get_option_name( 'plugin_install_queue' ) ); - } -} diff --git a/includes/TaskManagers/PluginUninstallTaskManager.php b/includes/TaskManagers/PluginUninstallTaskManager.php deleted file mode 100644 index 754b282be..000000000 --- a/includes/TaskManagers/PluginUninstallTaskManager.php +++ /dev/null @@ -1,183 +0,0 @@ - 10, - 'display' => __( 'Once Every Ten Seconds' ), - ); - } - - return $schedules; - } - - /** - * Queue out a PluginUninstallTask with the highest priority in the plugin uninstall queue and execute it. - * - * @return array|false - */ - public function uninstall() { - /* - Get the plugins queued up to be uninstalled, the PluginUninstall task gets - converted to an associative array before storing it in the option. - */ - $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); - - /* - Conversion of the max heap to an array will always place the PluginUninstallTask with the highest - priority at the beginning of the array - */ - $plugin_to_uninstall = array_shift( $plugins ); - - // Update the plugin uninstall queue. - \update_option( Options::get_option_name( self::$queue_name ), $plugins ); - - // Recreate the PluginInstall task from the associative array. - $plugin_uninstall_task = new PluginUninstallTask( - $plugin_to_uninstall['slug'], - $plugin_to_uninstall['priority'], - $plugin_to_uninstall['retries'] - ); - - // Execute the PluginUninstall Task. - $status = $plugin_uninstall_task->execute(); - if ( \is_wp_error( $status ) ) { - - // If there is an error, then increase the retry count for the task. - $plugin_uninstall_task->increment_retries(); - - /* - If the number of retries have not exceeded the limit - then re-queue the task at the end of the queue to be retried. - */ - if ( $plugin_uninstall_task->get_retries() <= self::$retry_limit ) { - array_push( $plugins, $plugin_uninstall_task->to_array() ); - - // Update the plugin install queue. - \update_option( Options::get_option_name( self::$queue_name ), $plugins ); - } - } - - return true; - } - - /** - * Adds a new PluginUninstallTask to the Plugin Uninstall queue. - * The Task will be inserted at an appropriate position in the queue based on it's priority. - * - * @param PluginUninstallTask $plugin_uninstall_task Plugin Task Details - * @return array|false - */ - public static function add_to_queue( PluginUninstallTask $plugin_uninstall_task ) { - /* - Get the plugins queued up to be uninstalled, the PluginUninstall task gets - converted to an associative array before storing it in the option. - */ - $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); - - $position_in_queue = PluginInstallTaskManager::status( $plugin_uninstall_task->get_slug() ); - if ( false !== $position_in_queue && 0 !== $position_in_queue ) { - PluginInstallTaskManager::remove_from_queue( - $plugin_uninstall_task->get_slug() - ); - - return true; - } - - $plugin_list = Plugins::get_squashed(); - // Gets the specified path for the Plugin from the predefined list - $plugin_path = $plugin_list[ $plugin_uninstall_task->get_slug() ]['path']; - - if ( ! PluginUninstaller::is_plugin_installed( $plugin_path ) ) { - return true; - } - - $queue = new PriorityQueue(); - foreach ( $plugins as $queued_plugin ) { - /* - Check if there is an already existing PluginUninstallTask in the queue - for a given slug. - */ - if ( $queued_plugin['slug'] === $plugin_uninstall_task->get_slug() ) { - return false; - } - $queue->insert( $queued_plugin, $queued_plugin['priority'] ); - } - - // Insert a new PluginUninstallTask at the appropriate position in the queue. - $queue->insert( - $plugin_uninstall_task->to_array(), - $plugin_uninstall_task->get_priority() - ); - - return \update_option( Options::get_option_name( self::$queue_name ), $queue->to_array() ); - } - - /** - * Returns the status of given plugin slug - uninstalling/completed. - * - * @param string $plugin Plugin Slug - * @return string|false - */ - public static function status( $plugin ) { - $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); - return array_search( $plugin, array_column( $plugins, 'slug' ) ); - } -} diff --git a/includes/TaskManagers/TaskManager.php b/includes/TaskManagers/TaskManager.php deleted file mode 100644 index 5642b8203..000000000 --- a/includes/TaskManagers/TaskManager.php +++ /dev/null @@ -1,32 +0,0 @@ -task_managers as $task_manager ) { - if ( ! empty( get_option( Options::get_option_name( $task_manager::get_queue_name() ), array() ) ) ) { - new $task_manager(); - } - } - } -} diff --git a/includes/TaskManagers/ThemeInstallTaskManager.php b/includes/TaskManagers/ThemeInstallTaskManager.php deleted file mode 100644 index b981ce365..000000000 --- a/includes/TaskManagers/ThemeInstallTaskManager.php +++ /dev/null @@ -1,204 +0,0 @@ - 10, - 'display' => __( 'Once Every Ten Seconds' ), - ); - } - - return $schedules; - } - - /** - * Retrieve status of init_list of plugins being queued. - * - * @return boolean - */ - public static function queue_initial_installs() { - // Checks if the init_list of themes have already been queued. - if ( \get_option( Options::get_option_name( 'theme_init_status' ), 'init' ) !== 'init' ) { - return true; - } - - // Set option to installing to prevent re-queueing the init_list again on page load. - \update_option( Options::get_option_name( 'theme_init_status' ), 'installing' ); - - // Get the initial list of themes to be installed based on the plan. - $init_themes = Themes::get_init(); - foreach ( $init_themes as $init_theme ) { - // Checks if a theme with the given slug and activation criteria already exists. - if ( ! ThemeInstaller::exists( $init_theme['slug'], $init_theme['activate'] ) ) { - // Add a new ThemeInstallTask to the theme install queue. - self::add_to_queue( - new ThemeInstallTask( - $init_theme['slug'], - $init_theme['activate'], - $init_theme['priority'] - ) - ); - } - } - - return true; - } - - /** - * Queue out a ThemeInstallTask with the highest priority in the theme install queue and execute it. - * - * @return array|false - */ - public function install() { - /* - Get the theme install tasks queued up to be installed, the ThemeInstallTask gets - converted to an associative array before storing it in the option. - */ - $themes = \get_option( Options::get_option_name( self::$queue_name ), array() ); - - /* - Conversion of the max heap to an array will always place the ThemeInstallTask with the highest - priority at the beginning of the array - */ - $theme_to_install = array_shift( $themes ); - - // Recreate the ThemeInstallTask from the associative array. - $theme_install_task = new ThemeInstallTask( - $theme_to_install['slug'], - $theme_to_install['activate'], - $theme_to_install['priority'], - $theme_to_install['retries'] - ); - - // Update status to the current slug being installed. - \update_option( Options::get_option_name( 'theme_init_status' ), $theme_install_task->get_slug() ); - - // Execute the ThemeInstallTask. - $status = $theme_install_task->execute(); - if ( \is_wp_error( $status ) ) { - - // If there is an error, then increase the retry count for the task. - $theme_install_task->increment_retries(); - - /* - If the number of retries have not exceeded the limit - then re-queue the task at the end of the queue to be retried. - */ - if ( $theme_install_task->get_retries() <= self::$retry_limit ) { - array_push( $themes, $theme_install_task->to_array() ); - } - } - - // If there are no more themes to be installed then change the status to completed. - if ( empty( $themes ) ) { - \update_option( Options::get_option_name( 'theme_init_status' ), 'completed' ); - } - - // Update the theme install queue. - return \update_option( Options::get_option_name( self::$queue_name ), $themes ); - } - - /** - * Adds a new ThemeInstallTask to the Theme Install queue. - * The Task will be inserted at an appropriate position in the queue based on it's priority. - * - * @param ThemeInstallTask $theme_install_task Theme Install Task to add to the queue - * @return array|false - */ - public static function add_to_queue( ThemeInstallTask $theme_install_task ) { - /* - Get the ThemeInstallTasks queued up to be installed, the ThemeInstallTask gets - converted to an associative array before storing it in the option. - */ - $themes = \get_option( Options::get_option_name( self::$queue_name ), array() ); - - $queue = new PriorityQueue(); - foreach ( $themes as $queued_theme ) { - /* - Check if there is an already existing ThemeInstallTask in the queue - for a given slug and activation criteria. - */ - if ( $queued_theme['slug'] === $theme_install_task->get_slug() - && $queued_theme['activate'] === $theme_install_task->get_activate() ) { - return false; - } - $queue->insert( $queued_theme, $queued_theme['priority'] ); - } - - // Insert a new ThemeInstallTask at the appropriate position in the queue. - $queue->insert( - $theme_install_task->to_array(), - $theme_install_task->get_priority() - ); - - return \update_option( Options::get_option_name( self::$queue_name ), $queue->to_array() ); - } - - /** - * Returns the status of given plugin slug - installing/completed. - * - * @param string $theme Theme Slug - * @return string|false - */ - public static function status( $theme ) { - $themes = \get_option( Options::get_option_name( self::$queue_name ), array() ); - return array_search( $theme, array_column( $themes, 'slug' ) ); - } -} diff --git a/includes/Tasks/PluginInstallTask.php b/includes/Tasks/PluginInstallTask.php deleted file mode 100644 index b1911dfa0..000000000 --- a/includes/Tasks/PluginInstallTask.php +++ /dev/null @@ -1,121 +0,0 @@ -slug = $slug; - $this->activate = $activate; - $this->priority = $priority; - $this->retries = $retries; - } - - /** - * Retrieves Slug for the Plugin. - * - * @return string - */ - public function get_slug() { - return $this->slug; - } - - /** - * Retrieves Plugin Activation Status. - * - * @return boolean - */ - public function get_activate() { - return $this->activate; - } - - /** - * Retrieves Task Priority. - * - * @return int - */ - public function get_priority() { - return $this->priority; - } - - /** - * Retrieves Task Installation retry count. - * - * @return string - */ - public function get_retries() { - return $this->retries; - } - - /** - * Increments retry count. - * - * @return void - */ - public function increment_retries() { - $this->retries++; - } - - /** - * Installs the Plugin using the PluginInstaller Service. - * - * @return \WP_REST_Response|WP_Error - */ - public function execute() { - return PluginInstaller::install( $this->get_slug(), $this->get_activate() ); - } - - /** - * Convert the PluginInstallTask into an associative array. - * - * @return array - */ - public function to_array() { - return array( - 'slug' => $this->slug, - 'activate' => $this->activate, - 'priority' => $this->priority, - 'retries' => $this->retries, - ); - } -} diff --git a/includes/Tasks/PluginUninstallTask.php b/includes/Tasks/PluginUninstallTask.php deleted file mode 100644 index a59ce38fa..000000000 --- a/includes/Tasks/PluginUninstallTask.php +++ /dev/null @@ -1,103 +0,0 @@ -slug = $slug; - $this->priority = $priority; - $this->retries = $retries; - } - - /** - * Retrieves Slug for the Plugin. - * - * @return string - */ - public function get_slug() { - return $this->slug; - } - - /** - * Retrieves Task Priority. - * - * @return int - */ - public function get_priority() { - return $this->priority; - } - - /** - * Retrieves Task Installation retry count. - * - * @return string - */ - public function get_retries() { - return $this->retries; - } - - /** - * Increments retry count. - * - * @return void - */ - public function increment_retries() { - $this->retries++; - } - - /** - * Uninstalls the Plugin using the PluginUninstaller Service. - * - * @return \WP_REST_Response|\WP_Error - */ - public function execute() { - return PluginUninstaller::uninstall( $this->get_slug() ); - } - - /** - * Convert the PluginUninstallTask into an associative array. - * - * @return array - */ - public function to_array() { - return array( - 'slug' => $this->slug, - 'priority' => $this->priority, - 'retries' => $this->retries, - ); - } - -} diff --git a/includes/Tasks/Task.php b/includes/Tasks/Task.php deleted file mode 100644 index 916816dbe..000000000 --- a/includes/Tasks/Task.php +++ /dev/null @@ -1,22 +0,0 @@ -slug = $slug; - $this->activate = $activate; - $this->priority = $priority; - $this->retries = $retries; - } - - /** - * Retrieves Slug for the Theme. - * - * @return string - */ - public function get_slug() { - return $this->slug; - } - - /** - * Retrieves Theme Activation Status. - * - * @return boolean - */ - public function get_activate() { - return $this->activate; - } - - /** - * Retrieves Task Priority. - * - * @return int - */ - public function get_priority() { - return $this->priority; - } - - /** - * Retrieves Task Installation retry count. - * - * @return string - */ - public function get_retries() { - return $this->retries; - } - - /** - * Increments retry count. - * - * @return void - */ - public function increment_retries() { - $this->retries++; - } - - /** - * Installs the Theme using the ThemeInstaller Service. - * - * @return \WP_REST_Response|WP_Error - */ - public function execute() { - return ThemeInstaller::install( - $this->get_slug(), - $this->get_activate() - ); - } - - /** - * Convert the ThemeInstallTask into an associative array. - * - * @return array - */ - public function to_array() { - return array( - 'slug' => $this->slug, - 'activate' => $this->activate, - 'priority' => $this->priority, - 'retries' => $this->retries, - ); - } - -} diff --git a/includes/WP_Admin.php b/includes/WP_Admin.php index 77e9dc846..7f4a1d4d1 100644 --- a/includes/WP_Admin.php +++ b/includes/WP_Admin.php @@ -2,8 +2,8 @@ namespace NewfoldLabs\WP\Module\Onboarding; use NewfoldLabs\WP\Module\Onboarding\Data\Data; -use NewfoldLabs\WP\Module\Onboarding\TaskManagers\PluginInstallTaskManager; -use NewfoldLabs\WP\Module\Onboarding\TaskManagers\ThemeInstallTaskManager; +use NewfoldLabs\WP\Module\Onboarding\Services\PluginService; +use NewfoldLabs\WP\Module\Onboarding\Services\ThemeService; /** * Register Admin Page, Assets & Admin functionality with WordPress. @@ -115,11 +115,11 @@ public static function register_assets() { */ public static function initialize() { if ( ! empty( $_GET['nfd_plugins'] ) && 'true' === sanitize_text_field( $_GET['nfd_plugins'] ) ) { - PluginInstallTaskManager::queue_initial_installs(); + PluginService::queue_initial_installs(); } if ( ! empty( $_GET['nfd_themes'] ) && 'true' === sanitize_text_field( $_GET['nfd_themes'] ) ) { - ThemeInstallTaskManager::queue_initial_installs(); + ThemeService::queue_initial_installs(); } self::register_assets(); diff --git a/src/OnboardingSPA/utils/api/common.js b/src/OnboardingSPA/utils/api/common.js index 409c8aebc..c72367097 100644 --- a/src/OnboardingSPA/utils/api/common.js +++ b/src/OnboardingSPA/utils/api/common.js @@ -1,4 +1,4 @@ -import { onboardingRestBase, wpRestBase } from '../../../constants'; +import { onboardingRestBase, wpRestBase, installerRestBase } from '../../../constants'; export const onboardingRestURL = ( api ) => { return ( @@ -9,6 +9,12 @@ export const onboardingRestURL = ( api ) => { ); }; +export const installerRestURL = ( api ) => { + return ( + `${ installerRestBase }/${ api }` + ); +}; + export const wpRestURL = ( api ) => { return `${ wpRestBase }/${ api }`; }; diff --git a/src/OnboardingSPA/utils/api/plugins.js b/src/OnboardingSPA/utils/api/plugins.js index 5b36def29..c6587f156 100644 --- a/src/OnboardingSPA/utils/api/plugins.js +++ b/src/OnboardingSPA/utils/api/plugins.js @@ -1,6 +1,6 @@ import apiFetch from '@wordpress/api-fetch'; -import { onboardingRestURL } from './common'; +import { installerRestURL, onboardingRestURL } from './common'; import { getQueryParam } from '../index'; import { resolve } from './resolve'; import { NFD_PLUGINS_QUERY_PARAM } from '../../../constants'; @@ -14,9 +14,10 @@ export const init = () => { url: onboardingRestURL( 'plugins/initialize' ), method: 'POST', headers: { - 'X-NFD-ONBOARDING': window.nfdOnboarding.pluginInstallHash, + 'X-NFD-INSTALLER': window.nfdOnboarding.pluginInstallHash, }, } ).catch( ( error ) => { + // eslint-disable-next-line no-console console.error( error ); } ); }; @@ -45,7 +46,7 @@ export const setSiteFeatures = async ( pluginInstallHash, data ) => { url: onboardingRestURL( 'plugins/site-features' ), method: 'POST', headers: { - 'X-NFD-ONBOARDING': pluginInstallHash, + 'X-NFD-INSTALLER': pluginInstallHash, }, data, } ) diff --git a/src/OnboardingSPA/utils/api/themes.js b/src/OnboardingSPA/utils/api/themes.js index 273bba53b..3ac0af5ea 100644 --- a/src/OnboardingSPA/utils/api/themes.js +++ b/src/OnboardingSPA/utils/api/themes.js @@ -1,6 +1,6 @@ import apiFetch from '@wordpress/api-fetch'; -import { onboardingRestURL } from './common'; +import { installerRestURL, onboardingRestURL } from './common'; import { resolve } from './resolve'; import { getQueryParam } from '../index'; import { NFD_THEMES_QUERY_PARAM } from '../../../constants'; @@ -14,6 +14,7 @@ const init = () => { url: onboardingRestURL( 'themes/initialize' ), method: 'POST', } ).catch( ( error ) => { + // eslint-disable-next-line no-console console.error( error ); } ); }; @@ -25,7 +26,7 @@ const install = async ( theme, activate = true, queue = true ) => { return await resolve( apiFetch( { - url: onboardingRestURL( 'themes/install' ), + url: installerRestURL( 'themes/install' ), method: 'POST', data: { theme, diff --git a/src/constants.js b/src/constants.js index eed2f4c2b..ed5e7c509 100644 --- a/src/constants.js +++ b/src/constants.js @@ -7,8 +7,10 @@ export const wpSiteUrl = window.nfdOnboarding.siteUrl; export const wpRestURL = window.nfdOnboarding.restUrl; export const wpRestRoute = 'wp/v2'; export const onboardingRestRoute = 'newfold-onboarding/v1'; +export const installerRestRoute = 'newfold-installer/v1'; export const wpRestBase = `${ wpRestURL }/${ wpRestRoute }`; export const onboardingRestBase = `${ wpRestURL }/${ onboardingRestRoute }`; +export const installerRestBase = `${ wpRestURL }/${ installerRestRoute }`; export const wpAdminPage = `${ wpAdminUrl }index.php`; export const pluginDashboardPage = `${ window.nfdOnboarding.currentBrand?.pluginDashboardPage ?? wpAdminPage From 27e14ba37b77c720e788518dbb2788f38ff33251 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Mon, 29 May 2023 19:11:03 +0530 Subject: [PATCH 2/4] update composer files --- composer.json | 9 +-------- composer.lock | 43 +++---------------------------------------- 2 files changed, 4 insertions(+), 48 deletions(-) diff --git a/composer.json b/composer.json index 6ee66cbf5..ab16d66fa 100644 --- a/composer.json +++ b/composer.json @@ -23,13 +23,6 @@ } }, "repositories": [ - { - "type": "path", - "url": "../wp-module-installer", - "options": { - "symlink": true - } - }, { "type": "composer", "url": "https://newfold-labs.github.io/satis/", @@ -46,7 +39,7 @@ "wp-phpunit/wp-phpunit": "^5.9", "yoast/phpunit-polyfills": "^1.0", "newfold-labs/wp-php-standards": "^1.2", - "newfold-labs/wp-module-installer": "@dev" + "newfold-labs/wp-module-installer": "^1.0.0" }, "scripts": { "lint": [ diff --git a/composer.lock b/composer.lock index cf4240087..650727190 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "70cec6682ff6fda0c8aec4c3889f5158", + "content-hash": "06d71429f830805afb16aca0971b0864", "packages": [ { "name": "mustache/mustache", @@ -309,41 +309,6 @@ ], "time": "2022-03-03T13:19:32+00:00" }, - { - "name": "newfold-labs/wp-module-installer", - "version": "dev-enhance/code-improvements", - "dist": { - "type": "path", - "url": "../wp-module-installer", - "reference": "38187ec26c412fafdff23e8006af78da6f3cac7e" - }, - "require-dev": { - "newfold-labs/wp-php-standards": "^1.2" - }, - "type": "library", - "autoload": { - "psr-4": { - "NewfoldLabs\\WP\\Module\\Installer\\": "includes" - }, - "files": [ - "bootstrap.php" - ] - }, - "license": [ - "GPL-2.0-or-later" - ], - "authors": [ - { - "name": "Micah Wood", - "email": "micah.wood@newfold.com" - } - ], - "description": "An installer for WordPress plugins and themes.", - "transport-options": { - "symlink": true, - "relative": true - } - }, { "name": "newfold-labs/wp-php-standards", "version": "1.2.2", @@ -2660,12 +2625,10 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "newfold-labs/wp-module-installer": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": [], "platform-dev": [], "plugin-api-version": "2.3.0" -} +} \ No newline at end of file From 9580bdbb5ec8243d4be5e3c73a20ddb36596482e Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Tue, 30 May 2023 19:21:09 +0530 Subject: [PATCH 3/4] move to require instead require-dev --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index ab16d66fa..753a44b90 100644 --- a/composer.json +++ b/composer.json @@ -33,13 +33,13 @@ ], "require": { "mustache/mustache": "~2.5", - "wp-cli/wp-config-transformer": "~1.3.0" + "wp-cli/wp-config-transformer": "~1.3.0", + "newfold-labs/wp-module-installer": "^1.0.0" }, "require-dev": { "wp-phpunit/wp-phpunit": "^5.9", "yoast/phpunit-polyfills": "^1.0", - "newfold-labs/wp-php-standards": "^1.2", - "newfold-labs/wp-module-installer": "^1.0.0" + "newfold-labs/wp-php-standards": "^1.2" }, "scripts": { "lint": [ From 2bf5da50366141bad21bddb37b82c1324b3a8290 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Mon, 5 Jun 2023 11:41:13 +0530 Subject: [PATCH 4/4] Update lock file now that we have a release 1.0.0 --- composer.lock | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/composer.lock b/composer.lock index 650727190..4bc2fbcb7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "06d71429f830805afb16aca0971b0864", + "content-hash": "2a19e67fdf37171e7a42799499503949", "packages": [ { "name": "mustache/mustache", @@ -56,6 +56,48 @@ }, "time": "2022-01-21T06:08:36+00:00" }, + { + "name": "newfold-labs/wp-module-installer", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/newfold-labs/wp-module-installer.git", + "reference": "5896e00fc6c6d830d3e5e30c03a780a46f7fb448" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/newfold-labs/wp-module-installer/zipball/5896e00fc6c6d830d3e5e30c03a780a46f7fb448", + "reference": "5896e00fc6c6d830d3e5e30c03a780a46f7fb448", + "shasum": "" + }, + "require-dev": { + "newfold-labs/wp-php-standards": "^1.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "NewfoldLabs\\WP\\Module\\Installer\\": "includes" + }, + "files": [ + "bootstrap.php" + ] + }, + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "Micah Wood", + "email": "micah.wood@newfold.com" + } + ], + "description": "An installer for WordPress plugins and themes.", + "support": { + "source": "https://github.com/newfold-labs/wp-module-installer/tree/1.0.0", + "issues": "https://github.com/newfold-labs/wp-module-installer/issues" + }, + "time": "2023-06-04T10:11:09+00:00" + }, { "name": "wp-cli/wp-config-transformer", "version": "v1.3.0", @@ -2631,4 +2673,4 @@ "platform": [], "platform-dev": [], "plugin-api-version": "2.3.0" -} \ No newline at end of file +}