PodsUpgrade_2_1_0

The Pods - Custom Content Types and Fields PodsUpgrade 2 1 0 class.

Defined (1)

The class is defined in the following location(s).

/sql/upgrade/PodsUpgrade_2_1_0.php  
  1. class PodsUpgrade_2_1_0 extends PodsUpgrade { 
  2.  
  3. /** 
  4. * @var string 
  5. */ 
  6. protected $version = '2.1.0'; 
  7.  
  8. /** 
  9. */ 
  10. function __construct () { 
  11.  
  12. /** 
  13. * @return array|bool|int|mixed|null|void 
  14. */ 
  15. public function prepare_relationships () { 
  16. $relationship_fields = $this->api->load_fields( array( 'type' => 'pick' ) ); 
  17.  
  18. $count = 0; 
  19.  
  20. if ( !empty( $relationship_fields ) ) 
  21. $count = count( $relationship_fields ); 
  22.  
  23. return $count; 
  24.  
  25. /** 
  26. * @return string 
  27. */ 
  28. public function migrate_relationships () { 
  29. if ( true === $this->check_progress( __FUNCTION__ ) ) 
  30. return '1'; 
  31.  
  32. $migration_limit = (int) apply_filters( 'pods_upgrade_item_limit', 1500 ); 
  33. $migration_limit = max( $migration_limit, 100 ); 
  34.  
  35. $last_id = (int) $this->check_progress( __FUNCTION__ ); 
  36.  
  37. $relationship_fields = $this->api->load_fields( array( 'type' => array( 'pick', 'file' ) ) ); 
  38.  
  39. foreach ( $relationship_fields as $field ) { 
  40. $pod = $this->api->load_pod( array( 'pod' => $field[ 'pod' ] ) ); 
  41.  
  42. // Only target pods that are meta-enabled 
  43. if ( !in_array( $pod[ 'type' ], array( 'post_type', 'media', 'user', 'comment' ) ) ) 
  44. continue; 
  45.  
  46. // Only target multi-select relationships 
  47. $single_multi = pods_var( $field[ 'type' ] . '_format_type', $field[ 'options' ], 'single' ); 
  48.  
  49. if ( 'multi' == $single_multi ) 
  50. $limit = (int) pods_var( $field[ 'type' ] . '_limit', $field[ 'options' ], 0 ); 
  51. else 
  52. $limit = 1; 
  53.  
  54. if ( $limit <= 1 ) 
  55. continue; 
  56.  
  57. // Get and loop through relationship meta 
  58. $sql = " 
  59.  
  60. "; 
  61.  
  62. // if serialized (or array), save as individual meta items and save new order meta key 
  63.  
  64. $last_id = true; 
  65.  
  66. $rel = array(); 
  67.  
  68. $this->update_progress( __FUNCTION__, $last_id ); 
  69.  
  70. if ( $migration_limit == count( $rel ) ) 
  71. return '-2'; 
  72. else 
  73. return '1'; 
  74.  
  75. /** 
  76. * @return string 
  77. */ 
  78. public function migrate_cleanup () { 
  79. $this->upgraded(); 
  80.  
  81. $this->api->cache_flush_pods(); 
  82.  
  83. return '1'; 
  84.  
  85. /** 
  86. */ 
  87. public function restart () { 
  88. $upgraded = get_option( 'pods_framework_upgraded' ); 
  89.  
  90. if ( empty( $upgraded ) || !is_array( $upgraded ) ) 
  91. $upgraded = array(); 
  92.  
  93. delete_option( 'pods_framework_upgrade_' . str_replace( '.', '_', $this->version ) ); 
  94.  
  95. if ( in_array( $this->version, $upgraded ) ) 
  96. unset( $upgraded[ array_search( $this->version, $upgraded ) ] ); 
  97.  
  98. update_option( 'pods_framework_upgraded', $upgraded ); 
  99.  
  100. /** 
  101. */ 
  102. public function cleanup () { 
  103. $this->restart();