| 1 |
<?php namespace TierPricingTable\BackgroundProcessing\Updater; |
| 2 |
|
| 3 |
use TierPricingTable\TierPricingTablePlugin; |
| 4 |
|
| 5 |
class Updater { |
| 6 |
|
| 7 |
const DB_OPTION = 'tiered_price_table_version'; |
| 8 |
|
| 9 |
public function checkForUpdates() { |
| 10 |
return $this->compare( TierPricingTablePlugin::DB_VERSION ); |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Compare plugin versions |
| 15 |
* |
| 16 |
* @param $version |
| 17 |
* |
| 18 |
* @return mixed |
| 19 |
*/ |
| 20 |
private function compare( $version ) { |
| 21 |
$dbVersion = get_option( self::DB_OPTION, '1.0.0' ); |
| 22 |
|
| 23 |
return version_compare( $dbVersion, $version, '<' ); |
| 24 |
} |
| 25 |
|
| 26 |
public function update() { |
| 27 |
foreach ( $this->getUpdates() as $version => $callback ) { |
| 28 |
if ( $this->compare( $version ) ) { |
| 29 |
call_user_func( $callback ); |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
public function getUpdates() { |
| 35 |
return array(); |
| 36 |
} |
| 37 |
} |
| 38 |
|