PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5.3
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5.3
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
jetformbuilder / modules / cli / commands / seed-records.php

seed-records.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.5.3, at modules/cli/commands/seed-records.php

102 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace JFB_Modules\Cli\Commands;
5
6 // If this file is called directly, abort.
7 if ( ! defined( 'WPINC' ) ) {
8 die;
9 }
10
11 use Jet_Form_Builder\Blocks\Block_Helper;
12 use JFB_Modules\Form_Record\Models\Record_Action_Result_Model;
13 use JFB_Modules\Form_Record\Models\Record_Field_Model;
14 use JFB_Modules\Form_Record\Models\Record_Model;
15 use JFB_Modules\Security\Csrf\Csrf_Tools;
16 use JFB_Modules\Cli\Cli_Tools;
17
18 class Seed_Records implements Base_Command_It {
19
20 public function rep_item_id() {
21 return 'seed-records';
22 }
23
24 public function condition(): bool {
25 return true;
26 }
27
28 public function do_command( $args, $assoc_args ) {
29 $form = Cli_Tools::resolve_form( $assoc_args );
30 $limit = absint( $assoc_args['limit'] ?? 1000000 );
31
32 if ( 0 >= $limit ) {
33 $limit = 1;
34 }
35
36 $field_names = array_keys(
37 Block_Helper::get_form_field_names(
38 Block_Helper::get_blocks_by_post( $form )
39 )
40 );
41
42 /** @var \WP_User $user */
43 list( $user ) = get_users(
44 array(
45 'number' => 1,
46 )
47 );
48
49 /** @var \WP_Post $post */
50 list( $post ) = get_posts(
51 array(
52 'numberposts' => 1,
53 )
54 );
55
56 $current = 0;
57
58 foreach ( range( 0, $limit ) as $current ) {
59 $record_id = ( new Record_Model() )->insert_soft(
60 array(
61 'user_id' => $user->ID,
62 'form_id' => $form->ID,
63 'from_content_id' => $post->ID,
64 'from_content_type' => 'cli',
65 'status' => 'failed',
66 )
67 );
68
69 foreach ( range( 0, 2 ) as $next ) {
70 ( new Record_Action_Result_Model() )->insert_soft(
71 array(
72 'record_id' => $record_id,
73 'action_slug' => 'insert_post',
74 'action_id' => 9999,
75 'status' => 'failed',
76 'on_event' => 'GENERATED.CLI',
77 )
78 );
79 }
80
81 foreach ( $field_names as $field_name ) {
82 ( new Record_Field_Model() )->insert_soft(
83 array(
84 'record_id' => $record_id,
85 'field_name' => $field_name,
86 'field_value' => Csrf_Tools::generate(),
87 'field_type' => 'text-field',
88 'field_attrs' => '{}',
89 )
90 );
91 }
92
93 if ( 0 === $current % 5000 ) {
94 \WP_CLI::line( 'Reached: ' . $current );
95 }
96 }
97
98 \WP_CLI::success( "Executed successfully ($current)" );
99 }
100
101 }
102