PluginProbe
Pods – Custom Content Types and Fields / 2.9.19.5
Pods – Custom Content Types and Fields v2.9.19.5
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 All 42 releases
pods / sql / upgrade / PodsUpgrade_2_1_0.php
PodsUpgrade_2_1_0.php
128 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @package Pods\Upgrade
5 */
6 class PodsUpgrade_2_1_0 extends PodsUpgrade {
7
8 /**
9 * @var string
10 */
11 protected $version = '2.1.0';
12
13 /**
14 *
15 */
16 public function __construct() {
17 }
18
19 /**
20 * @return array|bool|int|mixed|null|void
21 */
22 public function prepare_relationships() {
23 $relationship_fields = $this->api->load_fields( array( 'type' => 'pick' ) );
24
25 $count = 0;
26
27 if ( ! empty( $relationship_fields ) ) {
28 $count = count( $relationship_fields );
29 }
30
31 return $count;
32 }
33
34 /**
35 * @return string
36 */
37 public function migrate_relationships() {
38 if ( true === $this->check_progress( __FUNCTION__ ) ) {
39 return '1';
40 }
41
42 $migration_limit = (int) apply_filters( 'pods_upgrade_item_limit', 1500 );
43 $migration_limit = max( $migration_limit, 100 );
44
45 $last_id = (int) $this->check_progress( __FUNCTION__ );
46
47 $relationship_fields = $this->api->load_fields( array( 'type' => array( 'pick', 'file' ) ) );
48
49 foreach ( $relationship_fields as $field ) {
50 $pod = $this->api->load_pod( array( 'pod' => $field['pod'] ) );
51
52 // Only target pods that are meta-enabled
53 if ( ! in_array( $pod['type'], array( 'post_type', 'media', 'user', 'comment' ), true ) ) {
54 continue;
55 }
56
57 // Only target multi-select relationships
58 $single_multi = pods_v( $field['type'] . '_format_type', $field['options'], 'single' );
59
60 if ( 'multi' === $single_multi ) {
61 $limit = (int) pods_v( $field['type'] . '_limit', $field['options'], 0 );
62 } else {
63 $limit = 1;
64 }
65
66 if ( $limit <= 1 ) {
67 continue;
68 }
69
70 // Get and loop through relationship meta
71 $sql = '
72
73 ';
74 // if serialized (or array), save as individual meta items and save new order meta key
75 }//end foreach
76
77 $last_id = true;
78
79 $rel = array();
80
81 $this->update_progress( __FUNCTION__, $last_id );
82
83 if ( count( $rel ) === $migration_limit ) {
84 return '-2';
85 } else {
86 return '1';
87 }
88 }
89
90 /**
91 * @return string
92 */
93 public function migrate_cleanup() {
94 $this->upgraded();
95
96 $this->api->cache_flush_pods();
97
98 return '1';
99 }
100
101 /**
102 *
103 */
104 public function restart() {
105 $upgraded = get_option( 'pods_framework_upgraded' );
106
107 if ( empty( $upgraded ) || ! is_array( $upgraded ) ) {
108 $upgraded = array();
109 }
110
111 delete_option( 'pods_framework_upgrade_' . str_replace( '.', '_', $this->version ) );
112
113 if ( in_array( $this->version, $upgraded, true ) ) {
114 // @codingStandardsIgnoreLine
115 unset( $upgraded[ array_search( $this->version, $upgraded ) ] );
116 }
117
118 update_option( 'pods_framework_upgraded', $upgraded );
119 }
120
121 /**
122 *
123 */
124 public function cleanup() {
125 $this->restart();
126 }
127 }
128