data-migration.php
2 years ago
initiator.php
4 years ago
migration-contract.php
4 years ago
migration.php
2 years ago
initiator.php
85 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ElementsKit_Lite\Libs\Xs_Migration; |
| 4 | |
| 5 | use ElementsKit_Lite\Traits\Singleton; |
| 6 | |
| 7 | class Initiator { |
| 8 | |
| 9 | use Singleton; |
| 10 | |
| 11 | const OK_MIGRATION_LOGGER = 'ekit_migration_log'; |
| 12 | |
| 13 | |
| 14 | public function init() { |
| 15 | |
| 16 | add_filter( 'heartbeat_send', array( $this, 'send_heartbeat' ), 10, 2 ); |
| 17 | //add_filter('heartbeat_received', [$this, 'receive_heartbeat'], 10, 2); |
| 18 | //add_filter( 'heartbeat_settings', [$this, 'heartbeat_settings'] ); |
| 19 | } |
| 20 | |
| 21 | |
| 22 | public function send_heartbeat( $response, $screen_id ) { |
| 23 | |
| 24 | $txtDomain = 'elementskit-lite'; |
| 25 | $optionKey = 'data_migration_' . $txtDomain . '_log'; |
| 26 | |
| 27 | $option = get_option( $optionKey, array() ); |
| 28 | |
| 29 | if ( empty( $option['_last_version_scanned'] ) ) { |
| 30 | |
| 31 | /** |
| 32 | * Migration never ran in this domain |
| 33 | * |
| 34 | */ |
| 35 | $migration = new Migration(); |
| 36 | |
| 37 | $ret = $migration->input( $txtDomain, '1.3.1', \ElementsKit_Lite::version() ); |
| 38 | |
| 39 | $response['migration_log'] = $ret; |
| 40 | |
| 41 | return $response; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * We have last version of migration run |
| 46 | * checking if it is same as current version |
| 47 | */ |
| 48 | if ( $option['_last_version_scanned'] == \ElementsKit_Lite::version() ) { |
| 49 | |
| 50 | $data[] = 'Migration has already run for this version - ' . \ElementsKit_Lite::version(); |
| 51 | $data[] = $screen_id; |
| 52 | |
| 53 | $response['migration_push'] = $data; |
| 54 | |
| 55 | return $response; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * We have started running migration for this version |
| 60 | * Or this is an update version that need to check migration run again |
| 61 | * |
| 62 | */ |
| 63 | $migration = new Migration(); |
| 64 | |
| 65 | $ret = $migration->input( $txtDomain, '1.3.1', \ElementsKit_Lite::version() ); |
| 66 | |
| 67 | $response['migration_log'] = $ret; |
| 68 | |
| 69 | return $response; |
| 70 | } |
| 71 | |
| 72 | public function receive_heartbeat() { |
| 73 | } |
| 74 | |
| 75 | |
| 76 | public function heartbeat_settings() { |
| 77 | |
| 78 | $settings['interval'] = 15; //Anything between 15-120 |
| 79 | //$settings['autostart'] = false; |
| 80 | |
| 81 | return $settings; |
| 82 | } |
| 83 | |
| 84 | } |
| 85 |