DonationSeedCommand.php
5 years ago
DonationStatusCommand.php
5 years ago
DonorSeedCommand.php
5 years ago
FormSeedCommand.php
5 years ago
LogsSeedCommand.php
5 years ago
PageSeedCommand.php
5 years ago
LogsSeedCommand.php
88 lines
| 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 |