| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Handles the scheduling and sending of malware scan reports. | |
| 3 | + * Malware Scanning report notification stub for free version. | |
| 4 | 4 | * |
| 5 | 5 | * @package WP_Defender\Model\Notification |
| 6 | 6 | */ |
| 7 | 7 | |
| @@ -6,22 +6,13 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace WP_Defender\Model\Notification; |
| 9 | 9 | |
| 10 | -use DateTime; | |
| 11 | -use Exception; | |
| 12 | -use WP_Defender\Controller\Scan; | |
| 13 | -use WP_Defender\Model\Notification; | |
| 14 | -use WP_Defender\Model\Scan as Model_Scan; | |
| 15 | -use WP_Defender\Traits\Scan_Email_Template; | |
| 16 | - | |
| 17 | 10 | /** |
| 18 | - * Handles the scheduling and sending of malware scan reports. | |
| 11 | + * Malware Scanning – Reporting. | |
| 19 | 12 | */ |
| 20 | -class Malware_Report extends Notification { | |
| 13 | +class Malware_Report extends Free_Report { | |
| 21 | 14 | |
| 22 | - use Scan_Email_Template; | |
| 23 | - | |
| 24 | 15 | /** |
| 25 | 16 | * Table name. |
| 26 | 17 | * |
| 27 | 18 | * @var string |
| @@ -26,8 +17,9 @@ | ||
| 26 | 17 | * |
| 27 | 18 | * @var string |
| 28 | 19 | */ |
| 29 | 20 | protected $table = 'wd_malware_scanning_report'; |
| 21 | + | |
| 30 | 22 | /** |
| 31 | 23 | * Slug identifier for the malware report. |
| 32 | 24 | * |
| 33 | 25 | * @var string |
| @@ -34,102 +26,32 @@ | ||
| 34 | 26 | */ |
| 35 | 27 | public const SLUG = 'malware-report'; |
| 36 | 28 | |
| 37 | 29 | /** |
| 38 | - * Constructor method. | |
| 39 | - * Sets default values for the class. | |
| 30 | + * Sets default values. | |
| 40 | 31 | */ |
| 41 | 32 | protected function before_load(): void { |
| 42 | - $default = array( | |
| 43 | - 'slug' => self::SLUG, | |
| 44 | - 'title' => esc_html__( 'Malware Scanning - Reporting', 'defender-security' ), | |
| 45 | - 'status' => self::STATUS_DISABLED, | |
| 46 | - 'description' => esc_html__( | |
| 47 | - 'Automatically run regular scans of your website and email you reports.', | |
| 48 | - 'defender-security' | |
| 49 | - ), | |
| 50 | - // @since 3.0.0 Fix 'Guest'-line. | |
| 51 | - 'in_house_recipients' => is_user_logged_in() ? array( $this->get_default_user() ) : array(), | |
| 52 | - 'out_house_recipients' => array(), | |
| 53 | - 'type' => 'report', | |
| 54 | - // @since 2.7.0 Add Scheduled Scanning to Malware settings. | |
| 55 | - // Hide Schedule and 'dry_run' fields on UI but no delete for backward compatibility with Scan settings, the config structure and the Hub. | |
| 56 | - 'frequency' => 'weekly', | |
| 57 | - 'day' => 'sunday', | |
| 58 | - 'day_n' => 1, | |
| 59 | - 'time' => '4:00', | |
| 60 | - 'dry_run' => false, | |
| 61 | - 'configs' => array( | |
| 62 | - 'always_send' => false, | |
| 63 | - 'error_send' => false, | |
| 64 | - 'template' => $this->get_email_template(), | |
| 65 | - ), | |
| 33 | + $this->import( | |
| 34 | + array_merge( | |
| 35 | + $this->base_defaults(), | |
| 36 | + array( | |
| 37 | + 'slug' => self::SLUG, | |
| 38 | + 'title' => esc_html__( 'Issue - Reporting', 'defender-security' ), | |
| 39 | + 'description' => esc_html__( | |
| 40 | + 'Automatically run regular scans of your website and email you reports.', | |
| 41 | + 'defender-security' | |
| 42 | + ), | |
| 43 | + 'configs' => array( | |
| 44 | + 'always_send' => false, | |
| 45 | + 'error_send' => false, | |
| 46 | + 'template' => array(), | |
| 47 | + ), | |
| 48 | + ) | |
| 49 | + ) | |
| 66 | 50 | ); |
| 67 | - $this->import( $default ); | |
| 68 | 51 | } |
| 69 | 52 | |
| 70 | 53 | /** |
| 71 | - * Checks if the "Scheduled Scan" is checked and sends the malware scan report if necessary. | |
| 72 | - * | |
| 73 | - * @return bool Returns true if the scan report should be sent, false otherwise. | |
| 74 | - */ | |
| 75 | - public function maybe_send(): bool { | |
| 76 | - // @since 2.7.0 First, check "Scheduled Scan" is checked or not. | |
| 77 | - if ( ! ( new \WP_Defender\Model\Setting\Scan() )->scheduled_scanning ) { | |
| 78 | - return false; | |
| 79 | - } | |
| 80 | - | |
| 81 | - if ( $this->last_sent <= 0 || $this->est_timestamp <= 0 ) { | |
| 82 | - $this->last_sent = $this->est_timestamp; | |
| 83 | - $this->est_timestamp = $this->get_next_run()->getTimestamp(); | |
| 84 | - $this->save(); | |
| 85 | - } | |
| 86 | - $time = apply_filters( 'defender_current_time_for_report', new DateTime( 'now', wp_timezone() ) ); | |
| 87 | - // Testing. | |
| 88 | - if ( defined( 'WP_DEFENDER_TESTING' ) && true === constant( 'WP_DEFENDER_TESTING' ) ) { | |
| 89 | - return true; | |
| 90 | - } | |
| 91 | - | |
| 92 | - // Check by 'always_send' will be after scanning is complete. | |
| 93 | - return $time->getTimestamp() >= $this->est_timestamp; | |
| 94 | - } | |
| 95 | - | |
| 96 | - /** | |
| 97 | - * Sends the email. | |
| 98 | - * Retrieves data based on logic. Steps: | |
| 99 | - * 1) check the current active scan, | |
| 100 | - * 2) if there isn't active scan then check the latest scan, | |
| 101 | - * 3) save the report settings, | |
| 102 | - * 4) run new scan. | |
| 103 | - * | |
| 104 | - * @return void | |
| 105 | - * @throws Exception When an error occurs. | |
| 106 | - */ | |
| 107 | - public function send() { | |
| 108 | - // The current status. | |
| 109 | - $active = Model_Scan::get_active(); | |
| 110 | - if ( is_object( $active ) ) { | |
| 111 | - // Scan is running. | |
| 112 | - return; | |
| 113 | - } | |
| 114 | - // Check the latest scan. | |
| 115 | - $model = Model_Scan::get_last(); | |
| 116 | - if ( ! is_object( $model ) ) { | |
| 117 | - return; | |
| 118 | - } | |
| 119 | - // Save the report settings. | |
| 120 | - $this->last_sent = $this->est_timestamp; | |
| 121 | - $this->est_timestamp = $this->get_next_run()->getTimestamp(); | |
| 122 | - $this->save(); | |
| 123 | - // Run scan. | |
| 124 | - $scan = Model_Scan::create( true ); | |
| 125 | - if ( is_object( $scan ) && ! is_wp_error( $scan ) ) { | |
| 126 | - $scan_controller = wd_di()->get( Scan::class ); | |
| 127 | - $scan_controller->do_async_scan( 'report' ); | |
| 128 | - } | |
| 129 | - } | |
| 130 | - | |
| 131 | - /** | |
| 132 | 54 | * Define settings labels. |
| 133 | 55 | * |
| 134 | 56 | * @return array |
| 135 | 57 | */ |
| @@ -134,10 +56,10 @@ | ||
| 134 | 56 | * @return array |
| 135 | 57 | */ |
| 136 | 58 | public function labels(): array { |
| 137 | 59 | return array( |
| 138 | - 'report' => esc_html__( 'Malware Scanning - Reporting', 'defender-security' ), | |
| 139 | - 'always_send' => esc_html__( 'Send notifications when no issues are detected', 'defender-security' ), | |
| 60 | + 'report' => esc_html__( 'Issue - Reporting', 'defender-security' ), | |
| 61 | + 'always_send' => esc_html__( 'Send alerts when no issues are detected', 'defender-security' ), | |
| 140 | 62 | 'report_subscribers' => esc_html__( 'Recipients', 'defender-security' ), |
| 141 | 63 | 'day' => esc_html__( 'Day of', 'defender-security' ), |
| 142 | 64 | 'day_n' => esc_html__( 'Day of', 'defender-security' ), |
| 143 | 65 | 'time' => esc_html__( 'Time of day', 'defender-security' ), |
| @@ -145,29 +67,26 @@ | ||
| 145 | 67 | ); |
| 146 | 68 | } |
| 147 | 69 | |
| 148 | 70 | /** |
| 149 | - * Returns the next run date for the malware report in the format suitable for the Hub. | |
| 71 | + * Returns 'Never' — report cannot run in the free version. | |
| 150 | 72 | * |
| 151 | - * @return string The formatted next run date for the malware report, or 'Never' if the report is not active. | |
| 73 | + * @return string | |
| 152 | 74 | */ |
| 153 | 75 | public function get_next_run_for_hub(): string { |
| 154 | - return self::STATUS_ACTIVE === $this->status | |
| 155 | - ? $this->persistent_hub_datetime_format( $this->est_timestamp ) | |
| 156 | - : esc_html__( 'Never', 'defender-security' ); | |
| 76 | + return esc_html__( 'Never', 'defender-security' ); | |
| 157 | 77 | } |
| 158 | 78 | |
| 159 | 79 | /** |
| 160 | 80 | * Additional converting rules. |
| 161 | 81 | * |
| 162 | - * @param array $configs The configuration data. | |
| 82 | + * @param array $configs The configuration data. | |
| 163 | 83 | * |
| 164 | 84 | * @return array The type-casted configuration data. |
| 165 | - * @since 3.1.0 | |
| 166 | 85 | */ |
| 167 | 86 | public function type_casting( $configs ): array { |
| 168 | - $configs['always_send'] = (bool) $configs['always_send']; | |
| 169 | - $configs['error_send'] = (bool) $configs['error_send']; | |
| 87 | + $configs['always_send'] = (bool) ( $configs['always_send'] ?? false ); | |
| 88 | + $configs['error_send'] = (bool) ( $configs['error_send'] ?? false ); | |
| 170 | 89 | |
| 171 | 90 | return $configs; |
| 172 | 91 | } |
| 173 | 92 | } |