PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.5
Pods – Custom Content Types and Fields v3.3.5
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 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / src / Pods / CLI / Commands / Tools.php
pods / src / Pods / CLI / Commands Last commit date
Base.php 4 months ago Field.php 4 months ago Group.php 4 months ago Playbook.php 4 months ago Pod.php 4 months ago Tools.php 4 months ago
Tools.php
340 lines
1 <?php
2
3 namespace Pods\CLI\Commands;
4
5 // Don't load directly.
6 if ( ! defined( 'ABSPATH' ) ) {
7 die( '-1' );
8 }
9
10 use Exception;
11 use Pods\Tools\Repair;
12 use Pods\Tools\Reset;
13 use WP_CLI;
14 use WP_CLI_Command;
15
16 /**
17 * Pods Tools commands.
18 *
19 * @since 2.9.10
20 */
21 class Tools extends WP_CLI_Command {
22
23 /**
24 * Delete all content for Pod.
25 *
26 * ## OPTIONS
27 *
28 * <pod>
29 * : The pod name.
30 *
31 * [--test]
32 * : Whether to run the tool in test mode and not add/change/remove any data in the database.
33 *
34 * ## EXAMPLES
35 *
36 * wp pods tools delete-all-content your_pod
37 * - Delete all content for the pod "your_pod".
38 *
39 * wp pods tools delete-all-content your_pod --test
40 * - Preview the deleting of all content for the pod "your_pod", without changing the database.
41 *
42 * @subcommand delete-all-content
43 *
44 * @since 2.9.10
45 *
46 * @param array $args The list of positional arguments.
47 * @param array $assoc_args The list of associative arguments.
48 */
49 public function delete_all_content( $args, $assoc_args ) {
50 $api = pods_api();
51
52 $pod_name = $args[0];
53 $test_mode = ! empty( $assoc_args['test'] );
54
55 // Run the tool.
56 if ( empty( $pod_name ) ) {
57 WP_CLI::error( __( 'No Pod specified.', 'pods' ) );
58
59 return;
60 } else {
61 try {
62 $pod = $api->load_pod( [ 'name' => $pod_name ], false );
63
64 if ( empty( $pod ) ) {
65 WP_CLI::error( __( 'Pod not found.', 'pods' ) );
66
67 return;
68 } else {
69 $tool = pods_container( Reset::class );
70
71 $mode = 'full';
72
73 if ( $test_mode ) {
74 $mode = 'preview';
75 }
76
77 $tool->delete_all_content_for_pod( $pod, $mode );
78 }
79 } catch ( Exception $exception ) {
80 WP_CLI::error( $exception->getMessage() );
81
82 return;
83 }
84 }
85
86 WP_CLI::debug( __( 'Command timing', 'pods' ) );
87 WP_CLI::success( __( 'Content deleted', 'pods' ) );
88 }
89
90 /**
91 * Delete all relationship data for Pod.
92 *
93 * ## OPTIONS
94 *
95 * <pod>
96 * : The pod name.
97 *
98 * [--fields]
99 * : The field name(s) (leave empty to delete relationship data for all fields on pod).
100 *
101 * [--test]
102 * : Whether to run the tool in test mode and not add/change/remove any data in the database.
103 *
104 * ## EXAMPLES
105 *
106 * wp pods tools delete-all-relationship-data your_pod
107 * - Delete all relationship data for the pod "your_pod".
108 *
109 * wp pods tools delete-all-relationship-data your_pod --test
110 * - Preview the deleting of all relationship data for the pod "your_pod", without changing the database.
111 *
112 * @subcommand delete-all-relationship-data
113 *
114 * @since 2.9.10
115 *
116 * @param array $args The list of positional arguments.
117 * @param array $assoc_args The list of associative arguments.
118 */
119 public function delete_all_relationship_data_for_pod( $args, $assoc_args ) {
120 $api = pods_api();
121
122 $pod_name = $args[0];
123 $field_names = ! empty( $assoc_args['fields'] ) ? $assoc_args['fields'] : null;
124 $test_mode = ! empty( $assoc_args['test'] );
125
126 // Run the tool.
127 if ( empty( $pod_name ) ) {
128 WP_CLI::error( __( 'No Pod specified.', 'pods' ) );
129
130 return;
131 } else {
132 try {
133 $pod = $api->load_pod( [ 'name' => $pod_name ], false );
134
135 if ( empty( $pod ) ) {
136 WP_CLI::error( __( 'Pod not found.', 'pods' ) );
137
138 return;
139 } else {
140 $tool = pods_container( Reset::class );
141
142 $mode = 'full';
143
144 if ( $test_mode ) {
145 $mode = 'preview';
146 }
147
148 $tool->delete_all_relationship_data_for_pod( $pod, $field_names, $mode );
149 }
150 } catch ( Exception $exception ) {
151 WP_CLI::error( $exception->getMessage() );
152
153 return;
154 }
155 }
156
157 WP_CLI::debug( __( 'Command timing', 'pods' ) );
158 WP_CLI::success( __( 'Relationship data deleted', 'pods' ) );
159 }
160
161 /**
162 * Delete all groups and fields for Pod.
163 *
164 * ## OPTIONS
165 *
166 * <pod>
167 * : The pod name.
168 *
169 * [--test]
170 * : Whether to run the tool in test mode and not add/change/remove any data in the database.
171 *
172 * ## EXAMPLES
173 *
174 * wp pods tools delete-all-groups-and-fields your_pod
175 * - Delete all groups and fields for the pod "your_pod".
176 *
177 * wp pods tools delete-all-groups-and-fields your_pod --test
178 * - Preview the deleting of all groups and fields for the pod "your_pod", without changing the database.
179 *
180 * @subcommand delete-all-groups-and-fields
181 *
182 * @since 2.9.10
183 *
184 * @param array $args The list of positional arguments.
185 * @param array $assoc_args The list of associative arguments.
186 */
187 public function delete_all_groups_and_fields( $args, $assoc_args ) {
188 $api = pods_api();
189
190 $pod_name = $args[0];
191 $test_mode = ! empty( $assoc_args['test'] );
192
193 // Run the tool.
194 if ( empty( $pod_name ) ) {
195 WP_CLI::error( __( 'No Pod specified.', 'pods' ) );
196
197 return;
198 } else {
199 try {
200 $pod = $api->load_pod( [ 'name' => $pod_name ], false );
201
202 if ( empty( $pod ) ) {
203 WP_CLI::error( __( 'Pod not found.', 'pods' ) );
204
205 return;
206 } else {
207 $tool = pods_container( Reset::class );
208
209 $mode = 'full';
210
211 if ( $test_mode ) {
212 $mode = 'preview';
213 }
214
215 $tool->delete_all_content_for_pod( $pod, $mode );
216 }
217 } catch ( Exception $exception ) {
218 WP_CLI::error( $exception->getMessage() );
219
220 return;
221 }
222 }
223
224 WP_CLI::debug( __( 'Command timing', 'pods' ) );
225 WP_CLI::success( __( 'Groups and Fields for Pod deleted', 'pods' ) );
226 }
227
228 /**
229 * Repair all groups and fields for Pod.
230 *
231 * ## OPTIONS
232 *
233 * <pod>
234 * : The pod name.
235 *
236 * [--test]
237 * : Whether to run the tool in test mode and not add/change/remove any data in the database.
238 *
239 * ## EXAMPLES
240 *
241 * wp pods tools repair-groups-and-fields your_pod
242 * - Repair groups and fields for the pod "your_pod".
243 *
244 * wp pods tools repair-groups-and-fields your_pod --test
245 * - Preview the repair of all groups and fields for the pod "your_pod", without changing the database.
246 *
247 * @subcommand repair-groups-and-fields
248 *
249 * @since 2.9.10
250 *
251 * @param array $args The list of positional arguments.
252 * @param array $assoc_args The list of associative arguments.
253 */
254 public function repair_groups_and_fields( $args, $assoc_args ) {
255 $api = pods_api();
256
257 $pod_name = $args[0];
258 $test_mode = ! empty( $assoc_args['test'] );
259
260 // Run the tool.
261 if ( empty( $pod_name ) ) {
262 WP_CLI::error( __( 'No Pod specified.', 'pods' ) );
263
264 return;
265 } else {
266 try {
267 $pod = $api->load_pod( [ 'name' => $pod_name ], false );
268
269 if ( empty( $pod ) ) {
270 WP_CLI::error( __( 'Pod not found.', 'pods' ) );
271
272 return;
273 } else {
274 $tool = pods_container( Repair::class );
275
276 $mode = 'full';
277
278 if ( $test_mode ) {
279 $mode = 'preview';
280 }
281
282 $tool->repair_groups_and_fields_for_pod( $pod, $mode );
283 }
284 } catch ( Exception $exception ) {
285 WP_CLI::error( $exception->getMessage() );
286
287 return;
288 }
289 }
290
291 WP_CLI::debug( __( 'Command timing', 'pods' ) );
292 WP_CLI::success( __( 'Groups and Fields for Pod repaired', 'pods' ) );
293 }
294
295 /**
296 * Flush the Pods cache.
297 *
298 * ## OPTIONS
299 *
300 * [--pod=<pod>]
301 * : The pod name.
302 *
303 * ## EXAMPLES
304 *
305 * wp pods tools flush-cache
306 * - Flush the Pods cache.
307 *
308 * wp pods tools flush-cache --pod="your_pod"
309 * - Flush the Pods cache for the pod "your_pod".
310 *
311 * @subcommand flush-cache
312 *
313 * @since 2.9.10
314 *
315 * @param array $args The list of positional arguments.
316 * @param array $assoc_args The list of associative arguments.
317 */
318 public function flush_cache( $args, $assoc_args ) {
319 $api = pods_api();
320
321 $pod_name = pods_v( 'pod', $assoc_args );
322
323 $pod = null;
324
325 if ( ! empty( $pod_name ) ) {
326 try {
327 $pod = $api->load_pod( [ 'name' => $pod_name ] );
328 } catch ( Exception $exception ) {
329 WP_CLI::error( $exception->getMessage() );
330 }
331 }
332
333 $api->cache_flush_pods( $pod );
334
335 WP_CLI::debug( __( 'Command timing', 'pods' ) );
336 WP_CLI::success( __( 'Pods cache flushed', 'pods' ) );
337 }
338
339 }
340