From ed93adbad9c77964183ed1518d6bffef4dfdc372 Mon Sep 17 00:00:00 2001 From: SVFCode Date: Thu, 12 Dec 2024 09:34:16 +0300 Subject: [PATCH] Upd. Scan. Improved delete action. (#445) --- inc/spbc-scanner.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/inc/spbc-scanner.php b/inc/spbc-scanner.php index 696dd9e16..8e7aca31e 100644 --- a/inc/spbc-scanner.php +++ b/inc/spbc-scanner.php @@ -347,6 +347,8 @@ function spbc_scanner_file_delete_handler($file_id) } $root_path = spbc_get_root_path(); + $response_content_ok = false; + $response_content_admin_ok = false; // Getting file info. $sql = 'SELECT * FROM ' . SPBC_TBL_SCAN_FILES . ' WHERE fast_hash = %s LIMIT 1'; @@ -374,38 +376,36 @@ function spbc_scanner_file_delete_handler($file_id) : array('error' => 'FILE_IS_REQUIRED_IN_PHP_INI'); } - // Getting file && API call + // Getting file and prechecking website $remembered_file_content = file_get_contents($file_path); - $response_content_before_actions = HTTP::getContentFromURL(get_option('home')); - $response_content_admin_before_actions = HTTP::getContentFromURL(get_option('home') . '/wp-admin'); + $precheck_public = wp_remote_get(get_option('home')); + $precheck_admin = wp_remote_get(get_option('home') . '/wp-admin'); + $result = unlink($file_path); if (!$result) { return array('error' => 'FILE_COULDNT_DELETE'); } - $response_content = HTTP::getContentFromURL(get_option('home')); - if ($response_content === $response_content_before_actions) { + // if not work before and after unlink - it's ok, if both work - it's ok too and much better + $postcheck_public = wp_remote_get(get_option('home')); + if ((is_wp_error($postcheck_public) && is_wp_error($precheck_public)) || + (!is_wp_error($postcheck_public) && !is_wp_error($precheck_public) && + wp_remote_retrieve_response_code($postcheck_public) === wp_remote_retrieve_response_code($precheck_public)) + ) { $response_content_ok = true; - } else { - if (is_string($response_content) && !spbc_search_page_errors($response_content)) { - $response_content_ok = true; - } else { - $response_content_ok = false; - } } - $response_content_admin = HTTP::getContentFromURL(get_option('home') . '/wp-admin'); - if ($response_content_admin === $response_content_admin_before_actions) { + // if not work before and after unlink - it's ok, if both work - it's ok too and much better + $postcheck_admin = wp_remote_get(get_option('home') . '/wp-admin'); + if ((is_wp_error($postcheck_admin) && is_wp_error($precheck_admin)) || + (!is_wp_error($postcheck_admin) && !is_wp_error($precheck_admin) && + wp_remote_retrieve_response_code($postcheck_admin) === wp_remote_retrieve_response_code($precheck_admin)) + ) { $response_content_admin_ok = true; - } else { - if (is_string($response_content_admin) && !spbc_search_page_errors($response_content_admin)) { - $response_content_admin_ok = true; - } else { - $response_content_admin_ok = false; - } } + // general check to revert if something went wrong if (!$response_content_admin_ok || !$response_content_ok) { $result = file_put_contents($file_path, $remembered_file_content); $output = array('error' => 'WEBSITE_RESPONSE_BAD');