public function _run($request, $xcontext) { $name = Utils::testInput($request->name); $authorid = Utils::testInput($request->authorid); $this->logger->info("Input name: {$name}, authorid: {$authorid}"); if (empty($name) || empty($authorid)) { $this->logger->error("Need name or authorid!"); throw new Exception("Need name or authorid!"); } $bookService = new BookService(); $book = $bookService->add($name, $authorid); $this->logger->info("Create a book named {$name} which authorid is {$authorid}"); if (!$book || $book->id() <= 0) { $this->logger->error("failed in adding book!"); throw new Exception("failed in adding book!"); } return XNext::action("listbook"); }
public function test_delete() { $as = XAppSession::begin(); $name = "testname_delete"; $authorid = "3"; $bookService = new BookService(); $book = $bookService->add($name, $authorid); $as->commit(); $this->logger->info("Book status before: " . $book->getStatus()); $this->assertTrue(!is_null($book) && $book->getStatus() == Constants::USING); $book = $bookService->delete($book->id()); $as->commit(); $this->logger->info("Book status after: " . $book->getStatus()); $this->assertTrue(!is_null($book) && $book->getStatus() == Constants::DELETED); Dwriter::ins()->del_Book_by_id($book->id()); $as->commit(); $as = null; return; }