akeeba / fof

Rapid Application Development framework for Joomla!™ 3 and 4
0 stars 0 forks source link

Bug in DataModel update item #634

Closed go-source closed 7 years ago

go-source commented 7 years ago

Error happens when updating a record from edit view, if id >1, error message: Duplicate entry '2646' for key 'PRIMARY' SQL=INSERT INTO ...

In DataModel line 1079 $isNewRecord = $oldPKValue != $this->getId();

The intention (I guess) for this equation was to get zero but it is null. Replacing by:

$isNewRecord = 0;

Resolves the issue and is easier to understand. Please confirm

nikosdion commented 7 years ago

No. If old primary key value is different than the current value then is new record is true, else it is false.

Nicholas Dionysopoulos Director, Akeeba Ltd

Sent from a mobile device. Please excuse my brevity.

On 1 Oct 2016, at 23:51, pedrobicudo notifications@github.com wrote:

Error happens when updating a record from edit view, if id >1, error message: Duplicate entry '2646' for key 'PRIMARY' SQL=INSERT INTO ...

In DataModel line 1079 $isNewRecord = $oldPKValue != $this->getId();

The intention (I guess) for this equation was to get zero but it is null. Replacing by:

$isNewRecord = 0;

Resolves the issue and is easier to understand. Please confirm

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

go-source commented 7 years ago

That is what is written not what is happening. Tested on Magic Factory, front end, xml forms. From browse list all items have url on title field, click on title FOF3 send to form.form.xml edit.

On JToolBarHelper::apply() action is ...&task=edit&id=1 at line 1079: $this->getId() value is 1 and $oldPKValue value is 1. No error message. Saves OK.

On JToolBarHelper::apply() action is ...&task=edit&id=5 $this->getId() value is 5 and $oldPKValue value is 1. Error: Duplicate entry '5' for key 'PRIMARY' SQL=INSERT INTO...

This test shows a bug.

It seems I do not have the skills to solve this.

nikosdion commented 7 years ago

And it does not happen to the example component or any other component because...? Maybe because the bug is in your code?

Nicholas Dionysopoulos Director, Akeeba Ltd

Sent from a mobile device. Please excuse my brevity.

On 2 Oct 2016, at 22:12, pedrobicudo notifications@github.com wrote:

That is what is written not what is happening. Tested on Magic Factory, front end, xml forms. From browse list all items have url on title field, click on title FOF3 send to form.form.xml edit.

On JToolBarHelper::apply() action is ...&task=edit&id=1 at line 1079: $this->getId() value is 1 and $oldPKValue value is 1. No error message. Saves OK.

On JToolBarHelper::apply() action is ...&task=edit&id=5 $this->getId() value is 5 and $oldPKValue value is 1. Error: Duplicate entry '5' for key 'PRIMARY' SQL=INSERT INTO...

This test shows a bug.

It seems I do not have the skills to solve this.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

go-source commented 7 years ago

For sure something is wrong and I am asking for help to find what is wrong. I'll do more test , i.e: install the example component in this dev environment and will add a note here. For now I solved this by replacing with: if ($this->getId()) {$isNewRecord = false; } else { $isNewRecord = $oldPKValue != $this->getId(); }

go-source commented 7 years ago

Nick, I installed com_todo in a fresh joomla 3.6 for testing. Bug confirmed, component attached to reproduce the test and confirm. com_todo_FOF30.zip.

The bug does not occur in backend editing. It does happen in frontend. Just install the component, it will insert sample data, in the front end type com_todo&view=items, select edit of the item 2, on the edit page choose save&close - the error will show up. Please confirm.

nikosdion commented 7 years ago

Cannot reproduce using your instructions. I assume that your problem has to do with something broken in your PHP. I base that on your claim that $isNewRecord = $oldPKValue != $this->getId(); makes $isNewRecord to be null which is impossible (the right hand side is a boolean expression which can be exactly TRUE or FALSE but nothing else). For this reason I am closing this issue as invalid.