| 1 |
<?php |
| 2 |
|
| 3 |
class WPUPG_Migration { |
| 4 |
|
| 5 |
public function __construct() |
| 6 |
{ |
| 7 |
add_action( 'admin_init', array( $this, 'migrate_if_needed' ) ); |
| 8 |
} |
| 9 |
|
| 10 |
public function migrate_if_needed() |
| 11 |
{ |
| 12 |
// Get current migrated to version |
| 13 |
$migrate_version = get_option( 'wpupg_migrate_version', false ); |
| 14 |
|
| 15 |
if( !$migrate_version ) { |
| 16 |
$notices = false; |
| 17 |
$migrate_version = '0.0.1'; |
| 18 |
} else { |
| 19 |
$notices = true; |
| 20 |
} |
| 21 |
|
| 22 |
$migrate_special = ''; |
| 23 |
if( isset( $_GET['wpupg_migrate'] ) ) { |
| 24 |
$migrate_special = $_GET['wpupg_migrate']; |
| 25 |
} |
| 26 |
|
| 27 |
if( $migrate_version < '1.2' ) require_once( WPUltimatePostGrid::get()->coreDir . '/helpers/migration/1_2_active_colors.php'); |
| 28 |
|
| 29 |
// Each version update once |
| 30 |
if( $migrate_version < WPUPG_VERSION ) { |
| 31 |
WPUltimatePostGrid::addon( 'custom-templates' )->default_templates( true ); // Reset default templates |
| 32 |
|
| 33 |
// Update all grid caches |
| 34 |
$args = array( |
| 35 |
'post_type' => WPUPG_POST_TYPE, |
| 36 |
'post_status' => 'any', |
| 37 |
'posts_per_page' => -1, |
| 38 |
'nopaging' => true, |
| 39 |
'fields' => 'ids', |
| 40 |
); |
| 41 |
|
| 42 |
$query = new WP_Query( $args ); |
| 43 |
$posts = $query->have_posts() ? $query->posts : array(); |
| 44 |
$grid_ids = array_map( 'intval', $posts ); |
| 45 |
|
| 46 |
if( count( $grid_ids ) > 0 ) { |
| 47 |
update_option( 'wpupg_regenerate_grids_check', $grid_ids ); |
| 48 |
} |
| 49 |
|
| 50 |
update_option( 'wpupg_migrate_version', WPUPG_VERSION ); |
| 51 |
} |
| 52 |
} |
| 53 |
} |