| @@ -25,22 +25,22 @@ | ||
| 25 | 25 | $hidden = $this->get_hidden_columns(); |
| 26 | 26 | $sortable = $this->get_sortable_columns(); |
| 27 | 27 | $data = $this->table_data(); |
| 28 | 28 | |
| 29 | - usort( $data, array( &$this, 'sort_data' ) ); | |
| 29 | + usort( $data, [ &$this, 'sort_data' ] ); | |
| 30 | 30 | $per_page = 10; |
| 31 | 31 | $current_page = $this->get_pagenum(); |
| 32 | 32 | $total_items = count( $data ); |
| 33 | 33 | |
| 34 | 34 | $this->set_pagination_args( |
| 35 | - array( | |
| 35 | + [ | |
| 36 | 36 | 'total_items' => $total_items, |
| 37 | 37 | 'per_page' => $per_page, |
| 38 | - ) | |
| 38 | + ] | |
| 39 | 39 | ); |
| 40 | 40 | |
| 41 | 41 | $data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ), $per_page ); |
| 42 | - $this->_column_headers = array( $columns, $hidden, $sortable ); | |
| 42 | + $this->_column_headers = [ $columns, $hidden, $sortable ]; | |
| 43 | 43 | $this->items = $data; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
| @@ -48,16 +48,17 @@ | ||
| 48 | 48 | * |
| 49 | 49 | * @return Array |
| 50 | 50 | */ |
| 51 | 51 | public function get_columns() { |
| 52 | - return array( | |
| 52 | + return [ | |
| 53 | 53 | 'id' => 'ID', |
| 54 | 54 | 'title' => 'Title', |
| 55 | 55 | 'url' => 'URL', |
| 56 | 56 | 'activated' => 'License Status', |
| 57 | 57 | 'firewall_status' => 'Firewall Status', |
| 58 | + 'migration' => 'Rerun Migration', | |
| 58 | 59 | 'edit' => 'Manage', |
| 59 | - ); | |
| 60 | + ]; | |
| 60 | 61 | } |
| 61 | 62 | |
| 62 | 63 | /** |
| 63 | 64 | * Define which columns are hidden |
| @@ -64,9 +65,9 @@ | ||
| 64 | 65 | * |
| 65 | 66 | * @return Array |
| 66 | 67 | */ |
| 67 | 68 | public function get_hidden_columns() { |
| 68 | - return array(); | |
| 69 | + return []; | |
| 69 | 70 | } |
| 70 | 71 | |
| 71 | 72 | /** |
| 72 | 73 | * Define the sortable columns |
| @@ -73,9 +74,9 @@ | ||
| 73 | 74 | * |
| 74 | 75 | * @return Array |
| 75 | 76 | */ |
| 76 | 77 | public function get_sortable_columns() { |
| 77 | - return array( 'title' => array( 'title', false ) ); | |
| 78 | + return [ 'title' => [ 'title', false ] ]; | |
| 78 | 79 | } |
| 79 | 80 | |
| 80 | 81 | /** |
| 81 | 82 | * Get the table data |
| @@ -82,9 +83,12 @@ | ||
| 82 | 83 | * |
| 83 | 84 | * @return Array |
| 84 | 85 | */ |
| 85 | 86 | private function table_data() { |
| 86 | - $data = array(); | |
| 87 | + global $wpdb; | |
| 88 | + $data = []; | |
| 89 | + $free = get_option( 'patchstack_license_free', 0 ) == 1; | |
| 90 | + $nonce = wp_create_nonce( 'patchstack-migration' ); | |
| 87 | 91 | |
| 88 | 92 | $blogs_ids = get_sites(); |
| 89 | 93 | foreach ( $blogs_ids as $b ) { |
| 90 | 94 | $site_info = get_blog_details( $b->blog_id ); |
| @@ -107,19 +111,38 @@ | ||
| 107 | 111 | |
| 108 | 112 | if ( ! isset( $_GET['s'] ) || $match ) { |
| 109 | 113 | $is_firewall_enabled = get_blog_option( $b->blog_id, 'patchstack_basic_firewall' ); |
| 110 | 114 | $is_activated = get_blog_option( $b->blog_id, 'patchstack_clientid', '' ) != ''; |
| 115 | + $prefix = $wpdb->get_blog_prefix( $b->blog_id ); | |
| 111 | 116 | |
| 112 | - $data[] = array( | |
| 117 | + // Determine if the site has any missing migrations. | |
| 118 | + $has_missing = false; | |
| 119 | + if ($is_activated) { | |
| 120 | + foreach( [ 'patchstack_firewall_log', 'patchstack_logic', 'patchstack_event_log' ] as $table ) { | |
| 121 | + $result = $wpdb->get_results("SHOW TABLES LIKE '" . $prefix . $table . "'"); | |
| 122 | + if ( !$result ) { | |
| 123 | + $has_missing = true; | |
| 124 | + } | |
| 125 | + } | |
| 126 | + } | |
| 127 | + | |
| 128 | + $data[] = [ | |
| 113 | 129 | 'id' => (int) $b->blog_id, |
| 114 | 130 | 'title' => esc_html( $b->blogname ), |
| 115 | 131 | 'url' => '<a href="' . esc_url( $site_info->siteurl ). '">' . esc_url( $site_info->siteurl ) . '</a>', |
| 116 | 132 | 'activated' => $is_activated ? 'Activated' : 'Deactivated', |
| 117 | - 'firewall_status' => $is_firewall_enabled ? 'Enabled' : 'Disabled', | |
| 133 | + 'firewall_status' => $is_firewall_enabled && ! $free ? 'Enabled' : 'Disabled', | |
| 118 | 134 | 'edit' => $is_activated ? '<a href="' . esc_url( get_admin_url( $b->blog_id ) ) . 'options-general.php?page=patchstack">Edit Settings</a>' : '', |
| 119 | - ); | |
| 135 | + 'migration' => '<a href="' . esc_url( add_query_arg( | |
| 136 | + [ | |
| 137 | + 'PatchstackNonce' => $nonce, | |
| 138 | + 'site' => $b->blog_id | |
| 139 | + ] | |
| 140 | + ) ) . '">' . ($has_missing ? 'Run' : 'Rerun') . ' Database Migration</a>', | |
| 141 | + ]; | |
| 120 | 142 | } |
| 121 | 143 | } |
| 144 | + | |
| 122 | 145 | return $data; |
| 123 | 146 | } |
| 124 | 147 | |
| 125 | 148 | /** |
| @@ -136,8 +159,9 @@ | ||
| 136 | 159 | case 'title': |
| 137 | 160 | case 'url': |
| 138 | 161 | case 'activated': |
| 139 | 162 | case 'firewall_status': |
| 163 | + case 'migration': | |
| 140 | 164 | case 'edit': |
| 141 | 165 | return $item[ $column_name ]; |
| 142 | 166 | default: |
| 143 | 167 | return print_r( $item, true ); |