← All changes
|
src/BackgroundProcessing/Updater/Updates/VersionTwoDotZero.php
+23
-9
2.1.1
→
2.0
View file →
| @@ -22,17 +22,29 @@ | ||
| 22 | 22 | /** |
| 23 | 23 | * Main method to run updating. Version 2.0 |
| 24 | 24 | */ |
| 25 | 25 | public function run() { |
| 26 | - add_action( 'init', [ $this, 'update' ] ); | |
| 26 | + add_action( 'init', function () { | |
| 27 | + $this->begin(); | |
| 28 | + $this->showUpdatingMessage(); | |
| 29 | + } ); | |
| 27 | 30 | } |
| 28 | 31 | |
| 29 | 32 | /** |
| 30 | - * Update | |
| 33 | + * @param mixed $item | |
| 34 | + * | |
| 35 | + * @return bool|mixed | |
| 31 | 36 | */ |
| 32 | - public function update() { | |
| 33 | - $postsToUpdate = $this->getProductsToUpdate(); | |
| 37 | + protected function task( $item ) { | |
| 38 | + $postsToUpdate = $this->getProductsToUpdate( 10 ); | |
| 34 | 39 | |
| 40 | + if ( empty( $postsToUpdate ) ) { | |
| 41 | + $this->complete(); | |
| 42 | + | |
| 43 | + return false; | |
| 44 | + } | |
| 45 | + | |
| 46 | + | |
| 35 | 47 | // Single post |
| 36 | 48 | if ( $postsToUpdate instanceof \WP_Post ) { |
| 37 | 49 | $this->updatePost( $postsToUpdate->ID ); |
| 38 | 50 | } |
| @@ -40,9 +52,9 @@ | ||
| 40 | 52 | foreach ( $postsToUpdate as $postId ) { |
| 41 | 53 | $this->updatePost( $postId ); |
| 42 | 54 | } |
| 43 | 55 | |
| 44 | - $this->complete(); | |
| 56 | + return $item; | |
| 45 | 57 | } |
| 46 | 58 | |
| 47 | 59 | /** |
| 48 | 60 | * @param int $postId |
| @@ -64,20 +76,22 @@ | ||
| 64 | 76 | protected function complete() { |
| 65 | 77 | delete_post_meta_by_key( '_price_rules_updated' ); |
| 66 | 78 | delete_post_meta_by_key( '_price_rules' ); |
| 67 | 79 | |
| 68 | - $this->setCurrentDBVersion(); | |
| 80 | + parent::complete(); | |
| 69 | 81 | } |
| 70 | 82 | |
| 71 | 83 | /** |
| 72 | 84 | * Get list of products to update. |
| 73 | 85 | * |
| 86 | + * @param $count | |
| 87 | + * | |
| 74 | 88 | * @return array |
| 75 | 89 | */ |
| 76 | - protected function getProductsToUpdate() { | |
| 90 | + protected function getProductsToUpdate( $count ) { | |
| 77 | 91 | $args = array( |
| 78 | - 'post_type' => [ 'product', 'product_variation' ], | |
| 79 | - 'posts_per_page' => -1, | |
| 92 | + 'post_type' => ['product', 'product_variation'], | |
| 93 | + 'posts_per_page' => $count, | |
| 80 | 94 | |
| 81 | 95 | 'meta_query' => array( |
| 82 | 96 | 'relation' => 'AND', |
| 83 | 97 | array( |