get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber "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 AND `type` IN ($placeholders)" . // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared ' Group BY `type` WITH ROLLUP', array_merge( array( $parent_id, $status ), $types ) ) ); $results = array(); foreach ( $records as $record ) { $results[ $record->item_type ] = (int) $record->type_total; } return $results; } /** * Deletes a record from the database by its ID. * * @param int $id The ID of the record to be deleted. * * @return bool Returns true if the record was successfully deleted, false otherwise. */ public function delete_by_id( int $id ): bool { $delete = self::get_orm()->get_repository( self::class ) ->delete( array( 'id' => $id ) ); return is_int( $delete ); } /** * Import data into the model. * * @param mixed $data The data array to import values from. * * @return void */ public function import( $data ): void { parent::import( $data ); // Add behaviors. switch ( $this->type ) { case self::TYPE_SUSPICIOUS: $this->attach_behavior( Malware_Result::class, Malware_Result::class ); break; case self::TYPE_VULNERABILITY: $this->attach_behavior( Vuln_Result::class, Vuln_Result::class ); break; case self::TYPE_PLUGIN_CLOSED: case self::TYPE_PLUGIN_OUTDATED: $this->attach_behavior( Abandoned_Result::class, Abandoned_Result::class ); break; default: break; } } /** * Get all Scan types. * * @return array */ public static function get_all_scan_types(): array { return array( self::TYPE_VULNERABILITY, self::TYPE_SUSPICIOUS, self::TYPE_INTEGRITY, self::TYPE_PLUGIN_CHECK, self::TYPE_PLUGIN_CLOSED, self::TYPE_PLUGIN_OUTDATED, ); } /** * Get all scan statuses. * * @return array */ public static function get_all_scan_statuses(): array { return array( self::STATUS_ACTIVE, self::STATUS_IGNORE, ); } }