← All changes
|
app/src/Database/UpdateMigrationServiceProvider.php
+2
-65
4.2.2
→
1.2.5
View file →
| @@ -35,14 +35,13 @@ | ||
| 35 | 35 | public function run() { |
| 36 | 36 | if ( ! $this->versionChanged() ) { |
| 37 | 37 | return; |
| 38 | 38 | } |
| 39 | + | |
| 39 | 40 | // flush roles on every update. |
| 40 | 41 | \SureCart::plugin()->roles()->create(); |
| 41 | 42 | // make sure to check for and create cart post on every update. |
| 42 | - \SureCart::page_seeder()->createShopPage(); | |
| 43 | - // make sure to check for and create cart post on every update. | |
| 44 | - $this->handleCartMigration(); | |
| 43 | + \SureCart::page_seeder()->createCartPost(); | |
| 45 | 44 | } |
| 46 | 45 | |
| 47 | 46 | /** |
| 48 | 47 | * Update the migration version. |
| @@ -62,68 +61,6 @@ | ||
| 62 | 61 | * @return boolean |
| 63 | 62 | */ |
| 64 | 63 | public function versionChanged() { |
| 65 | 64 | return version_compare( \SureCart::plugin()->version(), get_option( 'surecart_migration_version', '0.0.0' ), '!=' ); |
| 66 | - } | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * Handle cart migration | |
| 70 | - * | |
| 71 | - * @return \WP_Post|WP_Error | |
| 72 | - */ | |
| 73 | - public function handleCartMigration() { | |
| 74 | - // get the existing cart post. | |
| 75 | - $existing_cart_post = \SureCart::cartPost()->get(); | |
| 76 | - | |
| 77 | - // we don't have a cart post - it's possibly been deleted or not seeded. | |
| 78 | - if ( empty( $existing_cart_post ) || empty( $existing_cart_post->post_content ) ) { | |
| 79 | - return; | |
| 80 | - } | |
| 81 | - | |
| 82 | - // get the defined template. | |
| 83 | - $template = get_block_template( 'surecart/surecart//cart', 'wp_template_part' ); | |
| 84 | - | |
| 85 | - // it has already been modified. | |
| 86 | - if ( ! empty( $template->wp_id ) ) { | |
| 87 | - return; | |
| 88 | - } | |
| 89 | - | |
| 90 | - $cart = [ | |
| 91 | - 'post_name' => 'cart', | |
| 92 | - 'post_title' => $template->title, | |
| 93 | - 'post_status' => 'publish', | |
| 94 | - 'tax_input' => [ | |
| 95 | - 'wp_template_part_area' => WP_TEMPLATE_PART_AREA_UNCATEGORIZED, | |
| 96 | - 'wp_theme' => $template->theme, | |
| 97 | - ], | |
| 98 | - 'meta_input' => [ | |
| 99 | - 'origin' => 'plugin', | |
| 100 | - ], | |
| 101 | - 'post_type' => 'wp_template_part', | |
| 102 | - 'post_content' => \SureCart\Cart\CartService::removeDeprecatedCartContent( $existing_cart_post->post_content ), | |
| 103 | - 'post_excerpt' => $template->description, | |
| 104 | - ]; | |
| 105 | - | |
| 106 | - // Create the template. | |
| 107 | - $result = wp_insert_post( wp_slash( $cart, false ) ); | |
| 108 | - | |
| 109 | - // insertion failed. | |
| 110 | - if ( is_wp_error( $result ) ) { | |
| 111 | - return $result; | |
| 112 | - } | |
| 113 | - | |
| 114 | - // delete all cart posts. | |
| 115 | - $allposts = get_posts( | |
| 116 | - array( | |
| 117 | - 'post_type' => 'sc_cart', | |
| 118 | - 'numberposts' => -1, | |
| 119 | - 'fields' => 'ids', | |
| 120 | - ) | |
| 121 | - ); | |
| 122 | - foreach ( $allposts as $eachpost ) { | |
| 123 | - wp_delete_post( $eachpost, true ); | |
| 124 | - } | |
| 125 | - | |
| 126 | - // return result. | |
| 127 | - return $result; | |
| 128 | 65 | } |
| 129 | 66 | } |