/var/www/html_uk/wp-content/plugins/automatewoo/includes/Notifications/SystemChecks.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php

namespace AutomateWoo\Notifications;

use 
Automattic\WooCommerce\Admin\Notes\Note;
use 
Automattic\WooCommerce\Admin\Notes\NoteTraits;

use 
AutomateWoo\Admin;
use 
AutomateWoo\SystemChecks\ActionSchedulerJobsRunning;
use 
AutomateWoo\SystemChecks\DatabaseTablesExist;

defined'ABSPATH' ) || exit;

/**
 * Class to run system checks periodically and add a notification if any fail
 *
 * @since 5.8.5
 *
 * @package AutomateWoo\Notifications
 */
class SystemChecks extends AbstractNotification {
    use 
NoteTraits;

    const 
NOTE_NAME 'automatewoo-system-checks';

    
/**
     * An array of all system check classes to run.
     *
     * @var array
     */
    
private $system_checks;

    
/**
     * When to process this notification.
     *
     * @return string
     */
    
public function notification_type(): string {
        return 
Notifications::ACTIVATION_OR_UPDATE;
    }

    
/**
     * Get the title of the notification.
     *
     * @return string
     */
    
public static function get_title(): string {
        return 
__'Failed System Checks''automatewoo' );
    }

    
/**
     * Get the contents of the notification.
     *
     * @return string
     */
    
public static function get_content(): string {
        return 
__'AutomateWoo system status check has found issues.''automatewoo' );
    }

    
/**
     * Return Note object.
     *
     * @see Automattic\WooCommerce\Admin\Notes\Note
     *
     * @return Note
     */
    
public static function get_note(): Note {
        
$note parent::get_note();

        
$note->add_action(
            
'aw-system-check-details',
            
__'View details''automatewoo' ),
            
Admin::page_url'status' )
        );

        return 
$note;
    }

    
/**
     * Get all system checks
     *
     * @return array
     */
    
public function get_system_checks(): array {
        if ( ! isset( 
$this->system_checks ) ) {
            
$this->system_checks array_map(
                function ( 
$system_check ) {
                    return new 
$system_check();
                },
                
apply_filters(
                    
'automatewoo/system_checks',
                    [
                        
ActionSchedulerJobsRunning::class,
                        
DatabaseTablesExist::class,
                    ]
                )
            );
        }

        return 
$this->system_checks;
    }

    
/**
     * Check if the notification should be added.
     *
     * @return bool
     */
    
public function should_be_added(): bool {
        
$checks $this->get_system_checks();

        foreach ( 
$checks as $check ) {
            if ( ! 
$check->high_priority ) {
                continue;
            }

            
$response $check->run();
            if ( ! isset( 
$response['success'] ) || true !== $response['success'] ) {
                return 
true;
            }
        }

        return 
false;
    }
}