PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.4.0
Defender Security – Malware Scanner, Login Security & Firewall v5.4.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / model / class-scan-item.php

class-scan-item.php in Defender Security – Malware Scanner, Login Security & Firewall 5.4.0, at src/model/class-scan-item.php

132 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles interactions with the database for scan items.
4 *
5 * @package WP_Defender\Model
6 */
7
8 namespace WP_Defender\Model;
9
10 use WP_Defender\DB;
11 use WP_Defender\Behavior\Scan_Item\Vuln_Result;
12 use WP_Defender\Behavior\Scan_Item\Malware_Result;
13
14 /**
15 * Model for scan item table.
16 */
17 class Scan_Item extends DB {
18
19 // For 'File change detection' option.
20 public const TYPE_INTEGRITY = 'core_integrity', TYPE_PLUGIN_CHECK = 'plugin_integrity';
21 // For 'Known vulnerabilities' and 'Suspicious code' options.
22 public const TYPE_VULNERABILITY = 'vulnerability', TYPE_SUSPICIOUS = 'malware';
23 // Different statuses.
24 public const STATUS_ACTIVE = 'active', STATUS_IGNORE = 'ignore';
25
26 /**
27 * Defines the table name.
28 *
29 * @var string
30 */
31 protected $table = 'defender_scan_item';
32 /**
33 * Defines the primary key.
34 *
35 * @var int
36 * @defender_property
37 */
38 public $id;
39 /**
40 * Defines a public property for storing the parent ID.
41 *
42 * @var int
43 * @defender_property
44 */
45 public $parent_id;
46 /**
47 * Type of the issue, base on this we will load the behavior.
48 *
49 * @var string
50 * @defender_property
51 */
52 public $type;
53 /**
54 * Contain generic data.
55 *
56 * @var array
57 * @defender_property
58 */
59 public $raw_data = array();
60
61 /**
62 * Defines a public property for storing the status.
63 *
64 * @var string
65 * @defender_property
66 */
67 public $status;
68
69 /**
70 * Get the total of each type of provided status either STATUS_ACTIVE or STATUS_IGNORE.
71 *
72 * @param int $parent_id The primary key of the scan table.
73 * @param string $status Active or ignore status of scan item(s).
74 *
75 * @return array Return array of group and all total.
76 */
77 public function get_types_total( $parent_id, $status ) {
78 global $wpdb;
79
80 $records = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
81 $wpdb->prepare(
82 "SELECT IFNULL(`type`, 'all') as `item_type`, count(*) as `type_total` FROM {$wpdb->base_prefix}defender_scan_item WHERE `parent_id` = %d AND `status` = %s Group BY `type` WITH ROLLUP",
83 $parent_id,
84 $status
85 )
86 );
87
88 $results = array();
89 foreach ( $records as $record ) {
90 $results[ $record->item_type ] = (int) $record->type_total;
91 }
92
93 return $results;
94 }
95
96 /**
97 * Deletes a record from the database by its ID.
98 *
99 * @param int $id The ID of the record to be deleted.
100 *
101 * @return bool Returns true if the record was successfully deleted, false otherwise.
102 */
103 public function delete_by_id( int $id ): bool {
104 $delete = self::get_orm()->get_repository( self::class )
105 ->delete( array( 'id' => $id ) );
106
107 return is_int( $delete );
108 }
109
110 /**
111 * Import data into the model.
112 *
113 * @param mixed $data The data array to import values from.
114 *
115 * @return void
116 */
117 public function import( $data ): void {
118 parent::import( $data );
119 switch ( $this->type ) {
120 // Add other behaviors here.
121 case self::TYPE_SUSPICIOUS:
122 $this->attach_behavior( Malware_Result::class, Malware_Result::class );
123 break;
124 case self::TYPE_VULNERABILITY:
125 $this->attach_behavior( Vuln_Result::class, Vuln_Result::class );
126 break;
127 default:
128 break;
129 }
130 }
131 }
132