|
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
|
|
|
|
|
24
|
|
|
$relationship_fields = $this->api->load_fields( array( 'type' => 'pick' ) ); |
|
25
|
|
|
|
|
26
|
|
|
$count = 0; |
|
27
|
|
|
|
|
28
|
|
|
if ( ! empty( $relationship_fields ) ) { |
|
29
|
|
|
$count = count( $relationship_fields ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
return $count; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return string |
|
37
|
|
|
*/ |
|
38
|
|
|
public function migrate_relationships() { |
|
39
|
|
|
|
|
40
|
|
|
if ( true === $this->check_progress( __FUNCTION__ ) ) { |
|
41
|
|
|
return '1'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$migration_limit = (int) apply_filters( 'pods_upgrade_item_limit', 1500 ); |
|
45
|
|
|
$migration_limit = max( $migration_limit, 100 ); |
|
46
|
|
|
|
|
47
|
|
|
$last_id = (int) $this->check_progress( __FUNCTION__ ); |
|
48
|
|
|
|
|
49
|
|
|
$relationship_fields = $this->api->load_fields( array( 'type' => array( 'pick', 'file' ) ) ); |
|
50
|
|
|
|
|
51
|
|
|
foreach ( $relationship_fields as $field ) { |
|
52
|
|
|
$pod = $this->api->load_pod( array( 'pod' => $field['pod'] ) ); |
|
53
|
|
|
|
|
54
|
|
|
// Only target pods that are meta-enabled |
|
55
|
|
|
if ( ! in_array( $pod['type'], array( 'post_type', 'media', 'user', 'comment' ), true ) ) { |
|
56
|
|
|
continue; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// Only target multi-select relationships |
|
60
|
|
|
$single_multi = pods_v( $field['type'] . '_format_type', $field['options'], 'single' ); |
|
61
|
|
|
|
|
62
|
|
|
if ( 'multi' === $single_multi ) { |
|
63
|
|
|
$limit = (int) pods_v( $field['type'] . '_limit', $field['options'], 0 ); |
|
64
|
|
|
} else { |
|
65
|
|
|
$limit = 1; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if ( $limit <= 1 ) { |
|
69
|
|
|
continue; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
// Get and loop through relationship meta |
|
73
|
|
|
$sql = ' |
|
74
|
|
|
|
|
75
|
|
|
'; |
|
76
|
|
|
|
|
77
|
|
|
// if serialized (or array), save as individual meta items and save new order meta key |
|
78
|
|
|
}//end foreach |
|
79
|
|
|
|
|
80
|
|
|
$last_id = true; |
|
81
|
|
|
|
|
82
|
|
|
$rel = array(); |
|
83
|
|
|
|
|
84
|
|
|
$this->update_progress( __FUNCTION__, $last_id ); |
|
85
|
|
|
|
|
86
|
|
|
if ( count( $rel ) === $migration_limit ) { |
|
87
|
|
|
return '-2'; |
|
88
|
|
|
} else { |
|
89
|
|
|
return '1'; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
public function migrate_cleanup() { |
|
97
|
|
|
|
|
98
|
|
|
$this->upgraded(); |
|
99
|
|
|
|
|
100
|
|
|
$this->api->cache_flush_pods(); |
|
101
|
|
|
|
|
102
|
|
|
return '1'; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* |
|
107
|
|
|
*/ |
|
108
|
|
|
public function restart() { |
|
109
|
|
|
|
|
110
|
|
|
$upgraded = get_option( 'pods_framework_upgraded' ); |
|
111
|
|
|
|
|
112
|
|
|
if ( empty( $upgraded ) || ! is_array( $upgraded ) ) { |
|
113
|
|
|
$upgraded = array(); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
delete_option( 'pods_framework_upgrade_' . str_replace( '.', '_', $this->version ) ); |
|
117
|
|
|
|
|
118
|
|
|
if ( in_array( $this->version, $upgraded, true ) ) { |
|
119
|
|
|
// @codingStandardsIgnoreLine |
|
120
|
|
|
unset( $upgraded[ array_search( $this->version, $upgraded ) ] ); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
update_option( 'pods_framework_upgraded', $upgraded ); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* |
|
128
|
|
|
*/ |
|
129
|
|
|
public function cleanup() { |
|
130
|
|
|
|
|
131
|
|
|
$this->restart(); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.