PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.13.1
GiveWP – Donation Plugin and Fundraising Platform v2.13.1
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / TestData / Commands / LogsSeedCommand.php
LogsSeedCommand.php
88 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\TestData\Commands;
4
5 use WP_CLI;
6 use Give\Log\LogFactory;
7 use Give\TestData\Factories\LogFactory as TestDataLogFactory;
8
9 /**
10 * Class LogsSeedCommand
11 * @package Give\TestData\Commands
12 *
13 * A WP-CLI command for seeding logs.
14 */
15 class LogsSeedCommand {
16
17 /**
18 * @var TestDataLogFactory
19 */
20 private $testDataLogFactory;
21
22 public function __construct( TestDataLogFactory $testDataLogFactory ) {
23 $this->testDataLogFactory = $testDataLogFactory;
24 }
25
26 /**
27 * Generates GiveWP test logs
28 *
29 * [--count=<count>]
30 * : Number of logs to generate
31 * default: 10
32 *
33 * [--type=<type>]
34 * : Log type
35 * default: random
36 *
37 * [--category=<category>]
38 * : Log category
39 * default: Core
40 *
41 * [--source=<source>]
42 * : Log source
43 * default: Core
44 *
45 * [--preview=<preview>]
46 * : Preview generated data
47 * default: false
48 *
49 * ## EXAMPLES
50 *
51 * wp give test-demonstration-page --preview=true
52 *
53 * @when after_wp_load
54 */
55 public function __invoke( $args, $assocArgs ) {
56 $count = WP_CLI\Utils\get_flag_value( $assocArgs, 'count', $default = 10 );
57 $type = WP_CLI\Utils\get_flag_value( $assocArgs, 'type', $default = 'random' );
58 $category = WP_CLI\Utils\get_flag_value( $assocArgs, 'category', $default = 'Core' );
59 $source = WP_CLI\Utils\get_flag_value( $assocArgs, 'source', $default = 'Core' );
60 $preview = WP_CLI\Utils\get_flag_value( $assocArgs, 'preview', $default = false );
61
62 $this->testDataLogFactory->setLogType( $type );
63 $this->testDataLogFactory->setLogCategory( $category );
64 $this->testDataLogFactory->setLogSource( $source );
65
66 $logs = $this->testDataLogFactory->make( $count );
67
68 if ( $preview ) {
69 WP_CLI\Utils\format_items(
70 'table',
71 [ $logs ],
72 array_keys( $this->testDataLogFactory->definition() )
73 );
74 } else {
75 $progress = WP_CLI\Utils\make_progress_bar( 'Generating logs', 1 );
76
77 foreach ( $logs as $data ) {
78 $log = LogFactory::makeFromArray( $data );
79 $log->save();
80
81 $progress->tick();
82 }
83
84 $progress->finish();
85 }
86 }
87 }
88