/** * Executes query * * @param AllegroApi $api * @return int */ public function execute(AllegroApi $api) { $result = $api->searchItems($this->query['query'], isset($this->query['filters']) ? $this->query['filters'] : null); $response = ResponseStorage::getInstance(); $allegroIds = array_map(function ($item) { return $item['allegroId']; }, $this->responses); $filteredData = []; foreach ($result as $allegroId => $content) { if (!in_array($allegroId, $allegroIds)) { $filteredData[$allegroId] = $content; $rid = $response->set(['allegroId' => $allegroId]); $response->hasOne($rid, QueryStorage::getInstance(), $this->queryId); } } if (empty($filteredData)) { return 0; } $response->save(); $mail = AllegroHelper::createEmail($filteredData); foreach ($this->emails as $emailData) { mail($emailData['email'], QueryStorage::formatQuery($this->query), str_replace('[[MESSAGE]]', isset($emailData['message']) ? $emailData['message'] : '', $mail), "Content-Type: text/html; charset=ISO-8859-1\r\n"); } return count($filteredData); }
private function registerShow() { $command = $this->register('show'); // set description $command->setDescription('Shows all queries'); // set action $command->setCode(function (InputInterface $input, OutputInterface $output) { // iterate through all queries foreach (QueryStorage::getInstance()->getAll() as $id => $data) { $output->writeln(sprintf('%s: <info>%s</info>', $id, QueryStorage::formatQuery($data))); } }); }