Sackgesicht VIP
Total posts: 1,636
04 Июнь 2017 10:00

CobaltApi::updateRecord() seems not working...

$record_id = 147854;
CobaltApi::updateRecord($record_id, $data = array(), [52 => '1245'], $categories = array(), $tags = array());

does not have any impact on the record.

Последние изменения: 22 Сен 2017


Sergey
Total posts: 13,748
18 Июнь 2017 08:57

What is 52 field type?


Sackgesicht VIP
Total posts: 1,636
18 Июнь 2017 09:10

text


Sergey
Total posts: 13,748
18 Июнь 2017 09:21

This code works for me perfectly

CobaltApi::updateRecord(821, [], [54 => 'wwwwwqw']);

Check all your parameters once more.


Sackgesicht VIP
Total posts: 1,636
18 Июнь 2017 09:51

hmmm ... just tried CobaltApi::updateRecord(147854, [], [52 => 'new']);

i only receive the Notice: Undefined index: extime in /administrator/components/com_cobalt/tables/record.php on line 201 and no update of the field/record

Joomla 3.7.2, PHP 7.0.19, Cobalt 8.741


Sackgesicht VIP
Total posts: 1,636
18 Июнь 2017 12:51

if i try to update a record where the field does not exist yet in js_res_record_values, nothing happens.

If i try to update a record, where the field exist already in js_res_record_values, it just duplicates the record with the original value.

I used CobaltApi::updateRecord(147858, [], [52 => 'new']);

2017-06-18_20-48-12

It should not create 2 records in js_res_record_values and it does not rename it to "new".


Sergey
Total posts: 13,748
19 Июнь 2017 13:31

I have to add unique index for this table for fields_id and record_id.

Unfortunately I cannot tell why it does not update record, until I reproduce it or get access to that instance.


Sackgesicht VIP
Total posts: 1,636
19 Июнь 2017 16:22

Sergey I have to add unique index for this table for fields_id and record_id.

Same fields store multiple records per record_id with different value_index. The table should be fine. There seems just some bug in the update. With the new 8.742, the Notice about the extime index is gone but duplication of records still continues and it just duplicates the old value and does not take the new value.


Sackgesicht VIP
Total posts: 1,636
20 Июнь 2017 00:29

After i checked the manual update of a record, I realized that Cobalt deletes all field rows in #__js_res_record_values of a particular record and rewrites them again on edit.

Now it is clear, that since the CobaltApi::updateRecord() uses the same code as CobaltApi::createRecord() it does not delete the existing rows before recreating them. To solve the double creation of rows a $table->clean($record->id,''); is missing in the code.

The other problem is that $values does not hold the updated values for the fields --> it always stores the original value and does not update the field.


Sackgesicht VIP
Total posts: 1,636
07 Июль 2017 04:13

Sergey Unfortunately I cannot tell why it does not update record, until I reproduce it or get access to that instance.

There are 2 problems why it is not working:

1) It does not update the record because the query is an "Insert" not an "Update".

Therefore it should first delete all record values, because they will be newly created with the $table->store_value($value, $key, $record, $field);

Before calling the _touchRecord() function it should delete like:

static public function updateRecord($redord_id, $data, $fields = array(), $categories = array(), $tags = array())
    {
        $record = JTable::getInstance('Record', 'CobaltTable');
        $record->load($redord_id);
        $record->bind($data);
        $data = $record->getProperties();

        $table  = JTable::getInstance('Record_values', 'CobaltTable');
        $table->clean($record->id,'');

        self::_touchRecord($data, $fields, $categories, $tags);
    }

2) Unfortunately the value to be updated is not part of the $table->store_value(), therfore it will never create a record_values with the updated value.


Sergey
Total posts: 13,748
09 Июль 2017 06:23

Added changes

Sackgesicht 2) Unfortunately the value to be updated is not part of the $table->store_value(), therfore it will never create a record_values with the updated value.

Cannot get this? What means "is not a part"?


Sackgesicht VIP
Total posts: 1,636
09 Июль 2017 08:02

on update it does not use the changed/updated values from $fields. It still uses the $Form_fields, which is the old not updated value.

Just try, if it updates the old record.

Did you change something in addition to the $table = JTable::getInstance('Record_values', 'CobaltTable'); $table->clean($record->id,'');


Sackgesicht VIP
Total posts: 1,636
24 Июль 2017 11:46

Any news on this topic?


Sergey
Total posts: 13,748
26 Июль 2017 04:12

Yes. I've revised this API and changed it. I also added touchRecord() method with detect if record exists or not and update it or create.

I'll upload updates later today.


Sackgesicht VIP
Total posts: 1,636
26 Июль 2017 04:35

Great. I will check and report back after downloading ...


danielbidala VIP
Total posts: 153
26 Авг 2017 20:16

I want to update only one field of the record. Now it updates the field what I want but all other field values are cleared. Is it normal?

And the previous entry for that field is not deleted from res_record_values table just a new one is created.


Sergey
Total posts: 13,748
29 Авг 2017 11:23

danielbidala I want to update only one field of the record. Now it updates the field what I want but all other field values are cleared. Is it normal?

And the previous entry for that field is not deleted from res_record_values table just a new one is created.

Should be fixed in next update.


danielbidala VIP
Total posts: 153
29 Авг 2017 11:36

Thanks for it in advance. Can you tell us when will it be available? I'm in a project with deadline. I'dont know if I wait for update or write SQL queries in my plugin.


Sergey
Total posts: 13,748
22 Сен 2017 10:59

I'll update new Cobalt today.

Работает на Cobalt