module-post-type-features.php
3 months ago
module-post-type-fields.php
3 years ago
module-post-type-upgrades.php
3 years ago
module-post-type.php
3 months ago
module-post-type-upgrades.php
161 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_module_post_type_upgrades')): |
| 8 | |
| 9 | class acfe_module_post_type_upgrades{ |
| 10 | |
| 11 | /** |
| 12 | * construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | add_action('acfe/do_upgrade', array($this, 'upgrade_0_8_9'), 30); |
| 17 | add_action('acfe/do_upgrade', array($this, 'upgrade_0_8_8'), 20); |
| 18 | add_action('acfe/do_upgrade', array($this, 'upgrade_0_8_5'), 10); |
| 19 | |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * upgrade_0_8_9 |
| 24 | * |
| 25 | * acfe/do_upgrade:30 |
| 26 | * |
| 27 | * @param $db_version |
| 28 | */ |
| 29 | function upgrade_0_8_9($db_version){ |
| 30 | |
| 31 | // check already done |
| 32 | if(acf_version_compare($db_version, '>=', '0.8.9')){ |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | // hook on init to load all WP components |
| 37 | // post types, post statuses 'acf-disabled' etc... |
| 38 | add_action('init', function(){ |
| 39 | |
| 40 | // get posts |
| 41 | $posts = get_posts(array( |
| 42 | 'post_type' => 'acfe-dpt', |
| 43 | 'posts_per_page' => -1, |
| 44 | 'fields' => 'ids', |
| 45 | 'post_status' => 'any', |
| 46 | )); |
| 47 | |
| 48 | $todo = array(); |
| 49 | |
| 50 | foreach($posts as $post_id){ |
| 51 | |
| 52 | if(acfe_is_module_v2_item($post_id)){ |
| 53 | $todo[] = $post_id; |
| 54 | } |
| 55 | |
| 56 | } |
| 57 | |
| 58 | if(!$todo){ |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | // get module |
| 63 | $module = acfe_get_module('post_type'); |
| 64 | |
| 65 | // loop |
| 66 | foreach($todo as $post_id){ |
| 67 | |
| 68 | $name = get_post_field('post_name', $post_id); |
| 69 | $settings = acfe_get_settings("modules.post_types.{$name}", array()); |
| 70 | |
| 71 | // db settings found |
| 72 | if($settings){ |
| 73 | |
| 74 | // generate item |
| 75 | $item = wp_parse_args($settings, array( |
| 76 | 'ID' => $post_id, |
| 77 | 'name' => $name, |
| 78 | )); |
| 79 | |
| 80 | // import item (update db) |
| 81 | $module->import_item($item); |
| 82 | |
| 83 | } |
| 84 | |
| 85 | } |
| 86 | |
| 87 | // log |
| 88 | acf_log('[ACF Extended] 0.8.9 Upgrade: Post Types'); |
| 89 | |
| 90 | }); |
| 91 | |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * upgrade_0_8_8 |
| 96 | * |
| 97 | * acfe/do_upgrade:20 |
| 98 | * |
| 99 | * @param $db_version |
| 100 | */ |
| 101 | function upgrade_0_8_8($db_version){ |
| 102 | |
| 103 | // check already done |
| 104 | if(acf_version_compare($db_version, '>=', '0.8.8')){ |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | $old = acfe_get_settings('modules.dynamic_post_type.data', array()); |
| 109 | $new = acfe_get_settings('modules.post_types', array()); |
| 110 | |
| 111 | acfe_delete_settings('modules.dynamic_post_type'); |
| 112 | |
| 113 | // Check |
| 114 | if(empty($old)){ |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | // Log |
| 119 | acf_log('[ACF Extended] 0.8.8 Upgrade: Post Types'); |
| 120 | |
| 121 | // Update |
| 122 | acfe_update_settings('modules.post_types', array_merge($old, $new)); |
| 123 | |
| 124 | } |
| 125 | |
| 126 | |
| 127 | /** |
| 128 | * upgrade_0_8_5 |
| 129 | * |
| 130 | * acfe/do_upgrade:10 |
| 131 | * |
| 132 | * @param $db_version |
| 133 | */ |
| 134 | function upgrade_0_8_5($db_version){ |
| 135 | |
| 136 | // check already done |
| 137 | if(acf_version_compare($db_version, '>=', '0.8.5')){ |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | $old = get_option('acfe_dynamic_post_types', array()); |
| 142 | $new = acfe_get_settings('modules.post_types', array()); |
| 143 | |
| 144 | delete_option('acfe_dynamic_post_types'); |
| 145 | |
| 146 | if(empty($old)){ |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | acf_log('[ACF Extended] 0.8.5 Upgrade: Post Types'); |
| 151 | |
| 152 | // Update |
| 153 | acfe_update_settings('modules.post_types', array_merge($old, $new)); |
| 154 | |
| 155 | } |
| 156 | |
| 157 | } |
| 158 | |
| 159 | acf_new_instance('acfe_module_post_type_upgrades'); |
| 160 | |
| 161 | endif; |