1 | <?php |
||||
2 | declare(strict_types=1); |
||||
3 | /** |
||||
4 | */ |
||||
5 | |||||
6 | namespace CommerceLeague\ActiveCampaign\Console\Command; |
||||
7 | |||||
8 | use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper; |
||||
9 | use CommerceLeague\ActiveCampaign\MessageQueue\Topics; |
||||
10 | use CommerceLeague\ActiveCampaign\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory; |
||||
0 ignored issues
–
show
|
|||||
11 | use CommerceLeague\ActiveCampaign\Model\ResourceModel\Customer\Collection as CustomerCollection; |
||||
12 | use Magento\Framework\Console\Cli; |
||||
13 | use Magento\Framework\MessageQueue\PublisherInterface; |
||||
14 | use Symfony\Component\Console\Exception\RuntimeException; |
||||
15 | use Symfony\Component\Console\Helper\ProgressBarFactory; |
||||
0 ignored issues
–
show
The type
Symfony\Component\Consol...lper\ProgressBarFactory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
16 | use Symfony\Component\Console\Input\InputInterface; |
||||
17 | use Symfony\Component\Console\Input\InputOption; |
||||
18 | use Symfony\Component\Console\Output\OutputInterface; |
||||
19 | |||||
20 | class ExportCustomerCommand extends AbstractExportCommand |
||||
21 | { |
||||
22 | private const NAME = 'activecampaign:export:customer'; |
||||
23 | private const OPTION_EMAIL = 'email'; |
||||
24 | private const OPTION_OMITTED = 'omitted'; |
||||
25 | private const OPTION_ALL = 'all'; |
||||
26 | |||||
27 | /** |
||||
28 | * @var CustomerCollectionFactory |
||||
29 | */ |
||||
30 | private $customerCollectionFactory; |
||||
31 | |||||
32 | /** |
||||
33 | * @param ConfigHelper $configHelper |
||||
34 | * @param CustomerCollectionFactory $customerCollectionFactory |
||||
35 | * @param ProgressBarFactory $progressBarFactory |
||||
36 | * @param PublisherInterface $publisher |
||||
37 | */ |
||||
38 | public function __construct( |
||||
39 | ConfigHelper $configHelper, |
||||
40 | CustomerCollectionFactory $customerCollectionFactory, |
||||
41 | ProgressBarFactory $progressBarFactory, |
||||
42 | PublisherInterface $publisher |
||||
43 | ) { |
||||
44 | $this->customerCollectionFactory = $customerCollectionFactory; |
||||
45 | parent::__construct($configHelper, $progressBarFactory, $publisher); |
||||
46 | } |
||||
47 | |||||
48 | /** |
||||
49 | * @inheritDoc |
||||
50 | */ |
||||
51 | protected function configure() |
||||
52 | { |
||||
53 | $this->setName(self::NAME) |
||||
54 | ->setDescription('Export customers') |
||||
55 | ->addOption( |
||||
56 | self::OPTION_EMAIL, |
||||
57 | null, |
||||
58 | InputOption::VALUE_REQUIRED, |
||||
59 | 'The customer email' |
||||
60 | ) |
||||
61 | ->addOption( |
||||
62 | self::OPTION_OMITTED, |
||||
63 | null, |
||||
64 | InputOption::VALUE_NONE, |
||||
65 | 'Only export omitted customers' |
||||
66 | ) |
||||
67 | ->addOption( |
||||
68 | self::OPTION_ALL, |
||||
69 | null, |
||||
70 | InputOption::VALUE_NONE, |
||||
71 | 'Export all customers' |
||||
72 | ); |
||||
73 | } |
||||
74 | |||||
75 | /** |
||||
76 | * @inheritDoc |
||||
77 | */ |
||||
78 | protected function interact(InputInterface $input, OutputInterface $output) |
||||
79 | { |
||||
80 | if (!$this->configHelper->isEnabled() || !$this->configHelper->isCustomerExportEnabled()) { |
||||
81 | throw new RuntimeException('Export disabled by system configuration'); |
||||
82 | } |
||||
83 | |||||
84 | $email = $input->getOption(self::OPTION_EMAIL); |
||||
85 | $omitted = $input->getOption(self::OPTION_OMITTED); |
||||
86 | $all = $input->getOption(self::OPTION_ALL); |
||||
87 | |||||
88 | if ($email === null && $omitted === false && $all === false) { |
||||
89 | throw new RuntimeException('Please provide at least one option'); |
||||
90 | } |
||||
91 | |||||
92 | if ($email !== null && ($omitted === true || $all === true)) { |
||||
93 | throw new RuntimeException('You cannot use --email together with another option'); |
||||
94 | } |
||||
95 | |||||
96 | if ($omitted === true && $all === true) { |
||||
97 | throw new RuntimeException('You cannot use --omitted and --all together'); |
||||
98 | } |
||||
99 | } |
||||
100 | |||||
101 | /** |
||||
102 | * @inheritDoc |
||||
103 | */ |
||||
104 | protected function execute(InputInterface $input, OutputInterface $output) |
||||
105 | { |
||||
106 | $customerIds = $this->getCustomerIds($input); |
||||
107 | $customerIdsCount = count($customerIds); |
||||
108 | |||||
109 | if ($customerIdsCount === 0) { |
||||
110 | $output->writeln('<error>No customer(s) found matching your criteria</error>'); |
||||
111 | return Cli::RETURN_FAILURE; |
||||
112 | } |
||||
113 | |||||
114 | $progressBar = $this->createProgressBar( |
||||
115 | $output, |
||||
116 | $customerIdsCount, |
||||
117 | 'Customer(s)' |
||||
118 | ); |
||||
119 | |||||
120 | foreach ($customerIds as $customerId) { |
||||
121 | $this->publisher->publish( |
||||
122 | Topics::CUSTOMER_CUSTOMER_EXPORT, |
||||
123 | json_encode(['magento_customer_id' => $customerId]) |
||||
0 ignored issues
–
show
json_encode(array('magen...er_id' => $customerId)) of type string is incompatible with the type array|object expected by parameter $data of Magento\Framework\Messag...herInterface::publish() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
124 | ); |
||||
125 | |||||
126 | $progressBar->advance(); |
||||
127 | } |
||||
128 | |||||
129 | $output->writeln(''); |
||||
130 | $output->writeln(sprintf( |
||||
131 | '<info>%s customers(s) have been scheduled for export.</info>', |
||||
132 | ($customerIdsCount) |
||||
133 | )); |
||||
134 | |||||
135 | return Cli::RETURN_SUCCESS; |
||||
136 | } |
||||
137 | |||||
138 | /** |
||||
139 | * @param InputInterface $input |
||||
140 | * @return array |
||||
141 | */ |
||||
142 | private function getCustomerIds(InputInterface $input): array |
||||
143 | { |
||||
144 | /** @var CustomerCollection $customerCollection */ |
||||
145 | $customerCollection = $this->customerCollectionFactory->create(); |
||||
146 | |||||
147 | if (($email = $input->getOption(self::OPTION_EMAIL)) !== null) { |
||||
148 | $customerCollection->addEmailFilter($email); |
||||
149 | } |
||||
150 | |||||
151 | if ($input->getOption(self::OPTION_OMITTED)) { |
||||
152 | $customerCollection->addCustomerOmittedFilter(); |
||||
153 | } |
||||
154 | |||||
155 | return $customerCollection->getAllIds(); |
||||
156 | } |
||||
157 | } |
||||
158 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths