akeneo-labs / EnhancedConnectorBundle

[DEPRECATED] Provides product reader with more option (choice on completeness, choice on enabled, delta based on last export time).
21 stars 11 forks source link

Invalid DateTime value #38

Closed sagikazarmark closed 8 years ago

sagikazarmark commented 8 years ago

I am trying to use the enhanced product export, with the updated since condition.

I passed this value as a parameter: -1 hour

Based on my quick inspections of the code, it should just work, I couldn't find any validations.

Still, I see the following error on the export view page:

This value is not a valid datetime.

Although it is not an absolute datetime representation, it is perfectly valid.

Where is this validation and how can I bypass it?

damien-carcel commented 8 years ago

Hi.

According to the message, this is a Symfony validation, performed by this constraint: Symfony\Component\Validator\Constraints\DateTime, and affecting all DateTime objects in Symfony project. So I don't think it is possible to bypass it.

Another solution that could work, however, is to provide a new field in the enhanced product reader, which does not wait for a date time, but for a time diff (what you want). When this option is enable, your code must calculate a DateTime by comparing the diff you put and the actual DateTime the export is launched at, and send this DateTime to the reader.

Regards, Damien

sagikazarmark commented 8 years ago

Where is this validation done? The updatedSince configuration is defined as string (defined without type) which means that field itself is not validated.

Is the datetime object validated or the string? Because this works perfectly: new \DateTime('-1 hour').

damien-carcel commented 8 years ago

new \DateTime('-1 hour') is pure PHP. Symfony, however, doesn't accept that. The validation is performed by the Validator component.

In the Enhanced product reader, you can find this variable:

/**
 * @Assert\DateTime(groups={"Execution"})
 * @var string
 */
protected $updatedSince;

You can probably bypass this precise validation by overriding the reader, and only redefining this variable without the annotation. However, I cannot guarantee that there will be no side effects.

Regards, Damien

sagikazarmark commented 8 years ago

Thanks for pointing me there. I think I will write my own constraint and validator which tries to convert the value to a datetime object and decides validation based on success.

Would you be open to such validation in this package? I think the feature itself would be a great addition (running exports based on relative time).

damien-carcel commented 8 years ago

Hi.

I too think the feature would be great, and we always appreciate external contributions on our bundles. So don't hesitate to do a pull request.

Regards, Damien