← All changes
|
src/BackgroundProcessing/Updater/Updates/VersionAbstract.php
+60
-1
2.3.2
→
2.0
View file →
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | <?php namespace TierPricingTable\BackgroundProcessing\Updater\Updates; |
| 2 | 2 | |
| 3 | +use TierPricingTable\BackgroundProcessing\BackgroundTask; | |
| 3 | 4 | use TierPricingTable\BackgroundProcessing\Updater\Updater; |
| 4 | 5 | |
| 5 | -abstract class VersionAbstract { | |
| 6 | +abstract class VersionAbstract extends BackgroundTask { | |
| 6 | 7 | |
| 7 | 8 | protected $version; |
| 8 | 9 | |
| 9 | 10 | public function getVersion() { |
| @@ -9,8 +10,66 @@ | ||
| 9 | 10 | public function getVersion() { |
| 10 | 11 | return $this->version; |
| 11 | 12 | } |
| 12 | 13 | |
| 14 | + protected function getIsCompletedUpdatingKey() { | |
| 15 | + return 'tiered_price_table_completed_updating_' . $this->getVersion(); | |
| 16 | + } | |
| 17 | + | |
| 18 | + protected function getIsUpdatingKey() { | |
| 19 | + return 'tiered_price_table_updating_' . $this->getVersion(); | |
| 20 | + } | |
| 21 | + | |
| 22 | + protected function isUpdating() { | |
| 23 | + return get_option( $this->getIsUpdatingKey() ) == 'yes'; | |
| 24 | + } | |
| 25 | + | |
| 26 | + protected function isCompleted() { | |
| 27 | + return get_option( $this->getIsCompletedUpdatingKey() ) == 'yes'; | |
| 28 | + } | |
| 29 | + | |
| 30 | + protected function begin() { | |
| 31 | + if ( ! $this->isUpdating() && ! $this->isCompleted() ) { | |
| 32 | + $this->push_to_queue( 'update_to_' . $this->getVersion() ); | |
| 33 | + | |
| 34 | + update_option( $this->getIsUpdatingKey(), 'yes' ); | |
| 35 | + | |
| 36 | + $this->save()->dispatch(); | |
| 37 | + } | |
| 38 | + } | |
| 39 | + | |
| 40 | + protected function complete() { | |
| 41 | + update_option( $this->getIsUpdatingKey(), 'no' ); | |
| 42 | + update_option( $this->getIsCompletedUpdatingKey(), 'yes' ); | |
| 43 | + | |
| 44 | + $this->setCurrentDBVersion(); | |
| 45 | + $this->showCompleteUpdatingMessage(); | |
| 46 | + | |
| 47 | + parent::complete(); | |
| 48 | + } | |
| 49 | + | |
| 13 | 50 | protected function setCurrentDBVersion() { |
| 14 | 51 | update_option( Updater::DB_OPTION, $this->getVersion() ); |
| 52 | + } | |
| 53 | + | |
| 54 | + protected function showUpdatingMessage() { | |
| 55 | + add_action( 'admin_notices', function () { | |
| 56 | + ?> | |
| 57 | + <div class="notice notice-info"> | |
| 58 | + <p><?php _e( 'Tiered Pricing Table is updating database version. It may take a few minutes.', | |
| 59 | + 'tier-pricing-table' ) ?></p> | |
| 60 | + </div> | |
| 61 | + <?php | |
| 62 | + } ); | |
| 63 | + } | |
| 64 | + | |
| 65 | + protected function showCompleteUpdatingMessage() { | |
| 66 | + add_action( 'admin_notices', function () { | |
| 67 | + ?> | |
| 68 | + <div class="notice notice-success"> | |
| 69 | + <p><?php _e( 'Tiered Pricing Table has been completed updating database version.', | |
| 70 | + 'tier-pricing-table' ) ?></p> | |
| 71 | + </div> | |
| 72 | + <?php | |
| 73 | + } ); | |
| 15 | 74 | } |
| 16 | 75 | } |