[Fixed] PHP generated for Gedmo definition is wrong

0 votes
asked Nov 23, 2018 in Solved by lenar (120 points)
recategorized Aug 14, 2020 by ludek.vodicka

I have multiple Timestampable definitions for one Entity but different fields.
The generated PHP only contains one (seems to be the last definition):

enter image description here

Would have expected:

/**
 * @ORM\Column(type="datetime", nullable=false)
 * @Gedmo\Timestampable(on="create")
 * @Gedmo\Timestampable(on="change", field="status")
 *
 */
private $statusTime;

But this is actually generated:

/**
 * @ORM\Column(type="datetime", nullable=false)
 * @Gedmo\Timestampable(on="change", field="status")
 *
 */
private $statusTime;
commented Nov 23, 2018 by ludek.vodicka Skipper developer (140,450 points)

Thanks for info. We will check it and let you know.

commented Nov 23, 2018 by ludek.vodicka Skipper developer (140,450 points)

I checked your screenshot but there is missing "Field" property for the first timestamp.

Are you sure you have correctly filled these values?

Can you please send me your Skipper file so I can check it directly on your file?

([email protected])

commented Nov 23, 2018 by lenar (120 points)

As I understand (and seems to be logical) Field property is not needed in case of On=create.

From documentation:

Field only valid if on=change is specified, tracks property or a list of properties for changes.

Relevant XML:

<?xml version="1.0"?>
<skipper-clipboard>
  <entity name="SomeBundle\Entity\Issue" local-name="Issue" namespace="SomeBundle\Entity" size-x="0" size-y="0" size-x2="125" size-y2="255" position-x="143" position-y="19" hdr-color="#D2D2D2" bg-color="#FFFFFF">
    <field name="id" type="integer" required="true" unique="true" primary="true" auto-increment="true">
      <orm-attributes>
        <attribute name="generator">
          <attribute name="strategy">IDENTITY</attribute>
        </attribute>
      </orm-attributes>
    </field>
    <field name="createdTime" type="datetime" required="true"/>
    <field name="statusTime" type="datetime" required="true"/>
    <field name="status" type="text" required="true"/>
    <orm-attributes>
      <attribute name="table">rma_cases</attribute>
      <attribute name="Gedmo">
        <attribute name="Timestampable">
          <attribute name="Fields">
            <attribute name="Field">
              <attribute name="On">create</attribute>
              <attribute name="Name">createdTime</attribute>
            </attribute>
            <attribute name="Field">
              <attribute name="Name">statusTime</attribute>
              <attribute name="Field">status</attribute>
              <attribute name="On">change</attribute>
            </attribute>
          </attribute>
        </attribute>
      </attribute>
      <attribute name="change-tracking-policy">DEFERRED_EXPLICIT</attribute>
    </orm-attributes>
  </entity>
</skipper-clipboard>
commented Nov 23, 2018 by ludek.vodicka Skipper developer (140,450 points)

You're probably right, sorry for confusion.

Thanks for example, we will check it.

commented Nov 23, 2018 by ludek.vodicka Skipper developer (140,450 points)

Thanks, but based on your example, the result is valid. You have first field used as "CreatedTime" and second is "StatusTime"

So, the annotation is exported to two different fiels:

/**
 * @ORM\Column(type="datetime", nullable=false)
 * @Gedmo\Timestampable(on="create")
 */
private $createdTime;

/**
 * @ORM\Column(type="datetime", nullable=false)
 * @Gedmo\Timestampable(on="change", field="status")
 */
private $statusTime; 
commented Nov 23, 2018 by lenar (120 points)

Ok, sorry, I've created a little bit of confusion now myself, it seems I removed the third defintion
during the time I tried to find workaround.

I now added it back, and ... it doesn't generate the line for it.

But for some reason I now tried to test what happens if remove @Gedmo annotations alltogether from PHP. And unbelievable ... it generated both definitions.

So, when the existing PHP looks like this:

/**
 * @ORM\Column(type="datetime", nullable=false)
 * @Gedmo\Timestampable(on="change", field="status")
 *
 *
 */
private $statusTime;

... Skipper does not generate the on="create" annotation (and says that file was not changed).

But when the PHP code looks like this before generation:

/**
 * @ORM\Column(type="datetime", nullable=false)
 */
private $statusTime;

It exports it as it should:

/**
 * @ORM\Column(type="datetime", nullable=false)
 * @Gedmo\Timestampable(on="change", field="status")
 * @Gedmo\Timestampable(on="create")
 */
private $statusTime;

BUT on the next generation (initiated immediately after previous one) it removes the on="create" annotation, giving me this:

    /**
 * @ORM\Column(type="datetime", nullable=false)
 * @Gedmo\Timestampable(on="change", field="status")
 *
 */
private $statusTime;

And it stays like this on subsequent generations.

So, my initial report was for actual problem, but I messed up with pic/xml. Sorry about that.

These last tests done with:
enter image description here

And:

    <?xml version="1.0"?>
<skipper-clipboard>
  <entity name="SomeBundle\Entity\Issue" local-name="Issue" namespace="SomeBundle\Entity" size-x="0" size-y="0" size-x2="125" size-y2="255" position-x="143" position-y="19" hdr-color="#D2D2D2" bg-color="#FFFFFF">
    <field name="id" type="integer" required="true" unique="true" primary="true" auto-increment="true">
      <orm-attributes>
        <attribute name="generator">
          <attribute name="strategy">IDENTITY</attribute>
        </attribute>
      </orm-attributes>
    </field>
    <field name="createdTime" type="datetime" required="true"/>
    <field name="statusTime" type="datetime" required="true"/>
    <field name="status" type="text" required="true"/>
    <orm-attributes>
      <attribute name="table">issues</attribute>
      <attribute name="Gedmo">
        <attribute name="Timestampable">
          <attribute name="Fields">
            <attribute name="Field">
              <attribute name="On">create</attribute>
              <attribute name="Name">createdTime</attribute>
            </attribute>
            <attribute name="Field">
              <attribute name="Name">statusTime</attribute>
              <attribute name="Field">status</attribute>
              <attribute name="On">change</attribute>
            </attribute>
            <attribute name="Field">
              <attribute name="Name">statusTime</attribute>
              <attribute name="On">create</attribute>
            </attribute>
          </attribute>
        </attribute>
      </attribute>
      <attribute name="change-tracking-policy">DEFERRED_EXPLICIT</attribute>
    </orm-attributes>
  </entity>
</skipper-clipboard>
commented Nov 23, 2018 by ludek.vodicka Skipper developer (140,450 points)

Perfect, I see the same behavior here. thanks

commented Nov 26, 2018 by ludek.vodicka Skipper developer (140,450 points)

Hi, we identified the problem but this will require more work to do.

We're already reworking AST manipulation (import/export) so we also update it together with this issue.

Unfortunately, currently I can't promise any exact term. It's a large change which allows us to support more framework in the future (starting with Laravel) so it will take some time.

commented Mar 30, 2019 by lenar (120 points)

Can you give now that Laravel support has appeared some ETA for this fix?

commented Mar 30, 2019 by ludek.vodicka Skipper developer (140,450 points)

Hello, although first Laravel support is released, unfortunately, there is no progress in this feature.

We currently skipped import of existing Php Laravel code (there is only database/MySql workbench import) because of the complexity of this issue.

It's still on our todo but this change will require huge code change.

1 Answer

0 votes
answered Apr 6, 2020 by ludek.vodicka Skipper developer (140,450 points)

Fixed in latest beta: https://www.skipper18.com/support/402/downloads-skipper-beta
Please let me know if it works as expected.

...