| 1 |
<?php namespace TierPricingTable\BackgroundProcessing\Updater; |
| 2 |
|
| 3 |
use TierPricingTable\TierPricingTablePlugin; |
| 4 |
use TierPricingTable\BackgroundProcessing\Updater\Updates\VersionTwoDotZero; |
| 5 |
|
| 6 |
class Updater { |
| 7 |
|
| 8 |
const DB_OPTION = 'tiered_price_table_version'; |
| 9 |
|
| 10 |
public function checkForUpdates() { |
| 11 |
return $this->compare( TierPricingTablePlugin::VERSION ); |
| 12 |
} |
| 13 |
|
| 14 |
private function compare( $version ) { |
| 15 |
$dbVersion = get_option( self::DB_OPTION, '1.1' ); |
| 16 |
|
| 17 |
return version_compare( $dbVersion, $version, '<' ); |
| 18 |
} |
| 19 |
|
| 20 |
public function update() { |
| 21 |
foreach ( $this->getUpdates() as $version => $callback ) { |
| 22 |
if ( $this->compare( $version ) ) { |
| 23 |
call_user_func( $callback ); |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
public function getUpdates() { |
| 29 |
return [ |
| 30 |
'2.0' => [ $this, 'update2_0' ], |
| 31 |
]; |
| 32 |
} |
| 33 |
|
| 34 |
public function update2_0() { |
| 35 |
( new VersionTwoDotZero() )->run(); |
| 36 |
} |
| 37 |
} |