| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sellkit\Core\Update; |
| 4 |
|
| 5 |
use Sellkit\Database; |
| 6 |
|
| 7 |
defined( 'ABSPATH' ) || die(); |
| 8 |
|
| 9 |
/** |
| 10 |
* Class Data base Updater. |
| 11 |
* |
| 12 |
* @package Sellkit\Contact_Segmentation |
| 13 |
* @SuppressWarnings(ExcessiveClassComplexity) |
| 14 |
* @since 1.1.0 |
| 15 |
*/ |
| 16 |
class Db_Updater extends \WP_Background_Process { |
| 17 |
|
| 18 |
/** |
| 19 |
* SellKit db version. |
| 20 |
* |
| 21 |
* @since 1.1.0 |
| 22 |
* @var $db_version |
| 23 |
*/ |
| 24 |
public $db_version; |
| 25 |
|
| 26 |
/** |
| 27 |
* Queue Action. |
| 28 |
* |
| 29 |
* @since 1.1.0 |
| 30 |
* @var string |
| 31 |
*/ |
| 32 |
protected $action = 'sellkit-database-updater'; |
| 33 |
|
| 34 |
/** |
| 35 |
* Override this method to perform any actions required on each |
| 36 |
* queue item. Return the modified item for further processing |
| 37 |
* in the next pass through. Or, return false to remove the |
| 38 |
* item from the queue. |
| 39 |
* |
| 40 |
* @since 1.1.0 |
| 41 |
* @param mixed $data Queue item to iterate over. |
| 42 |
*/ |
| 43 |
protected function task( $data ) { |
| 44 |
if ( empty( $data['callback_function'] ) || empty( $data['db_version'] ) ) { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
$this->db_version = $data['db_version']; |
| 49 |
$updater_functions = new Updater_Functions(); |
| 50 |
|
| 51 |
call_user_func( [ $updater_functions, $data['callback_function'] ] ); |
| 52 |
|
| 53 |
return false; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Complete |
| 58 |
* |
| 59 |
* Override if applicable, but ensure that the below actions are |
| 60 |
* performed, or, call parent::complete(). |
| 61 |
* |
| 62 |
* @since 1.1.0 |
| 63 |
*/ |
| 64 |
protected function complete() { |
| 65 |
parent::complete(); |
| 66 |
|
| 67 |
sellkit_update_option( 'current_db_version', $this->db_version ); |
| 68 |
} |
| 69 |
} |
| 70 |
|