1

APIを作成するためにApigilityを使用し、ORMとしてDoctrineを使用しています。次のコードは、flush() 時にセグメンテーション違反を生成します (作成した検証の一部を削除しました)。

class AdvertisersResource extends AbstractResourceListener 
{
    public function create($data)
    {
        $entityClass = $this->getEntityClass();
        $advertiserEntity = new $entityClass;
        $connection = $this->entityManager->getConnection();

        // rejecting if the posted data already contains an advertiser_id
        if (!empty($data->advertiser_id)) {
            return new ApiProblem(406, 'Advertiser ID cannot be provided at creation time.');
        }

        // generating the next advertiser_id
        $sql = "
        SELECT
            MAX(advertiser_id) + 1 as advertiser_id
        FROM
            advertisers
        ";
        $result = $connection->fetchAssoc($sql);
        if (empty($result)) {
            // error generating the new category_id
            return new ApiProblem(500, 'Database error.');
        }
        $advertiserEntity->setAdvertiserId((int)$result['advertiser_id']);

        // input data validation
        $advertisersRepository = $this->entityManager->getRepository('io\V1\Rest\Advertisers\AdvertisersEntity');

        // advertiser name uniqueness
        $result = $advertisersRepository->findBy(array('advertiserName' => $advertiserEntity->getAdvertiserName()));
        if (!empty($result)) {
            return new ApiProblem(406, 'There is already an advertiser with this name.');
        }

        // validate geo_id
        $sql = "
        SELECT
            countryCode
        FROM
            countries (NOLOCK)
        WHERE
            countryCode = '{$data->geo_id}'
        ";
        $result = $connection->fetchAssoc($sql);
        if (empty($result)) {
            return new ApiProblem(406, 'Invalid geo ID: ' . $data->geo_id . ".");
        }
        $advertiserEntity->setGeoId($data->geo_id);

        $advertiserEntity->setAdvertiserName($data->advertiser_name);

        // ?????????????????????????????????????????
        // ????????  WHY IS THIS NECESSARY  ????????
        // without it -> segmentation fault
        $connection->close();
        // ?????????????????????????????????????????

        $this->entityManager->persist($advertiserEntity);
        $this->entityManager->flush();

        $categories = $advertiserEntity->getCategories();
        $advertiserEntity->setCategories(Util::extractCollection($categories));

        return $advertiserEntity;
    }
}

を使用していない場合にのみセグメンテーション違反が発生する$connection->close();ため、何らかの理由で接続がハングしたままになっていると思いますが、なぜこれが発生するのかについて明確な説明を得ることができませんでした。

4

1 に答える 1

0

Doctrine の最新バージョンを使用していますか? また、PHP のバージョンをアップグレードしてみてください。

于 2014-08-08T14:10:33.223 に答える