From 050e57c417bd786db6630f0dc249c7ef584d5ca3 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:25:34 +0200 Subject: [PATCH 01/24] Refactor: Optimize post retrieval in sent_email_details_popup template --- .../templates/sent_email_details_popup.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/includes/templates/sent_email_details_popup.php b/includes/templates/sent_email_details_popup.php index 3169c77..2379fd4 100644 --- a/includes/templates/sent_email_details_popup.php +++ b/includes/templates/sent_email_details_popup.php @@ -5,19 +5,16 @@ * @package wpcd */ -// Check post_id in wpcd_notify_user. -$entry_args = array( - 'post_type' => 'wpcd_sent_emails', - 'post_status' => 'private', - 'posts_per_page' => -1, - 'p' => $post_id, -); +$email_body = ''; -$entry_found = get_posts( $entry_args ); +// Use get_post to retrieve the post directly by its ID. +$entry_found = get_post( $post_id ); -$email_body = ''; -if ( ! empty( $entry_found ) ) { - $email_body = get_post_meta( $post_id, 'wpcd_sent_email_email_body', true ); +// Check post_id in wpcd_notify_user. + +if ( $entry_found and $entry_found->post_type == 'wpcd_sent_emails' and $entry_found->post_status == 'private' ) { + // If the post exists and matches the expected post type and status, retrieve the meta data. + $email_body = get_post_meta( $post_id, 'wpcd_sent_email_email_body', true ); } ?> From 9e16435f21a0d0a9059cfb4fea02e597b1809628 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:27:26 +0200 Subject: [PATCH 02/24] Improved get_server_name function to prioritize fetching the server name from the wpcd_server_name meta field --- includes/core/class-wpcd-server.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/includes/core/class-wpcd-server.php b/includes/core/class-wpcd-server.php index ed2fe79..5ca7b13 100644 --- a/includes/core/class-wpcd-server.php +++ b/includes/core/class-wpcd-server.php @@ -446,27 +446,26 @@ public function get_server_os( $post_id ) { } /** - * Get the server name on the server record + * Get the server name on the server record. * - * @TODO: The server name is the post title - * or in a post meta field. Right now it - * might be inconsistent which is which. - * For now, we're going to return the - * post title. + * @param int $post_id Post ID of the server record. * - * @param int $post_id post id of server record. - * - * @return string the server name + * @return string|false The server name if available, or false on failure. */ public function get_server_name( $post_id ) { - $post = get_post( $post_id ); - if ( $post ) { - return $post->post_title; - } else { - return false; + // Attempt to get the server name from the meta field 'wpcd_server_name' + $server_name = get_post_meta( $post_id, 'wpcd_server_name', true ); + + // If the meta field is empty, fallback to using the post title + if ( ! empty( $server_name ) ) { + return $server_name; } + + // Fallback to post title if available, or false if post does not exist + return get_the_title( $post_id ) ?: false; } + /** * Get the server region on the server record * From 3f1f874fe84edb11ba390b0bf98dcfe97fface9a Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:28:32 +0200 Subject: [PATCH 03/24] Refactor: Optimize get_server_id_by_instance_id for performance --- includes/core/class-wpcd-server.php | 34 +++++++++++++---------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/includes/core/class-wpcd-server.php b/includes/core/class-wpcd-server.php index 5ca7b13..6657433 100644 --- a/includes/core/class-wpcd-server.php +++ b/includes/core/class-wpcd-server.php @@ -554,40 +554,36 @@ public function get_server_provider_instance_id( $post_id ) { return get_post_meta( $post_id, 'wpcd_server_provider_instance_id', true ); } - /** - * Returns an server ID using the instance of a server. +/** + * Returns a server ID using the instance of a server. * - * @param int $instance_id The server instance id used to locate the server post id. + * @param int $instance_id The server instance ID used to locate the server post ID. * - * @return int|boolean app post id or false or error message + * @return int|false The server post ID or false if not found or if multiple results are found. */ public function get_server_id_by_instance_id( $instance_id ) { - $posts = get_posts( + $query = new WP_Query( array( - 'post_type' => 'wpcd_app_server', - 'post_status' => 'private', - 'numberposts' => -1, - 'meta_query' => array( + 'post_type' => 'wpcd_app_server', + 'post_status' => 'private', + 'posts_per_page' => 1, // Limit to one result for efficiency + 'meta_query' => array( array( 'key' => 'wpcd_server_provider_instance_id', 'value' => $instance_id, ), ), - ), + 'fields' => 'ids', // Only retrieve post IDs + ) ); - // Too many posts? Bail out. - if ( count( $posts ) <> 1 ) { - return false; - } - - if ( $posts ) { - return $posts[0]->ID; - } else { - return false; + // Check if exactly one post was found + if ( $query->found_posts === 1 ) { + return $query->posts[0]; // Return the single post ID } + return false; // Return false if no post or multiple posts found } /** From 93d7c8e38e33669917b95950ca46884f9ddeecce Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:31:35 +0200 Subject: [PATCH 04/24] Enh: Optimize get_app_count for performance and memory efficiency --- includes/core/class-wpcd-server.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/includes/core/class-wpcd-server.php b/includes/core/class-wpcd-server.php index 6657433..594ee36 100644 --- a/includes/core/class-wpcd-server.php +++ b/includes/core/class-wpcd-server.php @@ -598,27 +598,20 @@ public function get_app_count( $post_id ) { $args = array( 'post_type' => 'wpcd_app', 'post_status' => 'private', - 'posts_per_page' => 9999, 'meta_query' => array( array( 'key' => 'parent_post_id', 'value' => $post_id, ), ), + 'fields' => 'ids', // Only retrieve post IDs to reduce memory usage + 'posts_per_page' => 1, // Limit the query to 1 post ); - $posts = get_posts( $args ); - - $cnt_posts = 0; - - if ( ! empty( $posts ) ) { - $cnt_posts = count( $posts ); - } - - return $cnt_posts; + $query = new WP_Query( $args ); + return $query->found_posts; // Return the count directly } - /** * Get the list of apps on a server. * From 7573fb460b8ac7a4d28f5402d31d10a84141bd84 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:33:22 +0200 Subject: [PATCH 05/24] Enhancement: Improved wpcd_sent_emails_list_pagination by switching from get_posts to WP_Query for efficient querying and better performance. Optimized logic for retrieving total counts and paginated results, reducing memory usage and improving scalability. --- .../core/class-wpcd-email-notifications.php | 34 ++++++------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/includes/core/class-wpcd-email-notifications.php b/includes/core/class-wpcd-email-notifications.php index d9fd118..c157054 100644 --- a/includes/core/class-wpcd-email-notifications.php +++ b/includes/core/class-wpcd-email-notifications.php @@ -1728,33 +1728,14 @@ public function wpcd_sent_emails_list_pagination() { $first_btn = true; $last_btn = true; $start = $page * $per_page; - - // Get total sent email entries. - $all_sent_emails = array( - 'post_type' => 'wpcd_sent_emails', - 'post_status' => 'private', - 'numberposts' => -1, - 'orderby' => 'date', - 'order' => 'DESC', - 'meta_query' => array( - array( - 'key' => 'wpcd_sent_email_parent_id', - 'value' => $parent_id, - 'compare' => '=', - ), - ), - ); - $count_sent_emails = get_posts( $all_sent_emails ); - $count = count( $count_sent_emails ); - - // Check and get all the sent emails either for server or site. + // Define the query arguments to get both count and paginated results $sent_emails_args = array( 'post_type' => 'wpcd_sent_emails', 'post_status' => 'private', 'orderby' => 'date', 'order' => 'DESC', - 'posts_per_page' => $per_page, - 'offset' => $start, + 'posts_per_page' => $per_page, // Number of items per page + 'offset' => $start, // Starting point for pagination 'meta_query' => array( array( 'key' => 'wpcd_sent_email_parent_id', @@ -1763,7 +1744,14 @@ public function wpcd_sent_emails_list_pagination() { ), ), ); - $get_sent_emails = get_posts( $sent_emails_args ); + + // Run the query + $query = new WP_Query( $sent_emails_args ); + + // Get the count of total matching posts + $count = $query->found_posts; + $get_sent_emails = $query->get_posts(); + $html = ''; From dd6c0cbedca99a4d9ecda65721d28208d60d6271 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:35:05 +0200 Subject: [PATCH 06/24] Enh: Improved notification retrieval by replacing get_posts with get_post for better performance and standardized metadata access with get_post_meta for consistency and efficiency. --- includes/templates/notify_user_form_popup.php | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/includes/templates/notify_user_form_popup.php b/includes/templates/notify_user_form_popup.php index 667e005..fbfcf27 100644 --- a/includes/templates/notify_user_form_popup.php +++ b/includes/templates/notify_user_form_popup.php @@ -34,27 +34,20 @@ // Check if data need to add or update the existing. if ( '0' !== (string) $post_id ) { - // Check post_id in wpcd_notify_user. - $notify_args = array( - 'post_type' => 'wpcd_notify_user', - 'post_status' => 'private', - 'posts_per_page' => -1, - 'p' => $post_id, - 'author' => $current_user_id, - ); - - $alert_found = get_posts( $notify_args ); - - if ( ! empty( $alert_found ) ) { + // Retrieve the post directly using get_post. + $alert_found = get_post( $post_id ); + + if ( $alert_found && $alert_found->post_type == 'wpcd_notify_user' && $alert_found->post_status == 'private' && $alert_found->post_author == $current_user_id ) { + // Fetch metadata associated with the post. $profile_name = get_post_meta( $post_id, 'wpcd_notify_user_profile_name', true ); $email_address = get_post_meta( $post_id, 'wpcd_notify_user_email_addresses', true ); $slack_webhook = get_post_meta( $post_id, 'wpcd_notify_user_slack_webhooks', true ); $zapier_webhook = get_post_meta( $post_id, 'wpcd_notify_user_zapier_webhooks', true ); $send_to_zapier = get_post_meta( $post_id, 'wpcd_notify_user_zapier_send', true ); - $selected_servers = get_metadata( 'post', $post_id, 'wpcd_notify_user_servers', false ); - $selected_sites = get_metadata( 'post', $post_id, 'wpcd_notify_user_sites', false ); - $selected_types = get_metadata( 'post', $post_id, 'wpcd_notify_user_type', false ); - $selected_references = get_metadata( 'post', $post_id, 'wpcd_notify_user_reference', false ); + $selected_servers = get_post_meta( $post_id, 'wpcd_notify_user_servers', false ); + $selected_sites = get_post_meta( $post_id, 'wpcd_notify_user_sites', false ); + $selected_types = get_post_meta( $post_id, 'wpcd_notify_user_type', false ); + $selected_references = get_post_meta( $post_id, 'wpcd_notify_user_reference', false ); } } From 87d99229e23c3d2d77e3f24f9681078a8f84b621 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:37:00 +0200 Subject: [PATCH 07/24] Optimized wpcd_is_server_available_for_commands by replacing get_posts with WP_Query, limiting results to a single post, and reducing memory usage with fields => 'ids'. Improved overall performance and scalability --- .../wordpress-app/class-wordpress-app.php | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/includes/core/apps/wordpress-app/class-wordpress-app.php b/includes/core/apps/wordpress-app/class-wordpress-app.php index 2b2cd14..cdfd737 100644 --- a/includes/core/apps/wordpress-app/class-wordpress-app.php +++ b/includes/core/apps/wordpress-app/class-wordpress-app.php @@ -5694,31 +5694,35 @@ public function wpcd_is_server_available_for_commands( $is_available, $server_id return false; } - // Ok, so far the server is still available for commands. Lets check the app records. - $args = array( - 'post_type' => 'wpcd_app', - 'post_status' => 'private', - 'posts_per_page' => -1, - 'meta_query' => array( - array( - 'key' => 'parent_post_id', - 'value' => $server_id, - ), - array( - 'key' => 'wpcd_app_wordpress-app_action_status', - 'value' => 'in-progress', + // Check app records for in-progress actions. + $args = array( + 'post_type' => 'wpcd_app', + 'post_status' => 'private', + 'posts_per_page' => 1, // Limit to 1 result for efficiency + 'meta_query' => array( + 'relation' => 'AND', + array( + 'key' => 'parent_post_id', + 'value' => $server_id, + ), + array( + 'key' => 'wpcd_app_wordpress-app_action_status', + 'value' => 'in-progress', + ), ), - ), - ); - - $app_posts = get_posts( $args ); - - if ( $app_posts ) { - return false; + 'fields' => 'ids', // Fetch only IDs to reduce memory usage + ); + + $query = new WP_Query( $args ); + + // If there are any matching posts, the server is not available. + if ( $query->have_posts() ) { + return false; + } + + return $is_available; } - - return $is_available; - } + /** * Checks a special transient to see if aptget is running on the server. From f952f846733b221a8e25122126fbd22a00b54262 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:38:48 +0200 Subject: [PATCH 08/24] Enhancement: Simplified wpcd_get_permissions by directly accessing post titles from the WP_Post object and handling IDs efficiently when fields => 'ids' is used. Improved code readability and performance. --- includes/core/class-wpcd-posts-team.php | 38 +++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/includes/core/class-wpcd-posts-team.php b/includes/core/class-wpcd-posts-team.php index dedb443..92d57c9 100644 --- a/includes/core/class-wpcd-posts-team.php +++ b/includes/core/class-wpcd-posts-team.php @@ -357,37 +357,45 @@ public function wpcd_team_save_post( $post_id ) { */ public function wpcd_get_permissions( $object_type, $only_ids = false ) { + // Set up query arguments. $args = array( - 'post_type' => 'wpcd_permission_type', - 'post_status' => 'private', - 'numberposts' => -1, - 'order' => 'ASC', - 'meta_query' => array( + 'post_type' => 'wpcd_permission_type', + 'post_status' => 'private', + 'posts_per_page' => -1, // Retrieve all matching posts + 'order' => 'ASC', + 'meta_query' => array( array( 'key' => 'wpcd_object_type', 'value' => $object_type, 'compare' => '=', ), ), + // Optimize query for only IDs if $only_ids is true. + 'fields' => $only_ids ? 'ids' : '', ); - - $posts = get_posts( $args ); + + // Use WP_Query for better control. + $query = new WP_Query( $args ); + + // Initialize the permissions array. $permissions = array(); - if ( count( $posts ) ) { - foreach ( $posts as $post ) { - $post_id = $post->ID; - $title = get_the_title( $post_id ); - + + if ( $query->have_posts() ) { + foreach ( $query->posts as $post ) { if ( $only_ids ) { - $permissions[] = (string) $post_id; + // If only IDs are required. + $permissions[] = (string) ( is_numeric( $post ) ? $post : $post->ID ); } else { - $permissions[ $post_id ] = $title; + // If titles are also needed. + $permissions[ $post->ID ] = $post->post_title; } } } - + return $permissions; } + + /** * To get the list of groups for specified group type from wpcd_permission_type cpt. From 7cf8f1d1cac7adacd2705d5d8814cb9f82550079 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:40:05 +0200 Subject: [PATCH 09/24] Enhancement: Refactored wpcd_get_permission_groups to use WP_Query with optional fields => 'ids', improving performance and memory efficiency. Simplified metadata and title retrieval by accessing the WP_Post object directly --- includes/core/class-wpcd-posts-team.php | 38 ++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/includes/core/class-wpcd-posts-team.php b/includes/core/class-wpcd-posts-team.php index 92d57c9..f7ffa2e 100644 --- a/includes/core/class-wpcd-posts-team.php +++ b/includes/core/class-wpcd-posts-team.php @@ -407,38 +407,44 @@ public function wpcd_get_permissions( $object_type, $only_ids = false ) { */ public function wpcd_get_permission_groups( $group, $only_ids = false ) { + // Set up query arguments. $args = array( - 'post_type' => 'wpcd_permission_type', - 'post_status' => 'private', - 'numberposts' => -1, - 'order' => 'ASC', - 'meta_query' => array( + 'post_type' => 'wpcd_permission_type', + 'post_status' => 'private', + 'posts_per_page' => -1, // Retrieve all matching posts + 'order' => 'ASC', + 'meta_query' => array( array( 'key' => 'wpcd_permission_group', 'value' => $group, 'compare' => '=', ), ), + // Optimize query for only IDs if $only_ids is true. + 'fields' => $only_ids ? 'ids' : '', ); - - $posts = get_posts( $args ); + + // Use WP_Query for better control. + $query = new WP_Query( $args ); + + // Initialize the permissions array. $permissions = array(); - if ( count( $posts ) ) { - foreach ( $posts as $post ) { - $post_id = $post->ID; - $title = get_the_title( $post_id ); - + + if ( $query->have_posts() ) { + foreach ( $query->posts as $post ) { if ( $only_ids ) { - $permissions[] = (string) $post_id; + // Add only the post ID if $only_ids is true. + $permissions[] = (string) ( is_numeric( $post ) ? $post : $post->ID ); } else { - $permissions[ $post_id ] = $title; + // Add the post ID and title if $only_ids is false. + $permissions[ $post->ID ] = $post->post_title; } } } - + return $permissions; } - + /** * This will store/update permissions in custom table * From 97dae922d26ec075e156ad6ca5aa86e7984e8845 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:44:57 +0200 Subject: [PATCH 10/24] Enhancement: Replaced get_posts with WP_Query in WPCD_POSTS_TEAM class for improved performance and memory efficiency. Limited results to a single post and updated logic for count retrieval. --- includes/core/class-wpcd-posts-team.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/includes/core/class-wpcd-posts-team.php b/includes/core/class-wpcd-posts-team.php index f7ffa2e..fcc1db0 100644 --- a/includes/core/class-wpcd-posts-team.php +++ b/includes/core/class-wpcd-posts-team.php @@ -782,14 +782,15 @@ public function wpcd_team_table_content( $column_name, $post_id ) { 'meta_key' => 'wpcd_assigned_teams', 'meta_value' => $post_id, 'meta_compare' => 'IN', - 'numberposts' => -1, + 'posts_per_page' => 1, 'fields' => 'ids', ); - - $posts = get_posts( $args ); - - if ( count( $posts ) ) { - $value = sprintf( '%d', esc_url( admin_url( 'edit.php?post_type=wpcd_app_server&team_id=' . $post_id ) ), count( $posts ) ); + + $query = new WP_Query( $args ); + $count = $query->found_posts; + + if ( $count ) { + $value = sprintf( '%d', esc_url( admin_url( 'edit.php?post_type=wpcd_app_server&team_id=' . $post_id ) ), $count ); } else { $value = 0; } @@ -802,14 +803,15 @@ public function wpcd_team_table_content( $column_name, $post_id ) { 'meta_key' => 'wpcd_assigned_teams', 'meta_value' => $post_id, 'meta_compare' => 'IN', - 'numberposts' => -1, + 'posts_per_page' => 1, 'fields' => 'ids', ); - $posts = get_posts( $args ); - - if ( count( $posts ) ) { - $value = sprintf( '%d', esc_url( admin_url( 'edit.php?post_type=wpcd_app&team_id=' . $post_id ) ), count( $posts ) ); + $query = new WP_Query( $args ); + $count = $query->found_posts; + + if ( $count ) { + $value = sprintf( '%d', esc_url( admin_url( 'edit.php?post_type=wpcd_app&team_id=' . $post_id ) ), $count ); } else { $value = 0; } From adeb1781478ff04b283319f123ff810015aaf3ac Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:49:23 +0200 Subject: [PATCH 11/24] Enhancement: Updated version check API request to include minimum WordPress version parameter --- .../wordpress-app/class-wordpress-app.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/includes/core/apps/wordpress-app/class-wordpress-app.php b/includes/core/apps/wordpress-app/class-wordpress-app.php index cdfd737..bcb979d 100644 --- a/includes/core/apps/wordpress-app/class-wordpress-app.php +++ b/includes/core/apps/wordpress-app/class-wordpress-app.php @@ -761,8 +761,14 @@ public static function get_wp_versions() $versions = get_transient('developvi_wp_versions'); if (false === $versions) { + $min_version = trim(wpcd_get_option('wpcd_allowed_min_wp_version')); + if (empty($min_version)) { + $min_version = '6.1.4'; + } + $min_version = apply_filters('wpcd_allowed_min_wp_version', $min_version); + // Make a request to fetch the latest WP versions - $response = wp_remote_get('https://api.wordpress.org/core/version-check/1.7/'); + $response = wp_remote_get("https://api.wordpress.org/core/version-check/1.7/?version=$min_version"); // Return if the request was unsuccessful if (200 !== wp_remote_retrieve_response_code($response)) { @@ -773,16 +779,7 @@ public static function get_wp_versions() $body = json_decode(wp_remote_retrieve_body($response), true); $versions = array_column($body['offers'], 'version'); $versions[] = 'latest'; - $min_version = trim(wpcd_get_option('wpcd_allowed_min_wp_version')); - if (empty($min_version)) { - $min_version = '6.1.4'; - } - $min_version = apply_filters('wpcd_allowed_min_wp_version', $min_version); - - // Filter versions greater than or equal to $min_version - $versions = array_filter($versions, function ($version) use ($min_version) { - return version_compare($version, $min_version, '>='); - }); + // Sort versions in reverse order rsort($versions); From ab0b0c5652ecdd975bdfd104da3fc15011720308 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:50:04 +0200 Subject: [PATCH 12/24] Refactor: Renamed function from custom_map_meta_cap_for_eslam to custom_map_meta_cap_for_server_access for improved clarity and alignment with its purpose. --- includes/core/functions-metabox.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/core/functions-metabox.php b/includes/core/functions-metabox.php index 0a54091..0661d4b 100644 --- a/includes/core/functions-metabox.php +++ b/includes/core/functions-metabox.php @@ -157,9 +157,9 @@ function wpcd_end_card( $tab ) { } // This code addresses an issue where servers are inaccessible due to changes in metabox behavior starting from version 5.9.11 -add_filter( 'map_meta_cap', 'custom_map_meta_cap_for_eslam', 10, 4 ); +add_filter( 'map_meta_cap', 'custom_map_meta_cap_for_server_access', 10, 4 ); -function custom_map_meta_cap_for_eslam( $caps, $cap, $user_id, $args ) { +function custom_map_meta_cap_for_server_access( $caps, $cap, $user_id, $args ) { // Check if the required capability is `read_post` and the user is an admin using `wpcd_is_admin()` if ( 'read_post' === $cap and wpcd_is_admin() ) { // Get the post ID from the arguments to check its post type From b9d940244e1f12668ec9242b0d1da6e0f5425873 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Fri, 22 Nov 2024 14:50:48 +0200 Subject: [PATCH 13/24] Refactor: Renamed function from custom_map_meta_cap_for_eslam to custom_map_meta_cap_for_server_access for improved clarity and alignment with its purpose. --- includes/core/wp-cloud-deploy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/core/wp-cloud-deploy.php b/includes/core/wp-cloud-deploy.php index ca7257c..6727483 100644 --- a/includes/core/wp-cloud-deploy.php +++ b/includes/core/wp-cloud-deploy.php @@ -754,7 +754,7 @@ public static function get_os_list() { $oslist = array( 'ubuntu2204lts' => __( 'Ubuntu 22.04 LTS', 'wpcd' ), 'ubuntu2004lts' => __( 'Ubuntu 20.04 LTS', 'wpcd' ), - 'ubuntu2404lts' => __( 'Ubuntu 24.04 LTS (Important Restrictions - See Docs!)', 'wpcd' ), + 'ubuntu2404lts' => __( 'Ubuntu 24.04 LTS', 'wpcd' ), ); // Remove some entries based on settings. From ba79ee4040070d0e1939f04b352d847aa8ac3882 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Sat, 23 Nov 2024 15:36:00 +0200 Subject: [PATCH 14/24] Added support for PHP 8.4 in server preparation script, including updates to php.ini configurations and Redis installation --- .../scripts/v1/raw/01-prepare_server.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/01-prepare_server.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/01-prepare_server.txt index b46dfa4..62426e6 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/01-prepare_server.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/01-prepare_server.txt @@ -181,7 +181,7 @@ then then echo $(date): "Warning: Installing PHP without the Imagick module because it is not yet available on $GV_UBUNTU_VERSION_STRING" fi - phpversion=(7.4 8.0 8.1 8.2 8.3) + phpversion=(7.4 8.0 8.1 8.2 8.3 8.4) for ver in "${phpversion[@]}" do echo $(date): ".....PHP $ver" @@ -396,7 +396,7 @@ else then # Update php.ini file to increase filesize uploads allowed in WordPress echo $(date): "Adding required entries in php.ini to allow for larger file uploads in WordPress..." - phpversion=(7.4 8.0 8.1 8.2 8.3) + phpversion=(7.4 8.0 8.1 8.2 8.3 8.4) for ver in "${phpversion[@]}" do sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 25M/g" /etc/php/$ver/fpm/php.ini @@ -415,9 +415,9 @@ else sed -i "s/;opcache.validate_permission=0/opcache.validate_permission=1/g" /etc/php/$ver/fpm/php.ini sed -i "s/;opcache.file_update_protection=2/opcache.file_update_protection=60/g" /etc/php/$ver/fpm/php.ini - # PHP 8.1, 8.2 & 8.3 needs a set of default functions added to its global php.ini file because its set to blank for some reason. + # PHP 8.1, 8.2 & 8.3 & 8.4 needs a set of default functions added to its global php.ini file because its set to blank for some reason. # We're going to use the same list as 7.4. - if [ $ver = "8.1" ] || [ $ver = "8.2" ] || [ $ver = "8.3" ]; then + if [ $ver = "8.1" ] || [ $ver = "8.2" ] || [ $ver = "8.3" ] || [ $ver = "8.4" ]; then echo "$(date): Setting global list of restricted php functions for PHP $ver" sed -i "s/^disable_functions.*/disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,/g" /etc/php/$ver/fpm/php.ini fi @@ -856,9 +856,9 @@ fastcgi_hide_header X-Powered-By; sed -i "s/;opcache.validate_permission=0/opcache.validate_permission=1/g" /usr/local/lsws/lsphp${phpver}/etc/php/${lsphpver}/litespeed/php.ini sed -i "s/;opcache.file_update_protection=2/opcache.file_update_protection=60/g" /usr/local/lsws/lsphp${phpver}/etc/php/${lsphpver}/litespeed/php.ini - # PHP 8.1, 8.2 & 8.3 needs a set of default functions added to its global php.ini file because its set to blank for some reason. + # PHP 8.1, 8.2 & 8.3 & 8.4 needs a set of default functions added to its global php.ini file because its set to blank for some reason. # We're going to use the same list as 7.4. - if [ $lsphpver = "8.1" ] || [ $lsphpver = "8.2" ] || [ $lsphpver = "8.3" ]; then + if [ $lsphpver = "8.1" ] || [ $lsphpver = "8.2" ] || [ $lsphpver = "8.3" ] || [ $lsphpver = "8.4" ]; then echo "$(date): Setting global list of restricted php functions for PHP $lsphpver" sed -i "s/^disable_functions.*/disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,/g" /usr/local/lsws/lsphp${phpver}/etc/php/${lsphpver}/litespeed/php.ini fi @@ -941,7 +941,7 @@ else # Do Redis things related to NGINX if [ "$webserver_type" = "nginx" ] then - apt-get install -y php7.4-redis php8.0-redis php8.1-redis php8.2-redis php8.3-redis > /dev/null 2>&1 + apt-get install -y php7.4-redis php8.0-redis php8.1-redis php8.2-redis php8.3-redis php8.4-redis > /dev/null 2>&1 fi # Do Redis things related to OLS From 60279d756163b3ef469d2293cebbaadf68a3a871 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Sat, 23 Nov 2024 15:36:44 +0200 Subject: [PATCH 15/24] Added PHP 8.4 to the supported versions in the nginx configuration script --- .../apps/wordpress-app/scripts/v1/raw/9999-common-functions.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/9999-common-functions.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/9999-common-functions.txt index 26f6b9b..dbedd34 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/9999-common-functions.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/9999-common-functions.txt @@ -2054,7 +2054,7 @@ function gf_mt_set_openbasedir(){ if [ "$g_webserver_type" = "nginx" ] then - phpversion=(7.4 8.0 8.1 8.2 8.3) + phpversion=(7.4 8.0 8.1 8.2 8.3 8.4) for ver in "${phpversion[@]}" do if [ -f /etc/php/$ver/fpm/pool.d/$domain.conf ]; then From 90d18bbb2567857e9fe4c208549a7f69185a8110 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Sat, 23 Nov 2024 15:40:51 +0200 Subject: [PATCH 16/24] Fix: Update passwordless link generation to use domain variable instead of username --- .../apps/wordpress-app/scripts/v1/raw/30-wp_site_things.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/30-wp_site_things.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/30-wp_site_things.txt index 645c626..74b56d8 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/30-wp_site_things.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/30-wp_site_things.txt @@ -303,7 +303,7 @@ if [[ $action == "wp_site_get_passwordless_link" || $action == "8" ]]; then admin_user=(${adminusers[@]}) # Get passwordless link - link=$(su - $user_name -c "wp login create $admin_user --url-only --expires=180 --url=https://$user_name") + link=$(su - $user_name -c "wp login create $admin_user --url-only --expires=180 --url=https://$domain") echo echo $link @@ -334,7 +334,7 @@ if [[ $action == "wp_site_get_passwordless_link_selected_user" || $action == "9" su - $user_name -c "wp login install --activate --yes" # Get passwordless link - link=$(su - $user_name -c "wp login create $login_user --url-only --expires=180 --url=https://$user_name") + link=$(su - $user_name -c "wp login create $login_user --url-only --expires=180 --url=https://$domain") echo echo $link From c02fe59ff2d8d5e9f4ed1b4697d4b55175945db4 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Sat, 23 Nov 2024 16:37:54 +0200 Subject: [PATCH 17/24] Enh: Added 'default' => array() to 'logging_and_tracing_types_debug_log' and 'logging_and_tracing_types' fields to properly initialize default selections, ensuring that no log types are pre-selected by default. This avoids potential database performance issues caused by logging all types unnecessarily --- includes/core/class-wpcd-settings.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/core/class-wpcd-settings.php b/includes/core/class-wpcd-settings.php index f6d6e20..caed5ff 100644 --- a/includes/core/class-wpcd-settings.php +++ b/includes/core/class-wpcd-settings.php @@ -238,6 +238,8 @@ function ( $meta_boxes ) { 'other' => __( 'Other', 'wpcd' ), ), 'select_all_none' => true, + 'default' => array() + ), array( 'name' => __( 'Only include messages with the following text', 'wpcd' ), @@ -332,6 +334,7 @@ function ( $meta_boxes ) { 'other' => __( 'Other', 'wpcd' ), ), 'select_all_none' => true, + 'default' => array() ), ), From 7ac9ab5765b17a954189c1c642c4512f3d05b29c Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Sat, 23 Nov 2024 16:48:30 +0200 Subject: [PATCH 18/24] Fix: Ensure exclude message text is an array or object before processing to prevent potential errors in logging logic --- includes/core/class-wpcd-posts-error-log.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/includes/core/class-wpcd-posts-error-log.php b/includes/core/class-wpcd-posts-error-log.php index 9c01728..0304989 100644 --- a/includes/core/class-wpcd-posts-error-log.php +++ b/includes/core/class-wpcd-posts-error-log.php @@ -261,15 +261,18 @@ public function add_error_log_entry( $msg, $type, $file, $line, $data ) { // Check for excluded text. if ( $ok_to_log ) { $exclude_msg_txt = wpcd_get_early_option( 'exclude_msg_txt' ); - foreach ( $exclude_msg_txt as $exclude ) { - if ( ! empty( $exclude ) && isset( $exclude['exclude_msg'] ) && ( ! empty( $exclude['exclude_msg'] ) ) ) { - if ( strpos( $msg, $exclude['exclude_msg'] ) !== false ) { - $ok_to_log = false; - break; + if(is_array($exclude_msg_txt) or is_object($exclude_msg_txt)){ + + foreach ( $exclude_msg_txt as $exclude ) { + if ( ! empty( $exclude ) && isset( $exclude['exclude_msg'] ) && ( ! empty( $exclude['exclude_msg'] ) ) ) { + if ( strpos( $msg, $exclude['exclude_msg'] ) !== false ) { + $ok_to_log = false; + break; + } } } } - } + } // Check to see if the log entry meets the include message criteria. if ( $ok_to_log ) { From 90e0f3f22e67f861fa90363b3684a4be34a2e743 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Sat, 23 Nov 2024 16:52:29 +0200 Subject: [PATCH 19/24] wpcd 5.9.1 --- wpcd.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpcd.php b/wpcd.php index 944cf2d..d6a2127 100644 --- a/wpcd.php +++ b/wpcd.php @@ -3,7 +3,7 @@ Plugin Name: WPCloudDeploy Plugin URI: https://developvi.com Description: Deploy and manage cloud servers and apps from inside the WordPress Admin dashboard. -Version: 5.9.0 +Version: 5.9.1 Requires at least: 5.8 Requires PHP: 7.4 Item Id: 1493 From bf8a9a59b934d2eee7c72a6d171fdd90962585e4 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Sun, 24 Nov 2024 10:44:27 +0200 Subject: [PATCH 20/24] Fix: Return the ID of the single post found in the query to ensure correct post identification --- includes/core/class-wpcd-server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/core/class-wpcd-server.php b/includes/core/class-wpcd-server.php index 594ee36..ed8a484 100644 --- a/includes/core/class-wpcd-server.php +++ b/includes/core/class-wpcd-server.php @@ -580,7 +580,7 @@ public function get_server_id_by_instance_id( $instance_id ) { // Check if exactly one post was found if ( $query->found_posts === 1 ) { - return $query->posts[0]; // Return the single post ID + return $query->posts[0]->ID; // Return the single post ID } return false; // Return false if no post or multiple posts found From 5eff48c72159ed141cfbcbbb73569b927175471d Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Tue, 26 Nov 2024 06:27:33 +0200 Subject: [PATCH 21/24] Add support for PHP 8.4 across various scripts and configuration files --- .../class-wordpress-app-settings.php | 2 + .../wordpress-app/class-wordpress-app.php | 46 ++++++- .../class-wordpress-posts-site-package.php | 1 + .../scripts/v1/raw/08-backup.txt | 2 +- .../wordpress-app/scripts/v1/raw/10-misc.txt | 4 +- .../v1/raw/1110-upgrade_install_php_84.txt | 126 ++++++++++++++++++ .../wordpress-app/scripts/v1/raw/12-redis.txt | 2 +- .../scripts/v1/raw/16-memcached.txt | 2 +- .../wordpress-app/scripts/v1/raw/20-monit.txt | 13 ++ .../scripts/v1/raw/32-filegator.txt | 6 +- .../v1/raw/37-backup-configuration.txt | 1 + .../scripts/v1/raw/41-wp-backup2.txt | 2 +- .../scripts/v1/raw/43-netdata.txt | 1 + .../scripts/v1/raw/58-git_control.txt | 2 +- .../scripts/v1/raw/81-origin-site-sync.txt | 1 + .../scripts/v1/run_upgrade_install_php_84.txt | 8 ++ .../apps/wordpress-app/tabs-server/logs.php | 1 + .../wordpress-app/tabs-server/services.php | 23 +++- .../apps/wordpress-app/tabs-server/tools.php | 2 +- .../wordpress-app/tabs-server/upgrade.php | 126 +++++++++++++++++- .../script-handlers.php | 14 ++ 21 files changed, 370 insertions(+), 15 deletions(-) create mode 100644 includes/core/apps/wordpress-app/scripts/v1/raw/1110-upgrade_install_php_84.txt create mode 100644 includes/core/apps/wordpress-app/scripts/v1/run_upgrade_install_php_84.txt diff --git a/includes/core/apps/wordpress-app/class-wordpress-app-settings.php b/includes/core/apps/wordpress-app/class-wordpress-app-settings.php index 409aaa8..593bfa1 100644 --- a/includes/core/apps/wordpress-app/class-wordpress-app-settings.php +++ b/includes/core/apps/wordpress-app/class-wordpress-app-settings.php @@ -1423,6 +1423,7 @@ public function server_fields() { '8.1' => '8.1', '8.2' => '8.2', '8.3' => '8.3', + '8.4' => '8.4', ), 'std' => ( array( '5.6', '7.1', '7.2', '7.3', '8.0' ) ), 'select_all_none' => true, @@ -1521,6 +1522,7 @@ public function site_fields() { '7.4' => '7.4', '8.2' => '8.2', '8.3' => '8.3', + '8.4' => '8.4', ), 'tab' => 'wordpress-app-sites', ), diff --git a/includes/core/apps/wordpress-app/class-wordpress-app.php b/includes/core/apps/wordpress-app/class-wordpress-app.php index bcb979d..99a6840 100644 --- a/includes/core/apps/wordpress-app/class-wordpress-app.php +++ b/includes/core/apps/wordpress-app/class-wordpress-app.php @@ -1294,14 +1294,40 @@ public function is_php_83_installed( $server_id ) { return false; } + + /** + * Returns a boolean true/false if PHP 83 is supposed to be installed. + * + * @param int $server_id ID of server being interrogated. + * + * @return boolean + */ + public function is_php_84_installed( $server_id ) { + + $initial_plugin_version = $this->get_server_meta_by_app_id( $server_id, 'wpcd_server_plugin_initial_version', true ); // This function is smart enough to know if the ID being passed is a server or app id and adjust accordingly. + + if ( version_compare( $initial_plugin_version, '5.9.1' ) > -1 ) { + // Versions of the plugin after 5.9.1 automatically install PHP 8.4. + return true; + } else { + // See if it was manually installed via an upgrade process - which would leave a meta field value behind on the server CPT record. + $is_php84_installed = (bool) $this->get_server_meta_by_app_id( $server_id, 'wpcd_server_php84_installed', true ); // This function is smart enough to know if the ID being passed is a server or app id and adjust accordingly. + if ( true === $is_php84_installed ) { + return true; + } else { + return false; + } + } + return false; + } /** * Returns a boolean true/false if a particular PHP version is active. * Version 4.16 and later of WPCD deactivated earlier versions of PHP * by default. Only if the user explicitly activated it was it enabled. * * @param int $server_id ID of server being interrogated. - * @param string $php_version PHP version - eg: php56, php71, php72, php73, php74, php81, php82, php83 etc. + * @param string $php_version PHP version - eg: php56, php71, php72, php73, php74, php81, php82, php83, php84 etc. * * @return boolean */ @@ -1344,6 +1370,11 @@ public function is_php_version_active( $server_id, $php_version ) { $return = false; } break; + case 'php84': + if ( ! $this->is_php_84_installed( $server_id ) ) { + $return = false; + } + break; } } @@ -2077,6 +2108,12 @@ public function get_php_versions( $id ) { } else { $php83 = array(); } + // Create single element array if php 8.4 is installed. + if ( $this->is_php_84_installed( $id ) ) { + $php84 = array( '8.4' => '8.4' ); + } else { + $php84 = array(); + } // Array of other PHP versions. switch ( $webserver_type ) { @@ -2136,7 +2173,8 @@ public function get_php_versions( $id ) { $php80, $php81, $php82, - $php83 + $php83, + $php84, ); // Filter out inactive versions. Only applies to NGINX. OLS always have all versions listed in the above switch statement active. @@ -2153,7 +2191,8 @@ public function get_php_versions( $id ) { 'php80' => '8.0', 'php81' => '8.1', 'php82' => '8.2', - 'php82' => '8.3', + 'php83' => '8.3', + 'php84' => '8.4', ); foreach ( $php_versions as $php_version_key => $php_version ) { if ( ! $this->is_php_version_active( $server_id, $php_version_key ) ) { @@ -5136,6 +5175,7 @@ public function wpapp_wpcd_app_table_filtering() { '8.1' => '8.1', '8.2' => '8.2', '8.3' => '8.3', + '8.4' => '8.4', ); $php_version = $this->generate_meta_dropdown( 'wpapp_php_version', __( 'PHP Version', 'wpcd' ), $php_version_options ); echo wpcd_kses_select( $php_version ); diff --git a/includes/core/apps/wordpress-app/class-wordpress-posts-site-package.php b/includes/core/apps/wordpress-app/class-wordpress-posts-site-package.php index d589325..f526954 100644 --- a/includes/core/apps/wordpress-app/class-wordpress-posts-site-package.php +++ b/includes/core/apps/wordpress-app/class-wordpress-posts-site-package.php @@ -401,6 +401,7 @@ public function register_post_type_fields( $metaboxes ) { '7.4' => '7.4', '8.2' => '8.2', '8.3' => '8.3', + '8.4' => '8.4', ), 'save_field' => true, 'columns' => 3, diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/08-backup.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/08-backup.txt index 063bfe9..0270a3e 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/08-backup.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/08-backup.txt @@ -231,7 +231,7 @@ then #fi # if /var/www/$domain exists, let the user know before overwriting - if [[ -d /var/www/$domain || -e /etc/nginx/sites-enabled/$domain || -e /etc/nginx/sites-available/$domain || -e /etc/php/5.6/fpm/pool.d/$domain.conf || -e /etc/php/7.1/fpm/pool.d/$domain.conf || -e /etc/php/7.2/fpm/pool.d/$domain.conf || -e /etc/php/7.3/fpm/pool.d/$domain.conf || -e /etc/php/7.4/fpm/pool.d/$domain.conf || -e /etc/php/8.0/fpm/pool.d/$domain.conf || -e /etc/php/8.1/fpm/pool.d/$domain.conf || -e /etc/php/8.2/fpm/pool.d/$domain.conf || -e /etc/php/8.3/fpm/pool.d/$domain.conf || -d ${VHDIR}/$domain ]] + if [[ -d /var/www/$domain || -e /etc/nginx/sites-enabled/$domain || -e /etc/nginx/sites-available/$domain || -e /etc/php/5.6/fpm/pool.d/$domain.conf || -e /etc/php/7.1/fpm/pool.d/$domain.conf || -e /etc/php/7.2/fpm/pool.d/$domain.conf || -e /etc/php/7.3/fpm/pool.d/$domain.conf || -e /etc/php/7.4/fpm/pool.d/$domain.conf || -e /etc/php/8.0/fpm/pool.d/$domain.conf || -e /etc/php/8.1/fpm/pool.d/$domain.conf || -e /etc/php/8.2/fpm/pool.d/$domain.conf || -e /etc/php/8.3/fpm/pool.d/$domain.conf || -e /etc/php/8.4/fpm/pool.d/$domain.conf || -d ${VHDIR}/$domain ]] then # we do the following to allow bypassing this check if the user sets $overwrite to "yes" if [[ "$overwrite" != "yes" ]] diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/10-misc.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/10-misc.txt index 23b406c..4735dfe 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/10-misc.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/10-misc.txt @@ -787,7 +787,7 @@ then while [[ -z $module ]] do default_lsphpver=$(grep -sEo 'lsphp[0-9]{2}' $WEBCF|head -n1| sed 's|lsphp||'); # 74 - default_php_version=$(echo $default_lsphpver | sed 's/^\(.\{1\}\)/\1./') # 7.0,7.1,7.2,7.3,7.4,8.0,8.1,8.2,8.3 etc + default_php_version=$(echo $default_lsphpver | sed 's/^\(.\{1\}\)/\1./') # 7.0,7.1,7.2,7.3,7.4,8.0,8.1,8.2,8.3,8.4 etc ls /usr/local/lsws/lsphp${default_lsphpver}/etc/php/${default_php_version}/mods-disabled | sed 's/.ini//' | nl echo read -p "Select module: " site_number @@ -830,7 +830,7 @@ then if [ "$g_webserver_type" = "ols" ] || [ "$g_webserver_type" = "ols-enterprise" ] then default_lsphpver=$(grep -sEo 'lsphp[0-9]{2}' $WEBCF|head -n1| sed 's|lsphp||'); # 74 - default_php_version=$(echo $default_lsphpver | sed 's/^\(.\{1\}\)/\1./') # 7.0,7.1,7.2,7.3,7.4,8.0,8.1,8.2,8.3 etc + default_php_version=$(echo $default_lsphpver | sed 's/^\(.\{1\}\)/\1./') # 7.0,7.1,7.2,7.3,7.4,8.0,8.1,8.2,8.3,8.4 etc mkdir -p /usr/local/lsws/lsphp${default_lsphpver}/etc/php/${default_php_version}/mods-disabled while [[ -z $module ]] do diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/1110-upgrade_install_php_84.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/1110-upgrade_install_php_84.txt new file mode 100644 index 0000000..193b5e1 --- /dev/null +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/1110-upgrade_install_php_84.txt @@ -0,0 +1,126 @@ +#!/bin/bash +# This script will install PHP 8.4 + +echo $(date): "Refreshing repositories..." +apt-get update > /dev/null 2>&1 +if [ $? -ne 0 ] +then + echo "Failed! Quitting process" + exit 1 +fi + +## Get our common functions +if [[ ! -f 9999-common-functions.sh ]] +then + echo "The file 9999-common-functions.sh is missing" + exit 1 +fi +source 9999-common-functions.sh + +echo $(date): "Installing PHP 8.4...." +export DEBIAN_FRONTEND=noninteractive +# Add Vhost config based on webserver_type +if [ "$g_webserver_type" = "nginx" ]; then + apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" php8.4 php8.4-fpm php8.4-mbstring php8.4-curl php8.4-mysql php8.4-xml php8.4-zip php8.4-gd php8.4-imap php8.4-soap php8.4-bcmath php8.4-imagick -y + if [ $? -ne 0 ] + then + echo "Failed! Quitting process" + exit 1 + fi + + # Update php.ini file to increase filesize uploads allowed in WordPress + echo $(date): "Adding required entries in php.ini to allow for larger file uploads in WordPress..." + sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 25M/g" /etc/php/8.4/fpm/php.ini + sed -i "s/post_max_size = 8M/post_max_size = 25M/g" /etc/php/8.4/fpm/php.ini + + # Update php.ini to enable and configure opcache + echo $(date): "Updating OPCACHE parameters in php.ini..." + sed -i "s/;opcache.enable=1/opcache.enable=1/g" /etc/php/8.4/fpm/php.ini + sed -i "s/;opcache.enable_cli=0/opcache.enable_cli=1/g" /etc/php/8.4/fpm/php.ini + sed -i "s/;opcache.interned_strings_buffer=8/opcache.interned_strings_buffer=8/g" /etc/php/8.4/fpm/php.ini + sed -i "s/;opcache.max_accelerated_files=10000/opcache.max_accelerated_files=100000/g" /etc/php/8.4/fpm/php.ini + sed -i "s/;opcache.memory_consumption=128/opcache.memory_consumption=128/g" /etc/php/8.4/fpm/php.ini + sed -i "s/;opcache.save_comments=1/opcache.save_comments=1/g" /etc/php/8.4/fpm/php.ini + sed -i "s/;opcache.revalidate_freq=2/opcache.revalidate_freq=1/g" /etc/php/8.4/fpm/php.ini + sed -i "s/;opcache.use_cwd=1/opcache.use_cwd=1/g" /etc/php/8.4/fpm/php.ini + sed -i "s/;opcache.validate_root=0/opcache.validate_root=1/g" /etc/php/8.4/fpm/php.ini + sed -i "s/;opcache.validate_permission=0/opcache.validate_permission=1/g" /etc/php/8.4/fpm/php.ini + sed -i "s/;opcache.file_update_protection=2/opcache.file_update_protection=60/g" /etc/php/8.4/fpm/php.ini + + # PHP 8.4 needs a set of default functions added to its global php.ini file because its set to blank for some reason. + # We're going to use the same list as 7.4. + sed -i "s/^disable_functions.*/disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,/g" /etc/php/8.4/fpm/php.ini + + # Restarting php + echo $(date): "Restarting PHP processes..." + if [ ! -f /etc/wpcd/php-versions-disabled/php8.4 ] ; then + systemctl restart php8.4-fpm > /dev/null 2>&1 + fi + +# OLS Wrapper +elif [ "$g_webserver_type" = "ols" ] || [ "$g_webserver_type" = "ols-enterprise" ]; then + # Install all possible lsphp-dev and pear and packages + apt-get install -y lsphp84 lsphp84-common lsphp84-dev lsphp84-pear lsphp84-mysql lsphp84-imap lsphp84-curl + if [ $? -ne 0 ] + then + echo "Failed! Quitting process" + exit 1 + fi + + apt-get install -y lsphp84-imagick lsphp84-intl lsphp* + if [ $? -ne 0 ] + then + echo "Failed! Quitting process" + exit 1 + fi + + # *** lsphp-gd isn't available for some reason so removing from above, adding block below and then commenting out for now. + # *** Later, when it's available we'll add it back in. At that time we'll need another upgrade package just to get it onto existing php 8.4 servers. + # apt-get install -y lsphp84-gd + # if [ $? -ne 0 ] + # then + # echo "Failed! Quitting process" + # exit 1 + # fi + + sed -i -e "s|^;session.save_path.*|session.save_path = '/var/lib/lsphp/session/lsphp84'|g" -e "s|^session.save_path.*|session.save_path = '/var/lib/lsphp/session/lsphp84'|g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini ; + # /usr/local/lsws/lsphp84/bin/php -i |grep -Ei 'session.save_path' && echo "" # Disable useless echo but leave for debugging + + sed -i 's/^memory_limit.*/memory_limit = 1024M/g' /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i 's/^post_max_size.*/post_max_size = 25M/g' /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i 's/^upload_max_filesize.*/upload_max_filesize = 25M/g' /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i 's/^max_execution_time.*/max_execution_time = 7200/g' /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + + # Update php.ini to enable and configure opcache + sed -i "s/;opcache.enable=1/opcache.enable=1/g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i "s/;opcache.enable_cli=0/opcache.enable_cli=1/g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i "s/;opcache.interned_strings_buffer=8/opcache.interned_strings_buffer=8/g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i "s/;opcache.max_accelerated_files=10000/opcache.max_accelerated_files=100000/g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i "s/;opcache.memory_consumption=128/opcache.memory_consumption=128/g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i "s/;opcache.save_comments=1/opcache.save_comments=1/g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i "s/;opcache.revalidate_freq=2/opcache.revalidate_freq=1/g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i "s/;opcache.use_cwd=1/opcache.use_cwd=1/g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i "s/;opcache.validate_root=0/opcache.validate_root=1/g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i "s/;opcache.validate_permission=0/opcache.validate_permission=1/g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + sed -i "s/;opcache.file_update_protection=2/opcache.file_update_protection=60/g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + + # PHP 8.4 needs a set of default functions added to its global php.ini file because its set to blank for some reason. + # We're going to use the same list as 7.4. + sed -i "s/^disable_functions.*/disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,/g" /usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini + + # Update pecl + /usr/local/lsws/lsphp84/bin/pecl channel-update pecl.php.net + + # timezone stuff + sed -i -e 's|^;date.timezone.*|date.timezone = "UTC"|g' /usr/local/lsws/lsphp84/etc/php/$(echo '84' | sed 's/^\(.\{1\}\)/\1./')/litespeed/php.ini; + php_utc_result=$(/usr/local/lsws/lsphp84/bin/php -i 2>&1 | grep -Ei 'date.timezone') + if ! echo "$php_utc_result"| grep UTC >/dev/null 2>&1 + then + echo "Configuring Timezone for UTC for LSPHP84 failed" + echo "Found: $php_utc_result" + fi + +fi + +gf_restart_webserver "true" +echo "PHP 8.4 has been installed." diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/12-redis.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/12-redis.txt index fd1c9f8..3a3120a 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/12-redis.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/12-redis.txt @@ -62,7 +62,7 @@ then if [ "$g_webserver_type" = "nginx" ] then - apt-get install -y php7.4-redis php8.0-redis php8.1-redis php8.2-redis php8.3-redis + apt-get install -y php7.4-redis php8.0-redis php8.1-redis php8.2-redis php8.3-redis php8.4-redis elif [ "$g_webserver_type" = "ols" ] || [ "$g_webserver_type" = "ols-enterprise" ] then apt-get install -y lsphp74-redis lsphp80-redis lsphp81-redis lsphp82-redis diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/16-memcached.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/16-memcached.txt index 169db98..2594870 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/16-memcached.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/16-memcached.txt @@ -48,7 +48,7 @@ then if [ "$g_webserver_type" = "nginx" ] then - apt-get install -y php7.4-memcache php8.0-memcache php8.1-memcache php8.2-memcache php8.3-memcache + apt-get install -y php7.4-memcache php8.0-memcache php8.1-memcache php8.2-memcache php8.3-memcache php8.4-memcache number_of_php=$(ls /etc/php/ | wc -l) for (( number=1; number <=$number_of_php; number++ )) do diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/20-monit.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/20-monit.txt index fba9b62..00f9c97 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/20-monit.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/20-monit.txt @@ -433,6 +433,16 @@ echo 'check process memcached with pidfile "/var/run/memcached/memcached.pid" if failed host 127.0.0.1 port 11211 then restart '> /etc/monit/conf-available/memcached +# Add php checks (nginx only) +if [ "$g_webserver_type" = "nginx" ] ; then + echo 'check process php84-fpm with pidfile /var/run/php/php8.4-fpm.pid + start program = "/bin/systemctl start php8.4-fpm" + stop program = "/bin/systemctl stop php8.4-fpm" + if cpu is greater than '$Alert_cpu'% for 3 cycles then alert + if cpu is greater than '$Restart_cpu'% for 5 cycles then restart + if totalmem > '$Restart_memory' MB then alert +' > /etc/monit/conf-available/php84 + # Add php checks (nginx only) if [ "$g_webserver_type" = "nginx" ] ; then echo 'check process php83-fpm with pidfile /var/run/php/php8.3-fpm.pid @@ -494,6 +504,9 @@ echo 'check system '$domain' ln -s /etc/monit/conf-available/"$g_webserver_type" /etc/monit/conf-enabled/"$g_webserver_type" if [ "$g_webserver_type" = "nginx" ] ; then + if [[ ! -f /etc/wpcd/php-versions-disabled/php8.4 ]]; then + ln -s /etc/monit/conf-available/php84 /etc/monit/conf-enabled/php84 + fi if [[ ! -f /etc/wpcd/php-versions-disabled/php8.3 ]]; then ln -s /etc/monit/conf-available/php83 /etc/monit/conf-enabled/php83 fi diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/32-filegator.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/32-filegator.txt index e5e2905..08e859c 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/32-filegator.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/32-filegator.txt @@ -56,7 +56,11 @@ processing_dependencies() { apt list --installed 2>&1 | grep -q php8.3-zip if [[ $? -ne 0 ]]; then apt install -y php8.3-zip > /dev/null 2>&1 - fi + fi + apt list --installed 2>&1 | grep -q php8.4-zip + if [[ $? -ne 0 ]]; then + apt install -y php8.4-zip > /dev/null 2>&1 + fi } diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/37-backup-configuration.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/37-backup-configuration.txt index 7b1e714..67271c0 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/37-backup-configuration.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/37-backup-configuration.txt @@ -61,6 +61,7 @@ then rsync -az /usr/local/lsws/lsphp81/etc/php/8.1/litespeed/php.ini $backuptmp/lsws/lsphp81/etc/php/8.1/litespeed/php.ini 2>/dev/null rsync -az /usr/local/lsws/lsphp82/etc/php/8.2/litespeed/php.ini $backuptmp/lsws/lsphp82/etc/php/8.2/litespeed/php.ini 2>/dev/null rsync -az /usr/local/lsws/lsphp82/etc/php/8.3/litespeed/php.ini $backuptmp/lsws/lsphp82/etc/php/8.3/litespeed/php.ini 2>/dev/null + rsync -az /usr/local/lsws/lsphp82/etc/php/8.4/litespeed/php.ini $backuptmp/lsws/lsphp82/etc/php/8.4/litespeed/php.ini 2>/dev/null rsync -az /etc/nginx/ $backuptmp/nginx/ 2>/dev/null rsync -az /etc/php/ $backuptmp/php/ 2>/dev/null rsync -az /etc/letsencrypt/ $backuptmp/letsencrypt/ 2>/dev/null diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/41-wp-backup2.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/41-wp-backup2.txt index 52696d4..07ba0aa 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/41-wp-backup2.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/41-wp-backup2.txt @@ -390,7 +390,7 @@ then fi # If /var/www/$domain exists, let the user know before overwriting - if [[ -d /var/www/$domain || -e /etc/nginx/sites-enabled/$domain || -e /etc/nginx/sites-available/$domain || -e /etc/php/5.6/fpm/pool.d/$domain.conf || -e /etc/php/7.1/fpm/pool.d/$domain.conf || -e /etc/php/7.2/fpm/pool.d/$domain.conf || -e /etc/php/7.3/fpm/pool.d/$domain.conf || -e /etc/php/7.4/fpm/pool.d/$domain.conf || -e /etc/php/8.0/fpm/pool.d/$domain.conf || -e /etc/php/8.1/fpm/pool.d/$domain.conf || -e /etc/php/8.2/fpm/pool.d/$domain.conf || -e /etc/php/8.3/fpm/pool.d/$domain.conf || -d ${VHDIR}/$domain ]] + if [[ -d /var/www/$domain || -e /etc/nginx/sites-enabled/$domain || -e /etc/nginx/sites-available/$domain || -e /etc/php/5.6/fpm/pool.d/$domain.conf || -e /etc/php/7.1/fpm/pool.d/$domain.conf || -e /etc/php/7.2/fpm/pool.d/$domain.conf || -e /etc/php/7.3/fpm/pool.d/$domain.conf || -e /etc/php/7.4/fpm/pool.d/$domain.conf || -e /etc/php/8.0/fpm/pool.d/$domain.conf || -e /etc/php/8.1/fpm/pool.d/$domain.conf || -e /etc/php/8.2/fpm/pool.d/$domain.conf || -e /etc/php/8.3/fpm/pool.d/$domain.conf || -e /etc/php/8.4/fpm/pool.d/$domain.conf || -d ${VHDIR}/$domain ]] then # we do the following to allow bypassing this check if the user sets $overwrite to "yes" if [[ "$overwrite" != "yes" ]] diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/43-netdata.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/43-netdata.txt index 4d4ef97..e88cd5f 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/43-netdata.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/43-netdata.txt @@ -250,6 +250,7 @@ if [ "$g_webserver_type" = "nginx" ] ; then sed -i "s%.*pm.status_path.*%pm.status_path=/status81%g" /etc/php/8.1/fpm/pool.d/www.conf sed -i "s%.*pm.status_path.*%pm.status_path=/status82%g" /etc/php/8.2/fpm/pool.d/www.conf sed -i "s%.*pm.status_path.*%pm.status_path=/status83%g" /etc/php/8.3/fpm/pool.d/www.conf + sed -i "s%.*pm.status_path.*%pm.status_path=/status84%g" /etc/php/8.4/fpm/pool.d/www.conf echo "Restarting PHP processes..." number_of_php=$(ls /etc/php/ | wc -l) diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/58-git_control.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/58-git_control.txt index 0fbd830..00dac18 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/58-git_control.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/58-git_control.txt @@ -2307,7 +2307,7 @@ then # @todo: replace this block with a call to gf_mt_set_openbasedir() if [ "$g_webserver_type" = "nginx" ] then - phpversion=(7.4 8.0 8.1 8.2 8.3) + phpversion=(7.4 8.0 8.1 8.2 8.3 8.4) for ver in "${phpversion[@]}" do if [ -f /etc/php/$ver/fpm/pool.d/$domain.conf ]; then diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/81-origin-site-sync.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/81-origin-site-sync.txt index 5ea4e7e..3b2bd76 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/81-origin-site-sync.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/81-origin-site-sync.txt @@ -179,6 +179,7 @@ else ssh -o StrictHostKeyChecking=no -i "~$localuser/.ssh/id_rsa" $sshuser@$destination_ip "[[ ! -f /etc/wpcd/php-versions-disabled/8.1 ]] && sudo systemctl restart php8.1-fpm" < /dev/null ssh -o StrictHostKeyChecking=no -i "~$localuser/.ssh/id_rsa" $sshuser@$destination_ip "[[ ! -f /etc/wpcd/php-versions-disabled/8.2 ]] && sudo systemctl restart php8.2-fpm" < /dev/null ssh -o StrictHostKeyChecking=no -i "~$localuser/.ssh/id_rsa" $sshuser@$destination_ip "[[ ! -f /etc/wpcd/php-versions-disabled/8.3 ]] && sudo systemctl restart php8.3-fpm" < /dev/null + ssh -o StrictHostKeyChecking=no -i "~$localuser/.ssh/id_rsa" $sshuser@$destination_ip "[[ ! -f /etc/wpcd/php-versions-disabled/8.4 ]] && sudo systemctl restart php8.4-fpm" < /dev/null ssh -o StrictHostKeyChecking=no -i "~$localuser/.ssh/id_rsa" $sshuser@$destination_ip "sudo systemctl restart nginx" < /dev/null fi ssh -o StrictHostKeyChecking=no -i "~$localuser/.ssh/id_rsa" $sshuser@$destination_ip "sudo systemctl restart cron" < /dev/null diff --git a/includes/core/apps/wordpress-app/scripts/v1/run_upgrade_install_php_84.txt b/includes/core/apps/wordpress-app/scripts/v1/run_upgrade_install_php_84.txt new file mode 100644 index 0000000..11a2301 --- /dev/null +++ b/includes/core/apps/wordpress-app/scripts/v1/run_upgrade_install_php_84.txt @@ -0,0 +1,8 @@ +cd ~ && +sudo -E \rm -f ##SCRIPT_NAME## && +sudo -E wget --no-check-certificate -O ##SCRIPT_COMMON_NAME## ##SCRIPT_COMMON_URL## && +sudo -E dos2unix ##SCRIPT_COMMON_NAME## && +sudo -E wget --no-check-certificate -O ##SCRIPT_NAME## ##SCRIPT_URL## && +export action=##ACTION## domain=##DOMAIN## interactive=##INTERACTIVE## && +sudo -E dos2unix ##SCRIPT_NAME## && +sudo -E bash ##SCRIPT_NAME## diff --git a/includes/core/apps/wordpress-app/tabs-server/logs.php b/includes/core/apps/wordpress-app/tabs-server/logs.php index a0f6c99..1c6eceb 100644 --- a/includes/core/apps/wordpress-app/tabs-server/logs.php +++ b/includes/core/apps/wordpress-app/tabs-server/logs.php @@ -347,6 +347,7 @@ public function get_log_list( $id ) { '/var/log/php8.1-fpm.log' => __( 'PHP 8.1 FPM Log', 'wpcd' ), '/var/log/php8.2-fpm.log' => __( 'PHP 8.2 FPM Log', 'wpcd' ), '/var/log/php8.3-fpm.log' => __( 'PHP 8.3 FPM Log', 'wpcd' ), + '/var/log/php8.4-fpm.log' => __( 'PHP 8.4 FPM Log', 'wpcd' ), '/var/log/auth.log' => __( 'Authorization Log', 'wpcd' ), '/var/log/ufw.log' => __( 'UFW Firewall Log', 'wpcd' ), '/var/log/wp-server-status.log' => __( 'WPCD Server Status Callback Log', 'wpcd' ), diff --git a/includes/core/apps/wordpress-app/tabs-server/services.php b/includes/core/apps/wordpress-app/tabs-server/services.php index 23213ac..f0aeb9a 100644 --- a/includes/core/apps/wordpress-app/tabs-server/services.php +++ b/includes/core/apps/wordpress-app/tabs-server/services.php @@ -387,6 +387,7 @@ public function tab_action( $result, $action, $id ) { case 'php-server-restart-php81': case 'php-server-restart-php82': case 'php-server-restart-php83': + case 'php-server-restart-php84': $result = $this->do_php_restart( $id, $action ); break; case 'php-server-activate-php56': @@ -399,6 +400,7 @@ public function tab_action( $result, $action, $id ) { case 'php-server-activate-php81': case 'php-server-activate-php82': case 'php-server-activate-php83': + case 'php-server-activate-php84': $result = $this->do_php_activation_toggle( $id, $action ); break; case 'php-server-deactivate-php56': @@ -411,6 +413,7 @@ public function tab_action( $result, $action, $id ) { case 'php-server-deactivate-php81': case 'php-server-deactivate-php82': case 'php-server-deactivate-php83': + case 'php-server-deactivate-php84': $result = $this->do_php_activation_toggle( $id, $action ); break; case 'ubuntu-pro-toggle': @@ -1255,6 +1258,7 @@ private function get_php_fields( $id ) { 'php81' => $default_status, 'php82' => $default_status, 'php83' => $default_status, + 'php84' => $default_status, ); // Unset php80 and 81 elements as necessary. @@ -1272,7 +1276,9 @@ private function get_php_fields( $id ) { if ( ! $this->is_php_83_installed( $id ) ) { unset( $php_services_status['php83'] ); } - + if ( ! $this->is_php_84_installed( $id ) ) { + unset( $php_services_status['php84'] ); + } // Add in old php versions (5.6, 7.1, 7.2, 7.3) as necessary. if ( $this->is_old_php_version_installed( $id, '56' ) ) { $php_services_status['php56'] = $default_status; @@ -1959,6 +1965,7 @@ private function refresh_services_status_php( $id, $action ) { 'php81' => 'sudo service php8.1-fpm status', 'php82' => 'sudo service php8.2-fpm status', 'php83' => 'sudo service php8.3-fpm status', + 'php84' => 'sudo service php8.4-fpm status', ); if ( $this->is_old_php_version_installed( $id, '56' ) ) { @@ -2036,6 +2043,7 @@ private function do_php_restart( $id, $action ) { 'php-server-restart-php81' => 'sudo service php8.1-fpm restart', 'php-server-restart-php82' => 'sudo service php8.2-fpm restart', 'php-server-restart-php83' => 'sudo service php8.3-fpm restart', + 'php-server-restart-php84' => 'sudo service php8.4-fpm restart', ); if ( isset( $php_services[ $action ] ) ) { @@ -2138,7 +2146,11 @@ private function do_php_activation_toggle( $id, $action ) { $php_version = 8.3; $php_key = 'php83'; break; - + case 'php-server-activate-php84': + $action = 'php_version_enable'; + $php_version = 8.4; + $php_key = 'php84'; + break; case 'php-server-deactivate-php56': $action = 'php_version_disable'; $php_version = 5.6; @@ -2189,6 +2201,12 @@ private function do_php_activation_toggle( $id, $action ) { $php_version = 8.3; $php_key = 'php83'; break; + case 'php-server-deactivate-php84': + $action = 'php_version_disable'; + $php_version = 8.4; + $php_key = 'php84'; + break; + } // Get the full command to be executed by ssh. @@ -2439,6 +2457,7 @@ public function set_php_service_state( $id, $service, $state ) { 'php-server-restart-php81' => 'php81', 'php-server-restart-php82' => 'php82', 'php-server-restart-php83' => 'php83', + 'php-server-restart-php84' => 'php84', ); if ( isset( $php_services[ $service ] ) ) { diff --git a/includes/core/apps/wordpress-app/tabs-server/tools.php b/includes/core/apps/wordpress-app/tabs-server/tools.php index 87c1ecb..1376028 100644 --- a/includes/core/apps/wordpress-app/tabs-server/tools.php +++ b/includes/core/apps/wordpress-app/tabs-server/tools.php @@ -437,7 +437,7 @@ private function reset_php_default_version( $id, $action ) { } // Check to make sure that the version is a valid version. - if ( ! in_array( $new_php_version, array( '7.4', '7.3', '7.2', '7.1', '5.6', '8.0', '8.1', '8.2', '8.3' ) ) ) { + if ( ! in_array( $new_php_version, array( '7.4', '7.3', '7.2', '7.1', '5.6', '8.0', '8.1', '8.2', '8.3','8.4' ) ) ) { return new \WP_Error( __( 'You must specify a VALID PHP version!', 'wpcd' ) ); } diff --git a/includes/core/apps/wordpress-app/tabs-server/upgrade.php b/includes/core/apps/wordpress-app/tabs-server/upgrade.php index 0006ff2..3b8edfb 100644 --- a/includes/core/apps/wordpress-app/tabs-server/upgrade.php +++ b/includes/core/apps/wordpress-app/tabs-server/upgrade.php @@ -192,7 +192,10 @@ public function tab_action( $result, $action, $id ) { case 'server-upgrade-php83': $result = $this->install_php83( $id, $action ); break; - + case 'server-upgrade-php84': + $result = $this->install_php84( $id, $action ); + break; + case 'server-upgrade-old-php-versions': $result = $this->install_old_php_version( $id, $action ); break; @@ -308,6 +311,11 @@ private function get_upgrade_fields( $id ) { $upgrade_php_83_fields = $this->get_upgrade_fields_php83( $id ); $actions = array_merge( $actions, $upgrade_php_83_fields ); } + // PHP 8.4. + if ( ! $this->is_php_84_installed( $id ) && 'ubuntu1804lts' !== $os ) { + $upgrade_php_84_fields = $this->get_upgrade_fields_php84( $id ); + $actions = array_merge( $actions, $upgrade_php_84_fields ); + } // WP-CLI Upgrade Options. if ( ! $this->is_wpcli210_installed( $id ) ) { @@ -930,6 +938,46 @@ private function get_upgrade_fields_php83( $id ) { } + /** + * Gets the fields to show in the UPGRADE tab in the server details screen + * if PHP 8.4 needs to be installed. + * + * @param int $id the post id of the app cpt record. + * + * @return array Array of actions with key as the action slug and value complying with the structure necessary by metabox.io fields. + */ + private function get_upgrade_fields_php84( $id ) { + + // Set up metabox items. + $actions = array(); + + $upg_desc = __( 'Use this button to install PHP 8.4 if it was released after your server was created. WPCD V 5.9.1 and later automatically installs PHP 8.4 on new servers. But older servers will not have it.', 'wpcd' ); + $upg_desc .= '
'; + $upg_desc .= __( 'Before running this, you should check to see if your server needs to be restarted because of prior upgrades. If so, please restart your server before using this option to install PHP 8.4', 'wpcd' ); + + $actions['server-upgrade-header-php84'] = array( + 'label' => __( '(Optional) Install PHP 8.4', 'wpcd' ), + 'type' => 'heading', + 'raw_attributes' => array( + 'desc' => $upg_desc, + ), + ); + + $actions['server-upgrade-php84'] = array( + 'label' => '', + 'raw_attributes' => array( + 'std' => __( 'Install PHP 8.4 on this server', 'wpcd' ), + // make sure we give the user a confirmation prompt. + 'confirmation_prompt' => __( 'Are you sure you would like to install PHP 8.4 on this server?', 'wpcd' ), + ), + 'type' => 'button', + ); + + + + return $actions; + + } /** * Gets the fields to show in the UPGRADE tab in the server details screen @@ -1861,6 +1909,82 @@ public function install_php83( $id, $action ) { return $result; } + + /** + * Run install script for PHP 8.4 + * + * @param int $id The postID of the server cpt. + * @param string $action The action to be performed (this matches the string required in the bash scripts if bash scripts are used ). + * + * @return boolean success/failure/other + */ + public function install_php84( $id, $action ) { + + // Upgrade History Type. + $upgrade_history_key_type = 'install-php84'; + $upgrade_description = __( 'Installed PHP 8.4', 'wpcd' ); + + // Get data about the server. + $instance = $this->get_server_instance_details( $id ); + + if ( is_wp_error( $instance ) ) { + /* translators: %s is replaced with the internal action name. */ + return new \WP_Error( sprintf( __( 'Unable to execute this request because we cannot get the instance details for action %s', 'wpcd' ), $action ) ); + } + + // Get the full command to be executed by ssh. + $run_cmd = $this->turn_script_into_command( + $instance, + 'run_upgrade_install_php_84.txt', + array( + 'action' => $action, + 'interactive' => 'no', + ) + ); + + // log. + // phpcs:ignore + do_action( 'wpcd_log_error', sprintf( 'attempting to run command for %s = %s ', print_r( $instance, true ), $run_cmd ), 'trace', __FILE__, __LINE__, $instance, false ); //PHPcs warning normally issued because of print_r + + // execute. + $result = $this->execute_ssh( 'generic', $instance, array( 'commands' => $run_cmd ) ); + + // Make sure we don't have a wp_error object being returned... + if ( is_wp_error( $result ) ) { + return new \WP_Error( __( 'There was a problem installing PHP 8.4 - please check the server logs for more information.', 'wpcd' ) ); + } + + // evaluate results. + if ( strpos( $result, 'journalctl -xe' ) !== false ) { + // Looks like there was a problem with restarting the NGINX - So update completion meta, add to history and return message. + $this->update_history( $id, $upgrade_history_key_type, $upgrade_description ); + update_post_meta( $id, 'wpcd_server_php84_installed', 1 ); + /* translators: %s is replaced with the text of the result of the operation. */ + return new \WP_Error( sprintf( __( 'There was a problem restarting the nginx server after the upgrade - here is the full output of the upgrade process: %s', 'wpcd' ), $result ) ); + } + + // If we're here, we know that the nginx server restarted ok so let's do standard success checks. + $success = $this->is_ssh_successful( $result, 'run_upgrade_install_php_84.txt' ); + if ( ! $success ) { + /* translators: %1$s is replaced with the internal action name; %2$s is replaced with the result of the call, usually an error message. */ + return new \WP_Error( sprintf( __( 'Unable to perform action %1$s for server: %2$s', 'wpcd' ), $action, $result ) ); + } else { + // update server field to tag server as being upgraded. + update_post_meta( $id, 'wpcd_server_php84_installed', 1 ); + + // Let user know command is complete and force a page rfresh. + $result = array( + 'msg' => __( 'PHP 8.4 install has been completed - this page will now refresh', 'wpcd' ), + 'refresh' => 'yes', + ); + + // Add to update history. + $this->update_history( $id, $upgrade_history_key_type, $upgrade_description ); + } + + return $result; + + } /** * Run install script for PHP 5.6/7.0/7.1/7.2/7.3/ diff --git a/includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/script-handlers.php b/includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/script-handlers.php index 746821a..f6e554c 100644 --- a/includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/script-handlers.php +++ b/includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/script-handlers.php @@ -505,6 +505,10 @@ public function is_ssh_successful( $result, $command, $action = '' ) { case 'run_upgrade_install_php_83.txt': $return = ( strpos( $result, 'PHP 8.3 has been installed' ) !== false ); break; + case 'run_upgrade_install_php_84.txt': + $return = ( strpos( $result, 'PHP 8.4 has been installed' ) !== false ); + break; + case 'run_upgrade_install_old_php_version.txt': $return = ( strpos( $result, 'has been installed' ) !== false ); break; @@ -1549,6 +1553,16 @@ public function script_placeholders( $array, $script_name, $script_version, $ins $additional ); break; + case 'run_upgrade_install_php_84.txt': + $new_array = array_merge( + array( + 'SCRIPT_URL' => trailingslashit( wpcd_url ) . $this->get_scripts_folder_relative() . $script_version . '/raw/1110-upgrade_install_php_84.txt', + 'SCRIPT_NAME' => '1110-upgrade_install_php_84.sh', + ), + $common_array, + $additional + ); + break; case 'run_upgrade_install_old_php_version.txt': $new_array = array_merge( array( From a036f5a6c1ae24ab33cc46b7adb123f619570909 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Tue, 26 Nov 2024 06:29:41 +0200 Subject: [PATCH 22/24] Fix: Comment out the command to stop PHP-FPM service during domain change to prevent unintended service disruption --- .../core/apps/wordpress-app/scripts/v1/raw/05-change_domain.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/core/apps/wordpress-app/scripts/v1/raw/05-change_domain.txt b/includes/core/apps/wordpress-app/scripts/v1/raw/05-change_domain.txt index 8891c55..eeb2667 100644 --- a/includes/core/apps/wordpress-app/scripts/v1/raw/05-change_domain.txt +++ b/includes/core/apps/wordpress-app/scripts/v1/raw/05-change_domain.txt @@ -199,7 +199,7 @@ sed -i "s/$old_domain/$new_domain/g" /etc/wp-backup.conf 2> /dev/null if [ "$g_webserver_type" = "nginx" ] then php_version=$(ls /etc/php/*/fpm/pool.d/$old_domain.conf | cut -d '/' -f 4) - systemctl stop php$php_version-fpm + # systemctl stop php$php_version-fpm rename_nginx_site_confs elif [ "$g_webserver_type" = "ols" ] || [ "$g_webserver_type" = "ols-enterprise" ] then From cf5dd72b5ee68005049991e470fec18954b2ad0e Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Tue, 26 Nov 2024 13:16:12 +0200 Subject: [PATCH 23/24] wpcd 5.9.2 --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ wpcd.php | 3 ++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5962cb7..08c5a8c 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,50 @@ Note: Even though the entire git development history isn't available on github, [Friendly Release Notes](https://wpclouddeploy.com/category/release-notes/) ## Change Log ## + +5.9.2 +---- + +* Tweak: Renamed function custom_map_meta_cap_for_eslam to custom_map_meta_cap_for_server_access for better clarity and alignment with naming conventions. + +* Tweak: Updated the label for ubuntu2404lts from "Ubuntu 24.04 LTS (Important Restrictions - See Docs!)" to "Ubuntu 24.04 LTS" for cleaner presentation. + +* New: Added support for PHP 8.4 in various components, including version checks, configuration files, and logging. Updated scripts for installation and management of PHP 8.4. + +* New: Added support for PHP 8.4 in server preparation script, including updates to php.ini configurations and Redis installation. + +* Enh: Refactored get_wp_versions to optimize version retrieval by dynamically appending the version parameter to the API request (?version=$min_version), ensuring only relevant versions are fetched directly from the source, thereby eliminating the need for local filtering with array_filter and version_compare + +* Fix: Update passwordless link generation to use domain variable instead of username + +* Enh: Added 'default' => array() to 'logging_and_tracing_types_debug_log' and 'logging_and_tracing_types' fields to properly initialize default selections, ensuring that no log types are pre-selected by default. This avoids potential database performance issues caused by logging all types unnecessarily. + +* Fix: Ensure exclude message text is an array or object before processing to prevent potential errors in logging logic +* Fix: Comment out the command to stop PHP-FPM service during domain change to prevent unintended service disruption + +5.9.1 +---- +* Enh: Optimized post retrieval in `includes/templates/sent_email_details_popup.php` by replacing get_posts with get_post for improved performance and reduced memory usage. +* Enh: Improved get_server_name function to prioritize fetching the server name from the wpcd_server_name meta field, with a fallback to the post title for consistency and better data handling. + +* Enh: Optimized get_server_id_by_instance_id function by replacing get_posts with WP_Query for better performance and scalability. Limited results to a single post and retrieved only post IDs to reduce overhead. Improved logic to handle multiple results gracefully. + +* Enh: Optimized get_app_count function by replacing get_posts with WP_Query, limiting results to IDs only, and using found_posts to reduce memory usage and improve performance. + +* Enh: Improved wpcd_sent_emails_list_pagination by switching from get_posts to WP_Query for efficient querying and better performance. Optimized logic for retrieving total counts and paginated results, reducing memory usage and improving scalability. + +* Enh: Improved notification retrieval by replacing get_posts with get_post for better performance and standardized metadata access with get_post_meta for consistency and efficiency. + +* Enh: Optimized wpcd_is_server_available_for_commands by replacing get_posts with WP_Query, limiting results to a single post, and reducing memory usage with fields => 'ids'. Improved overall performance and scalability. + +* Enh: Simplified wpcd_get_permissions by directly accessing post titles from the WP_Post object and handling IDs efficiently when fields => 'ids' is used. Improved code readability and performance. + +* Enh: Refactored wpcd_get_permission_groups to use WP_Query with optional fields => 'ids', improving performance and memory efficiency. Simplified metadata and title retrieval by accessing the WP_Post object directly. + +* Enh: Replaced get_posts with WP_Query in WPCD_POSTS_TEAM class for improved performance and memory efficiency. Limited results to a single post and updated logic for count retrieval. + + + 5.9.0 ----- * Fix : the caching issue related to checking the plugin version. diff --git a/wpcd.php b/wpcd.php index d6a2127..8a85ad0 100644 --- a/wpcd.php +++ b/wpcd.php @@ -3,7 +3,7 @@ Plugin Name: WPCloudDeploy Plugin URI: https://developvi.com Description: Deploy and manage cloud servers and apps from inside the WordPress Admin dashboard. -Version: 5.9.1 +Version: 5.9.2 Requires at least: 5.8 Requires PHP: 7.4 Item Id: 1493 @@ -942,6 +942,7 @@ public function get_list_of_absent_crons() { public function wpcd_append_support_and_faq_links( $links_array, $plugin_file_name, $plugin_data, $status ) { if ( strpos( $plugin_file_name, basename( __FILE__ ) ) ) { + $links_array[] = ' Sponsor'; // You can still use `array_unshift()` to add links at the beginning. $links_array[] = 'Quick Start'; $links_array[] = 'Documentation'; From d4705bf13819b038eed7d52e97ef5e6838bc68e2 Mon Sep 17 00:00:00 2001 From: eslam el sherif Date: Tue, 26 Nov 2024 13:38:01 +0200 Subject: [PATCH 24/24] Added PayPal donation and Discord community links to plugin action links --- README.md | 2 +- wpcd.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 08c5a8c..df1af79 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ Note: Even though the entire git development history isn't available on github, * Fix: Ensure exclude message text is an array or object before processing to prevent potential errors in logging logic * Fix: Comment out the command to stop PHP-FPM service during domain change to prevent unintended service disruption - +* New: Added PayPal donation and Discord community links to plugin action links 5.9.1 ---- * Enh: Optimized post retrieval in `includes/templates/sent_email_details_popup.php` by replacing get_posts with get_post for improved performance and reduced memory usage. diff --git a/wpcd.php b/wpcd.php index 8a85ad0..3807c0f 100644 --- a/wpcd.php +++ b/wpcd.php @@ -943,6 +943,7 @@ public function wpcd_append_support_and_faq_links( $links_array, $plugin_file_na if ( strpos( $plugin_file_name, basename( __FILE__ ) ) ) { $links_array[] = ' Sponsor'; + $links_array[] = ' Join Our Discord Community'; // You can still use `array_unshift()` to add links at the beginning. $links_array[] = 'Quick Start'; $links_array[] = 'Documentation'; @@ -953,6 +954,7 @@ public function wpcd_append_support_and_faq_links( $links_array, $plugin_file_na $links_array[] = 'Premium Options'; $links_array[] = 'Support'; + } return $links_array;