public function setUp() { $this->entry = new Entry(self::FAKE_ID); $this->entry->addMessage(1, 'Message #1'); $this->entry->addMessage(2, 'Message #2'); $this->entry->addMessage(3, 'Message #3'); $this->entry->addMessage(4, 'Message #4'); $this->entry->addException('Exception #1'); $this->entry->addException('Exception #2'); $this->path = self::REPORT_PATH . $this->entry->getId() . '.txt'; }
/** * Saves report to a file. * * @param Entry $entry * @throws ReportException */ public function save(Entry $entry) { $content = sprintf("User: %s", $entry->getId()); $messages = $this->createMessageReport($entry->getMessages()); $exceptions = $this->createExceptionReport($entry->getExceptions()); $content .= PHP_EOL . $messages . PHP_EOL . $exceptions; $this->saveToFile($content); }
public function add(Entry $entry) { $rowCount = 0; if ($entry->getId()) { ++$rowCount; foreach ($entry->getMessages() as $message) { ++$rowCount; } } self::$added = $rowCount; self::$entry = $entry; }
/** * Adds an Entry object to the database. Entry object contains User and Messages data. * * @param Entry $entry * @return int * @throws \DataAggregator\Store\StoreException */ public function add(Entry $entry) { $this->pdo->beginTransaction(); $stmt = $this->pdo->prepare(sprintf("INSERT INTO %s (provider_id) VALUES(:provider_id)", self::TABLE_USER)); $stmt->bindValue(':provider_id', $entry->getId(), \PDO::PARAM_STR); $rowCount = 0; try { $stmt->execute(); $userId = $this->pdo->lastInsertId(); $rowCount += $this->prepareMultiInsert($userId, $entry->getMessages()); $this->pdo->commit(); } catch (\PDOException $ex) { $this->pdo->rollBack(); throw new StoreException($ex->getMessage()); } $rowCount += $stmt->rowCount(); return $rowCount; }