Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Problem processing entities with non-scalar id #184

Closed
core23 opened this issue Nov 2, 2018 · 1 comment
Closed

Problem processing entities with non-scalar id #184

core23 opened this issue Nov 2, 2018 · 1 comment
Labels

Comments

@core23
Copy link
Member

core23 commented Nov 2, 2018

Environment

Sonata packages

sonata-project/admin-bundle              3.40.2          3.40.2             The missing Symfony Admin Generator
sonata-project/block-bundle              3.12.1          3.12.1             Symfony SonataBlockBundle
sonata-project/cache                     1.1.1           2.0.1              Cache library
sonata-project/cache-bundle              2.4.2           3.0.0              This bundle provides caching services
sonata-project/classification-bundle     3.7.1           3.7.1              Symfony SonataClassificationBundle
sonata-project/core-bundle               3.11.2          3.11.2             Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.4.0           2.4.0              Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.1.0           1.1.0              Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.6.3           3.6.3              Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.5.0           2.5.0              Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.9.1           1.9.1              Lightweight Exporter library
sonata-project/formatter-bundle          4.1.2           4.1.2              Symfony SonataFormatterBundle
sonata-project/intl-bundle               2.5.0           2.5.0              Symfony SonataIntlBundle
sonata-project/media-bundle              3.16.2          3.16.2             Symfony SonataMediaBundle
sonata-project/notification-bundle       3.5.1           3.5.1              Symfony SonataNotificationBundle
sonata-project/page-bundle               3.9.0           3.9.0              This bundle provides a Site and Page management through container and block services
sonata-project/seo-bundle                2.x-dev bee783d dev-master a23f60e Symfony SonataSeoBundle
sonata-project/timeline-bundle           3.3.1           3.3.1              Integrates SpyTimelineBundle into Sonata
sonata-project/user-bundle               4.2.3           4.2.3              Symfony SonataUserBundle

Symfony packages

symfony/asset                   v4.1.6  v4.1.6  Symfony Asset Component
symfony/cache                   v4.1.6  v4.1.6  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config                  v4.1.6  v4.1.6  Symfony Config Component
symfony/console                 v4.1.6  v4.1.6  Symfony Console Component
symfony/css-selector            v4.1.6  v4.1.6  Symfony CssSelector Component
symfony/debug                   v4.1.6  v4.1.6  Symfony Debug Component
symfony/debug-bundle            v4.1.6  v4.1.6  Symfony DebugBundle
symfony/dependency-injection    v4.1.6  v4.1.6  Symfony DependencyInjection Component
symfony/doctrine-bridge         v4.1.6  v4.1.6  Symfony Doctrine Bridge
symfony/dom-crawler             v4.1.6  v4.1.6  Symfony DomCrawler Component
symfony/dotenv                  v4.1.6  v4.1.6  Registers environment variables from a .env file
symfony/event-dispatcher        v4.1.6  v4.1.6  Symfony EventDispatcher Component
symfony/expression-language     v4.1.6  v4.1.6  Symfony ExpressionLanguage Component
symfony/filesystem              v4.1.6  v4.1.6  Symfony Filesystem Component
symfony/finder                  v4.1.6  v4.1.6  Symfony Finder Component
symfony/flex                    v1.1.1  v1.1.1  Composer plugin for Symfony
symfony/form                    v4.1.6  v4.1.6  Symfony Form Component
symfony/framework-bundle        v4.1.6  v4.1.6  Symfony FrameworkBundle
symfony/http-foundation         v4.1.6  v4.1.6  Symfony HttpFoundation Component
symfony/http-kernel             v4.1.6  v4.1.6  Symfony HttpKernel Component
symfony/inflector               v4.1.6  v4.1.6  Symfony Inflector Component
symfony/intl                    v4.1.6  v4.1.6  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/monolog-bridge          v4.1.6  v4.1.6  Symfony Monolog Bridge
symfony/monolog-bundle          v3.3.0  v3.3.0  Symfony MonologBundle
symfony/options-resolver        v4.1.6  v4.1.6  Symfony OptionsResolver Component
symfony/phpunit-bridge          v4.1.6  v4.1.6  Symfony PHPUnit Bridge
symfony/polyfill-ctype          v1.10.0 v1.10.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-icu       v1.10.0 v1.10.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring       v1.10.0 v1.10.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72          v1.10.0 v1.10.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/process                 v4.1.6  v4.1.6  Symfony Process Component
symfony/property-access         v4.1.6  v4.1.6  Symfony PropertyAccess Component
symfony/psr-http-message-bridge v1.1.0  v1.1.0  PSR HTTP message bridge
symfony/routing                 v4.1.6  v4.1.6  Symfony Routing Component
symfony/security                v4.1.6  v4.1.6  Symfony Security Component
symfony/security-acl            v3.0.1  v3.0.1  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle         v4.1.6  v4.1.6  Symfony SecurityBundle
symfony/stopwatch               v4.1.6  v4.1.6  Symfony Stopwatch Component
symfony/swiftmailer-bundle      v3.2.4  v3.2.4  Symfony SwiftmailerBundle
symfony/templating              v4.1.6  v4.1.6  Symfony Templating Component
symfony/translation             v4.1.6  v4.1.6  Symfony Translation Component
symfony/twig-bridge             v4.1.6  v4.1.6  Symfony Twig Bridge
symfony/twig-bundle             v4.1.6  v4.1.6  Symfony TwigBundle
symfony/validator               v4.1.6  v4.1.6  Symfony Validator Component
symfony/var-dumper              v4.1.6  v4.1.6  Symfony mechanism for exploring and dumping PHP variables
symfony/web-profiler-bundle     v4.1.6  v4.1.6  Symfony WebProfilerBundle
symfony/yaml                    v4.1.6  v4.1.6  Symfony Yaml Component

Subject

Steps to reproduce

Given an user entity with an id of type UserId and try to persist an entity with an associated user.

namespace App\Bundle\Doctrine\Entity\User;

class UserId extends GuidType
{
    /**
     * {@inheritdoc}
     */
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        return \is_object($value) ? $value->value() : $value;
    }

    /**
     * {@inheritdoc}
     */
    public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        if (null === $value) {
            return null;
        }

        $className = $this->getName();

        return new $className($value);
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return \App\Domain\User\Model\UserId::class;
    }
}

namespace App\Domain\User\Model;

use Ramsey\Uuid\Uuid;

final class UserId
{
    /**
     * @var string
     */
    private $id;

    /**
     * @param string|null $id
     */
    public function __construct(?string $id = null)
    {
        $this->id = $id ?? Uuid::uuid4()->toString();
    }

    /**
     * @return string
     */
    public function __toString()
    {
        return (string) $this->value();
    }

    /**
     * @return string
     */
    public function value(): string
    {
        return $this->id;
    }

    /**
     * @param UserId $userId
     *
     * @return bool
     */
    public function equals(self $userId): bool
    {
        return $this->value() === $userId->value();
    }
}

Expected results

Everything works fine.

Actual results

nvalidArgumentException:
subjectId has to be a scalar or an array

  at vendor/stephpy/timeline/src/Spread/Entry/EntryUnaware.php:42
  at Spy\Timeline\Spread\Entry\EntryUnaware->__construct('App\\Domain\\User\\Model\\User', object(UserId))
     (vendor/sonata-project/timeline-bundle/src/Spread/AdminSpread.php:74)
  at Sonata\TimelineBundle\Spread\AdminSpread->process(object(Action), object(EntryCollection))
     (vendor/stephpy/timeline/src/Spread/Deployer.php:151)
  at Spy\Timeline\Spread\Deployer->processSpreads(object(Action))
     (vendor/stephpy/timeline/src/Spread/Deployer.php:76)
  at Spy\Timeline\Spread\Deployer->deploy(object(Action), object(ActionManager))
     (vendor/stephpy/timeline/src/Driver/AbstractActionManager.php:100)
  at Spy\Timeline\Driver\AbstractActionManager->deployActionDependOnDelivery(object(Action))
     (vendor/stephpy/timeline-bundle/Driver/Doctrine/AbstractActionManager.php:47)
  at Spy\TimelineBundle\Driver\Doctrine\AbstractActionManager->updateAction(object(Action))
     (vendor/sonata-project/timeline-bundle/src/Admin/AdminExtension.php:114)
  at Sonata\TimelineBundle\Admin\AdminExtension->create(object(Component), 'sonata.admin.update', array('target' => object(Component), 'target_text' => 'fos_user_profile_show', 'admin_code' => 'sonata.page.admin.page'))
     (vendor/sonata-project/timeline-bundle/src/Admin/AdminExtension.php:57)
  at Sonata\TimelineBundle\Admin\AdminExtension->postUpdate(object(PageAdmin), object(Page))
     (vendor/sonata-project/admin-bundle/src/Admin/AbstractAdmin.php:671)
  at Sonata\AdminBundle\Admin\AbstractAdmin->update(object(Page))
     (vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php:357)
  at Sonata\AdminBundle\Controller\CRUDController->editAction('60')
     (vendor/symfony/http-kernel/HttpKernel.php:149)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(SiteRequest), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:66)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(SiteRequest), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:188)
  at Symfony\Component\HttpKernel\Kernel->handle(object(SiteRequest))
     (public/index.php:47)
@stale
Copy link

stale bot commented Jan 30, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the wontfix label Jan 30, 2020
@SonataCI SonataCI removed the wontfix label Jan 30, 2020
@core23 core23 added the stale label Feb 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants