Skip to content

Merged all open PR's request into one pull request#188

Open
jkwakman wants to merge 67 commits intofloriansemm:masterfrom
jkwakman:dev-master
Open

Merged all open PR's request into one pull request#188
jkwakman wants to merge 67 commits intofloriansemm:masterfrom
jkwakman:dev-master

Conversation

@jkwakman
Copy link
Copy Markdown
Contributor

Bundled all changes into one PR. Merging and maintaining all the separate PR's causes a mess.

jkwakman added 30 commits July 20, 2018 14:23
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
PHPUnit v5 namespace is deprecated. Changed it to the new v6 namespace.
Current version of phpunit. Support untill 1 feb 2019.
Here we test if the field Alias is working as expected.
When using the OnetoMany relation we often do not want the parameter name as the fieldname in the Solr database. For example..

Company -> Orders ($orders) -> getOrderNumber()

Here the fieldname will be casted to orders_ss in the solr_database. Instead we want order_id_ss.

To arrange this behaviour we added the fieldAlias in the annotation.

 * @solr\Field(type="strings", getter="getOrderId", fieldAlias="order_id")
To define an alias field name for the database entry you can use the fieldAlias in the @solr\Field tag.
Added a db example after code review
Added typo fix from costom to custom.
Added typo fix from costom to custom.
Added typo fix from costom to custom.
Added typo fix from costom to custom.
Added typo fix from costom to custom.
Added typo fix from costom to custom.
@jkwakman jkwakman changed the title Dev master Merged all open PR's request into one pull request Sep 11, 2018
@floriansemm
Copy link
Copy Markdown
Owner

I will test your pull-request in the end of the week

Copy link
Copy Markdown
Owner

@floriansemm floriansemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bug in the annotation reader class. I have add locally a test case

    /**
     * @test
     */
    public function readPropertiesFromFields()
    {
        $entity = new EntityWithFields();

        $nested = new ValidTestEntity();
        $nested->setId(rand(1, 10000));
        $nested->setTitle('title 123');

        $entity->setFields([$entity]);

        $this->reader->getFields($entity);
    }
    // ....
class EntityWithFields
{
    /**
     * @Solr\Fields(getter="getFields", fields={
     *      @Solr\Field(type="integers", getter="getId", fieldAlias="id"),
     *      @Solr\Field(type="strings", getter="getTitle", fieldAlias="title")
     *      })
     */
    private $fields;

    /**
     * @return mixed
     */
    public function getFields()
    {
        return $this->fields;
    }

    /**
     * @param mixed $fields
     */
    public function setFields($fields)
    {
        $this->fields = $fields;
    }
}

This causes an exception Unknown method "getId" configured which I would not expect here.

$property->setAccessible(true);
$annotation->value = $property->getValue($entity);
$annotation->name = $property->getName();
if($type == $this::FIELDS_CLASS) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space between if and bracket

Comment thread Doctrine/Annotation/AnnotationReader.php
$field->getter = $method;

} else {
throw new AnnotationReaderException(sprintf('Unknown method "%s" configured', $method));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add class in the exception message

@jkwakman
Copy link
Copy Markdown
Contributor Author

Dear Florian,

Thank you for you're time reviewing my PR. I have added the following changes (see commits):

  • Added fix for inserting array of objects instead of doctrine annotation data.
  • Added test testReadPropertiesMultipleFields in AnnotationReaderTest.php
  • Added extra tests for exceptions:

testGetFields_NoParentGetter
testGetFields_UnkownParentGetterMethod
testGetFields_NoFieldAlias
testGetFields_NoFieldGetter
testGetFields_UnknownFieldGetter

  • Removed newlines and added missing spaces.

Can you please reevaluate my PR? If you require any further information, feel free to contact me.

Kind regards,

Jack Kwakman

@floriansemm
Copy link
Copy Markdown
Owner

I have tested your feature with an Post entity that has a tags property.

    /**
     * @Solr\Fields(getter="getTags", fields={
     *      @Solr\Field(type="integers", getter="getId", fieldAlias="id"),
     *      @Solr\Field(type="strings", getter="getName", fieldAlias="name")
     *      })
     *
     * @ORM\OneToMany(targetEntity="Acme\DemoBundle\Entity\Tag", mappedBy="post", cascade={"persist", "remove"})
     */
    private $tags;

When I persist a post then an error is logged:

solr.DEBUG: Unknown method defined "getId" in class "Acme\DemoBundle\Entity\Post"
Post has an getId method, but I would expect that Tag::getId is called in this case.

        $post = new Post();
        $post->setTitle('post with fields');
        $post->setText('text');

        $tag1 = new Tag();
        $tag1->setName('tag #1');

        $tag2 = new Tag();
        $tag2->setName('tag #2');

        $post->setTags([$tag1, $tag2]);
        // save $post comes here....

Did I have misunderstood the documentation?

@jkwakman
Copy link
Copy Markdown
Contributor Author

jkwakman commented Oct 30, 2018

Dear Florian,

I have reevaluated the changes with the example in the docs. I have e-mailed the example entities so we can be sure we test the same setup. These entities are working without errors on my side and update the Solr database with the following result:

{
"id":"post_15",
"id_is":[29,30],
"name_ss":["tag #1","tag #2"],
"version":1615765069600129024}]
}
The tag id's are grouped in the id_is property and the names are grouped under the name_ss. This setup also works for @manytoone relationships and can be defined with the same annotation syntax.

Can you please (re)reevaluate my PR? If you require any further information, feel free to contact me.

Kind regards,

Jack Kwakman

jackabovo and others added 7 commits November 14, 2018 15:32
Thank you for checking my changes. The problem lies in the fact that the current logic for the EntityIndexerSubsriber binds to the postPersist event. I have changes this to the onFlush event so we have access to all the relational data. Now the id's get persisted as expected.

Changes per file:

AnnotationReader: Allow empty relations to be nullable

DocumentFactory: FieldValue should not be required

EntityIndexerSubscriber: Changed the indexer to onFlush instead of postPersist. At that point the ORM relations are available.

Can you please (re)reevaluate my PR? If you require any further information, feel free to contact me.

Kind regards,

Jack Kwakman
Thank you for checking my changes. The problem lies in the fact that the current logic for the EntityIndexerSubsriber binds to the postPersist event. I have changes this to the onFlush event so we have access to all the relational data. Now the id's get persisted as expected.

Changes per file:

AnnotationReader: Allow empty relations to be nullable

DocumentFactory: FieldValue should not be required

EntityIndexerSubscriber: Changed the indexer to onFlush instead of postPersist. At that point the ORM relations are available.

Can you please (re)reevaluate my PR? If you require any further information, feel free to contact me.

Kind regards,

Jack Kwakman
Thank you for checking my changes. The problem lies in the fact that the current logic for the EntityIndexerSubsriber binds to the postPersist event. I have changes this to the onFlush event so we have access to all the relational data. Now the id's get persisted as expected.

Changes per file:

AnnotationReader: Allow empty relations to be nullable

DocumentFactory: FieldValue should not be required

EntityIndexerSubscriber: Changed the indexer to onFlush instead of postPersist. At that point the ORM relations are available.

Can you please (re)reevaluate my PR? If you require any further information, feel free to contact me.

Kind regards,

Jack Kwakman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants