/** * Create new query exector * * @param mixed $id Qeery id * @throws Exception */ public function __construct($id) { $queryStorage = QueryStorage::getInstance(); $this->query = $queryStorage->getById($id); if (empty($this->query)) { throw new Exception("Query {$id} does not exist."); } $this->emails = EmailStorage::getInstance()->getAllWhichHasOne($id, $queryStorage); $this->responses = ResponseStorage::getInstance()->getAllWhichHasOne($id, $queryStorage); $this->queryId = $id; }
private function registerUnsubscribe() { $command = $this->register('unsubscribe'); // set description $command->setDescription('Deletes email related to query'); // set arguments $command->setDefinition(array(new InputArgument('email', InputArgument::REQUIRED, 'Email address'), new InputArgument('id', InputArgument::REQUIRED, 'Query identifier'))); // set action $command->setCode(function (InputInterface $input, OutputInterface $output) { // get argument id $id = $input->getArgument('id'); // get argument email $email = $input->getArgument('email'); // email storage $emailStorage = EmailStorage::getInstance(); // get key $key = $id . ',' . $email; // get email keys $emailIds = $emailStorage->getIds(); // check if query exists if (in_array($key, $emailIds)) { // set data $emailStorage->delete($key); // save $emailStorage->save(); // output $output->writeln(sprintf('%s email unsubscribed (from query %s)', $email, $id)); } else { $output->writeln("Email {$email} related to query {$id} not found"); } }); }