PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.2.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.2.3
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 / GeneralMigration.php
GeneralMigration.php
82 lines 1.5 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 abstract class GeneralMigration {
6 /**
7 * The version number when we will run the migration.
8 *
9 * @var string
10 */
11 protected $version = '0.0.0';
12
13 /**
14 * The key for the migration.
15 *
16 * @var string
17 */
18 protected $migration_key = 'surecart_migration_version';
19
20 /**
21 * Run on init.
22 *
23 * @return void
24 */
25 public function bootstrap() {
26 add_action( 'admin_init', [ $this, 'maybeRun' ] );
27 }
28
29 /**
30 * Maybe let's run the migration.
31 *
32 * @return void
33 */
34 public function maybeRun() {
35 if ( ! $this->shouldMigrate() ) {
36 return;
37 }
38
39 // run the migration.
40 $this->run();
41
42 // update the migration complete on admin_init complete, after all migrations have run.
43 add_action( 'admin_init', [ $this, 'complete' ], 999999 );
44 }
45
46 /**
47 * Should we run this migration?
48 *
49 * @return boolean
50 */
51 public function shouldMigrate(): bool {
52 // check if we already have done this migration.
53 return version_compare( $this->version, $this->getLastMigrationVersion(), '>=' );
54 }
55
56 /**
57 * Run the migration
58 *
59 * @return void
60 */
61 protected function run() {
62 }
63
64 /**
65 * Store the current plugin version when complete.
66 *
67 * @return void
68 */
69 public function complete() {
70 update_option( $this->migration_key, \SureCart::plugin()->version() );
71 }
72
73 /**
74 * Get the last version there was a migration.
75 *
76 * @return string
77 */
78 public function getLastMigrationVersion() {
79 return get_option( $this->migration_key, '0.0.0' );
80 }
81 }
82