【发布时间】:2017-02-07 15:21:28
【问题描述】:
我在调用内部制作的 api 时遇到问题。 日志说:
[2017-02-07 16:04:39] doctrine.DEBUG: SELECT h0_.id AS id_0, h0_.hash AS hash_1, h0_.request AS request_2, h0_.options AS options_3, h0_.serialized_response_body AS serialized_response_body_4, h0_.response AS response_5, h0_.sent_at AS sent_at_6 FROM http_request h0_ WHERE h0_.hash = ? ["dd3e36a5a38618974cae2b45f9cb3a67"] []
[2017-02-07 16:04:39] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Notice: unserialize(): Error at offset 36 of 40 bytes" at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/ObjectType.php line 57 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\ContextErrorException(code: 0): Notice: unserialize(): Error at offset 36 of 40 bytes at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/ObjectType.php:57)"} []
我有点迷茫>.
编辑:
在我的控制器中,我提交了一个包含多个信息的表单以执行该过程。
/**
* @Rest\View(serializerGroups={"Review"})
* @Security("is_granted('ROLE_REVIEW_CREATE')")
*/
public function postAction(Request $request)
{
if ($this->getUser()->getBalance()->getTokens() == 0) {
throw new AccessDeniedException('The Review can not be created because you lack of tokens');
}
$review = new Review();
$review->setCreatedBy($this->getUser());
$reviewForm = $this->createForm(ReviewType::class, $review, [
'csrf_protection' => false,
]);
$reviewForm->submit($request->request->all());
if ($reviewForm->isSubmitted() && $reviewForm->isValid()) {
// If the user is in an organization, takes the organization analyzer environment, otherwise takes the user one.
$analyzerEnvironment = $this->getUser()->getCompany() ? $this->getUser()->getCompany()->getAnalyzerEnvironment() : $this->getUser()->getAnalyzerEnvironment();
$crawlingFlow = $this->get('app.manager.crawling_flow')->getCrawlingFlow();
$this->get('app.manager.review')->process(
$review,
$crawlingFlow,
$analyzerEnvironment
);
$reviewEncrypted = new ReviewEncrypted();
$reviewEncrypted->setReliability($review->getReliability());
$reviewEncrypted->setData($this->get('app.manager.review')->encrypt($review));
$reviewEncrypted->setCreatedBy($this->getUser());
$this->getDoctrine()->getManager()->persist($reviewEncrypted);
$this->getDoctrine()->getManager()->flush();
$review->setId($reviewEncrypted->getId());
if ($this->getUser()->getBalance()->getTokens() > 0) {
$this->getUser()->getBalance()->setTokens($this->getUser()->getBalance()->getTokens() - 1);
$this->getDoctrine()->getManager()->persist($this->getUser());
$this->getDoctrine()->getManager()->flush();
}
return $review;
}
return $reviewForm;
}
调用时:
$crawlingFlow = $this->get('app.manager.crawling_flow')->getCrawlingFlow();
$this->get('app.manager.review')->process(
$review,
$crawlingFlow,
$analyzerEnvironment
);
调用了几个服务,它们发送请求,执行诸如存储在数据库中之类的事情......
问题是,当我更改数据库(从 mysql 到 postgresql)时,我是否忘记了做某事,或者是别的什么?
哪里可能会出现 unserialize() 错误?为什么?
感谢您的帮助:p
编辑 2:
根据日志“vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/ObjectType.php line 57”,这里是错误的来源:
/**
* {@inheritdoc}
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return serialize($value);
}
/**
* {@inheritdoc}
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
}
$value = (is_resource($value)) ? stream_get_contents($value) : $value;
$val = unserialize($value);
if ($val === false && $value !== 'b:0;') {
throw ConversionException::conversionFailed($value, $this->getName());
}
return $val;
}
【问题讨论】:
-
你的代码有什么问题吗?
-
是的,数据可能会有所帮助。
-
抱歉帖子已编辑
标签: php mysql postgresql symfony