PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.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 All 255 releases
give / src / TestData / Commands / DonorSeedCommand.php

DonorSeedCommand.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/TestData/Commands/DonorSeedCommand.php

86 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 namespace Give\TestData\Commands;
4
5 use Give\TestData\Factories\DonorFactory;
6 use Give\TestData\Repositories\DonorRepository;
7 use WP_CLI;
8
9 /**
10 * Class DonorSeedCommand
11 * @package Give\TestData\Commands
12 *
13 * A WP-CLI command for seeding donors.
14 */
15 class DonorSeedCommand
16 {
17 /**
18 * @var DonorFactory
19 */
20 private $donorFactory;
21 /**
22 * @var DonorRepository
23 */
24 private $donorRepository;
25
26 /**
27 * @param DonorFactory $donorFactory
28 * @param DonorRepository $donorRepository
29 */
30 public function __construct(
31 DonorFactory $donorFactory,
32 DonorRepository $donorRepository
33 ) {
34 $this->donorFactory = $donorFactory;
35 $this->donorRepository = $donorRepository;
36 }
37
38 /**
39 * Generates Donors
40 *
41 * ## OPTIONS
42 * [--count=<count>]
43 * : Number of donors to generate
44 * default: 10
45 *
46 * [--preview=<preview>]
47 * : Preview generated data
48 * default: false
49 *
50 * [--consistent=<consistent>]
51 * : Generate consistent data
52 * default: false
53 *
54 * ## EXAMPLES
55 *
56 * wp give test-donors --count=10 --preview=true
57 *
58 * @when after_wp_load
59 */
60 public function __invoke($args, $assocArgs)
61 {
62 $count = WP_CLI\Utils\get_flag_value($assocArgs, 'count', $default = 10);
63 $preview = WP_CLI\Utils\get_flag_value($assocArgs, 'preview', $default = false);
64 $consistent = WP_CLI\Utils\get_flag_value($assocArgs, 'consistent', $default = false);
65
66 $donors = $this->donorFactory->consistent($consistent)->make($count);
67
68 if ($preview) {
69 WP_CLI\Utils\format_items(
70 'table',
71 $donors,
72 array_keys($this->donorFactory->definition())
73 );
74 } else {
75 $progress = WP_CLI\Utils\make_progress_bar('Generating donors', $count);
76
77 foreach ($donors as $donor) {
78 $this->donorRepository->insertDonor($donor);
79 $progress->tick();
80 }
81
82 $progress->finish();
83 }
84 }
85 }
86