Ejemplo n.º 1
0
 public function _run($request, $xcontext)
 {
     $id = intval(Utils::testInput($request->id));
     $name = Utils::testInput($request->name);
     $authorid = Utils::testInput($request->authorid);
     $this->logger->info("Update id: {$id}, name: {$name}, authorid: {$authorid}");
     if (empty($id) || empty($name) || empty($authorid)) {
         $this->logger->error("Id, name or authorid is empty!");
         throw new Exception("Id, name or authorid is empty!");
     }
     $bookService = new BookService();
     $book = $bookService->update($id, $name, $authorid);
     $this->logger->info("Update a book which id is {$id}, named {$name} and authorid is {$authorid}");
     if (!$book || $book->id() <= 0) {
         $this->logger->error("failed in updating book!");
         throw new Exception("failed in updating book!");
     }
     return XNext::action("listbook");
 }
Ejemplo n.º 2
0
 public function test_update()
 {
     $as = XAppSession::begin();
     $name = "testname_before";
     $authorid = "3";
     $bookService = new BookService();
     $book = $bookService->add($name, $authorid);
     $as->commit();
     $this->logger->info("Book name before: " . $book->getName() . ", authorid before: " . $book->getAuthor()->id());
     $this->assertTrue(!is_null($book) && strcmp($book->getName(), $name) == 0);
     $name = "testname_after";
     $authorid = "4";
     $book = $bookService->update($book->id(), $name, $authorid);
     $as->commit();
     $this->logger->info("Book name after: " . $book->getName() . ", authorid before: " . $book->getAuthor()->id());
     $this->assertTrue(!is_null($book) && strcmp($book->getName(), $name) == 0);
     Dwriter::ins()->del_Book_by_id($book->id());
     $as->commit();
     $as = null;
     return;
 }