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