PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.8.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.8.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Database / UpdateMigrationServiceProvider.php

UpdateMigrationServiceProvider.php in SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments 2.8.1, at app/src/Database/UpdateMigrationServiceProvider.php

69 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Database;
4
5 use SureCartCore\ServiceProviders\ServiceProviderInterface;
6
7 /**
8 * This service provider runs on every single update.
9 */
10 class UpdateMigrationServiceProvider implements ServiceProviderInterface {
11 /**
12 * {@inheritDoc}
13 *
14 * @param \Pimple\Container $container Service Container.
15 */
16 public function register( $container ) {
17 // nothing to register.
18 }
19
20 /**
21 * {@inheritDoc}
22 *
23 * @param \Pimple\Container $container Service Container.
24 */
25 public function bootstrap( $container ) {
26 // only run the migration if the version changes.
27 add_action( 'admin_init', [ $this, 'run' ] );
28 // update the migration version on admin_init lower priority, after all migrations have run.
29 add_action( 'admin_init', [ $this, 'updateMigrationVersion' ], 9999999 );
30 }
31
32 /**
33 * Run the migration.
34 */
35 public function run() {
36 if ( ! $this->versionChanged() ) {
37 return;
38 }
39
40 // flush roles on every update.
41 \SureCart::plugin()->roles()->create();
42 // make sure to check for and create cart post on every update.
43 \SureCart::page_seeder()->createCartPost();
44 // make sure to check for and create cart post on every update.
45 \SureCart::page_seeder()->createShopPage();
46 }
47
48 /**
49 * Update the migration version.
50 *
51 * @return void
52 */
53 public function updateMigrationVersion() {
54 if ( ! $this->versionChanged() ) {
55 return;
56 }
57 update_option( 'surecart_migration_version', \SureCart::plugin()->version() );
58 }
59
60 /**
61 * Version has changed?
62 *
63 * @return boolean
64 */
65 public function versionChanged() {
66 return version_compare( \SureCart::plugin()->version(), get_option( 'surecart_migration_version', '0.0.0' ), '!=' );
67 }
68 }
69