public function _run($request, $xcontext) { $id = intval(Utils::testInput($request->id)); $this->logger->info("Delete id: {$id}."); if (empty($id)) { $this->logger->error("Id is empty!"); throw new Exception("Id is empty!"); } $bookService = new BookService(); $book = $bookService->delete($id); $this->logger->info("Delete a book which id is {$id}"); if (!$book || $book->id() <= 0) { $this->logger->error("failed in deleting book!"); throw new Exception("failed in deleting 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; }