Admin
5 years ago
AdminBarDashboardAccess
5 years ago
Classes
5 years ago
ContentProtection
5 years ago
Functions
5 years ago
NavigationMenuLinks
5 years ago
RegisterActivation
5 years ago
ShortcodeParser
5 years ago
Themes
5 years ago
Widgets
5 years ago
lib
5 years ago
Base.php
5 years ago
DBUpdates.php
5 years ago
RegisterScripts.php
5 years ago
DBUpdates.php
66 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core; |
| 4 | |
| 5 | class DBUpdates |
| 6 | { |
| 7 | public static $instance; |
| 8 | |
| 9 | const DB_VER = 0; |
| 10 | |
| 11 | public function init_options() |
| 12 | { |
| 13 | get_option('ppress_db_ver', 0); |
| 14 | } |
| 15 | |
| 16 | public function maybe_update() |
| 17 | { |
| 18 | $this->init_options(); |
| 19 | |
| 20 | if (get_option('ppress_db_ver') >= self::DB_VER) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | // update plugin |
| 25 | $this->update(); |
| 26 | } |
| 27 | |
| 28 | public function update() |
| 29 | { |
| 30 | // no PHP timeout for running updates |
| 31 | set_time_limit(0); |
| 32 | |
| 33 | // this is the current database schema version number |
| 34 | $current_db_ver = get_option('ppress_db_ver', 0); |
| 35 | |
| 36 | // this is the target version that we need to reach |
| 37 | $target_db_ver = self::DB_VER; |
| 38 | |
| 39 | // run update routines one by one until the current version number |
| 40 | // reaches the target version number |
| 41 | while ($current_db_ver < $target_db_ver) { |
| 42 | // increment the current db_ver by one |
| 43 | $current_db_ver++; |
| 44 | |
| 45 | // each db version will require a separate update function |
| 46 | $update_method = "ppress_update_routine_{$current_db_ver}"; |
| 47 | |
| 48 | if (method_exists($this, $update_method)) { |
| 49 | call_user_func(array($this, $update_method)); |
| 50 | } |
| 51 | |
| 52 | // update the option in the database, so that this process can always |
| 53 | // pick up where it left off |
| 54 | update_option('ppress_db_ver', $current_db_ver); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | public static function get_instance() |
| 59 | { |
| 60 | if ( ! isset(self::$instance)) { |
| 61 | self::$instance = new self(); |
| 62 | } |
| 63 | |
| 64 | return self::$instance; |
| 65 | } |
| 66 | } |