| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | class Red_Database_Status { |
| 4 | 4 | // Used in < 3.7 versions of Redirection, but since migrated to general settings |
| 5 | 5 | const OLD_DB_VERSION = 'redirection_version'; |
| 6 | - const DB_UPGRADE_STAGE = 'redirection_database_stage'; | |
| 6 | + const DB_UPGRADE_STAGE = 'database_stage'; | |
| 7 | 7 | |
| 8 | 8 | const RESULT_OK = 'ok'; |
| 9 | 9 | const RESULT_ERROR = 'error'; |
| 10 | 10 | |
| @@ -26,17 +26,24 @@ | ||
| 26 | 26 | $this->status = self::STATUS_OK; |
| 27 | 27 | |
| 28 | 28 | if ( $this->needs_installing() ) { |
| 29 | 29 | $this->status = self::STATUS_NEED_INSTALL; |
| 30 | - } elseif ( $this->needs_updating() ) { | |
| 30 | + } | |
| 31 | + | |
| 32 | + $this->load_stage(); | |
| 33 | + | |
| 34 | + if ( $this->needs_updating() ) { | |
| 31 | 35 | $this->status = self::STATUS_NEED_UPDATING; |
| 32 | 36 | } |
| 37 | + } | |
| 33 | 38 | |
| 34 | - $info = get_option( self::DB_UPGRADE_STAGE ); | |
| 35 | - if ( $info ) { | |
| 36 | - $this->stage = isset( $info['stage'] ) ? $info['stage'] : false; | |
| 37 | - $this->stages = isset( $info['stages'] ) ? $info['stages'] : []; | |
| 38 | - $this->status = isset( $info['status'] ) ? $info['status'] : false; | |
| 39 | + public function load_stage() { | |
| 40 | + $settings = red_get_options(); | |
| 41 | + | |
| 42 | + if ( isset( $settings[ self::DB_UPGRADE_STAGE ] ) ) { | |
| 43 | + $this->stage = isset( $settings[ self::DB_UPGRADE_STAGE ]['stage'] ) ? $settings[ self::DB_UPGRADE_STAGE ]['stage'] : false; | |
| 44 | + $this->stages = isset( $settings[ self::DB_UPGRADE_STAGE ]['stages'] ) ? $settings[ self::DB_UPGRADE_STAGE ]['stages'] : []; | |
| 45 | + $this->status = isset( $settings[ self::DB_UPGRADE_STAGE ]['status'] ) ? $settings[ self::DB_UPGRADE_STAGE ]['status'] : false; | |
| 39 | 46 | } |
| 40 | 47 | } |
| 41 | 48 | |
| 42 | 49 | /** |
| @@ -164,9 +171,9 @@ | ||
| 164 | 171 | $this->stage = false; |
| 165 | 172 | $this->stages = []; |
| 166 | 173 | $this->debug = []; |
| 167 | 174 | |
| 168 | - delete_option( self::DB_UPGRADE_STAGE ); | |
| 175 | + red_set_options( [ self::DB_UPGRADE_STAGE => false ] ); | |
| 169 | 176 | $this->clear_cache(); |
| 170 | 177 | } |
| 171 | 178 | |
| 172 | 179 | public function finish() { |
| @@ -190,8 +197,9 @@ | ||
| 190 | 197 | /** |
| 191 | 198 | * Move current stage on to the next |
| 192 | 199 | */ |
| 193 | 200 | public function set_next_stage() { |
| 201 | + $this->debug = []; | |
| 194 | 202 | $stage = $this->get_current_stage(); |
| 195 | 203 | |
| 196 | 204 | if ( $stage ) { |
| 197 | 205 | $stage = $this->get_next_stage( $stage ); |
| @@ -300,13 +308,17 @@ | ||
| 300 | 308 | $this->save_details(); |
| 301 | 309 | } |
| 302 | 310 | |
| 303 | 311 | private function save_details() { |
| 304 | - update_option( self::DB_UPGRADE_STAGE, [ | |
| 305 | - 'stage' => $this->stage, | |
| 306 | - 'stages' => $this->stages, | |
| 307 | - 'status' => $this->status, | |
| 308 | - ] ); | |
| 312 | + $stages = [ | |
| 313 | + self::DB_UPGRADE_STAGE => [ | |
| 314 | + 'stage' => $this->stage, | |
| 315 | + 'stages' => $this->stages, | |
| 316 | + 'status' => $this->status, | |
| 317 | + ], | |
| 318 | + ]; | |
| 319 | + | |
| 320 | + red_set_options( $stages ); | |
| 309 | 321 | |
| 310 | 322 | $this->clear_cache(); |
| 311 | 323 | } |
| 312 | 324 | |