Sackgesicht VIP
Total posts: 1,636
04 Май 2016 01:21

What is the best practice/most efficient way to

  1. update an existing record
  2. create a new record

with a script to comply with all SECTION and TYPE settings (like version control/audit trail setting)? I presume there are helpers, functions, methods available to make it easier than doing every single step manually.

Are there code snippets available?

Последние изменения: 10 Май 2016


Sergey
Total posts: 13,748
05 Май 2016 16:15

For creating a new record, there is no code snippet. this is very complex process. You can see for example postSaveHook in components/com_cobalt/controllers/form.php. This is only post save code 400 lines. And there are much more in the other places.

For updating a record, I have code snippet to update field values. Replace them from one value to another.

http://docs.mintjoomla.com/en/cobalt/change-field


Sackgesicht VIP
Total posts: 1,636
06 Май 2016 05:14

Sergey For creating a new record, there is no code snippet.

I was thinking of an API call which has all needed info in the parameters. Something like:

createRecord($section_id, $type_id, $categories, $fields, $options)

$options will be optional parameter to influnce record columns like meta_descr, meta_key, published, user_id etc ...

this function will do following steps:

1) loop over $categories to verify existence, create the #__js_res_record record and get back the new record_id

2) check for audit trail setting and add if necessary the log entry (add record)

3) create the #__js_res_record_category based on verified $categories

4) loop through fields from $fields to verify existence of fields, get searchable parameter and store $fields (loop through field values) in #__js_res_record_values

5) update the newly created #__js_res_record if searchable exist (reindex)

Sergey For updating a record, I have code snippet to update field values. Replace them from one value to another.

http://docs.mintjoomla.com/en/cobalt/change-field

The main problem i see here is with the fields storing more records (like geo, uploads etc), other than that updating should be similar, even easier than adding a new record:

updateRecord($record_id, $fields, $categories, $options)

$categories and $options are optional.

1) $record = ItemsStore::getRecord($recordId);

2) Update fields .. like Step 4 of new record and if needed update categories and options ... 3) add log entry if needed

4) save record and reindex if needed

Creating and updating records should be essential API functions. Maybe you can think of an easy implementation, you know the steps better than anyone else.


Sergey
Total posts: 13,748
10 Май 2016 07:27

I know. You are not the one who asks this functianlity. there are people who want to make import from different feeds to Cobalt and other things. All of them need createRecord API. I'll see what I can do.


Sergey
Total posts: 13,748
10 Май 2016 09:24

I have added API to create new record and update records.

I also have added docs for that http://docs.mintjoomla.com/en/cobalt/api-reference


Sackgesicht VIP
Total posts: 1,636
10 Май 2016 09:39

How to determine if new record or update? If $data has a record_id then it will update, if none, then new record ....?


Sackgesicht VIP
Total posts: 1,636
10 Май 2016 10:04

If updating a field, how will it handle existing data? Example: the field is an upload field and it has already 5 uploaded files. The $data only has the new document for upload. Will it add the document to the list or will it overrite the existing documents?

It applies for any field which stores the value in an array.


Sergey
Total posts: 13,748
10 Май 2016 11:07

Sackgesicht How to determine if new record or update? If $data has a record_id then it will update, if none, then new record ....?

I have updated documentation. there will be 2 different methods.

Sackgesicht f updating a field, how will it handle existing data? Example: the field is an upload field and it has already 5 uploaded files. The $data only has the new document for upload. Will it add the document to the list or will it overrite the existing documents?

Most probably it will override. But I did dnot test it.

Sackgesicht It applies for any field which stores the value in an array.

It does not matter. You can actualy feed any field posible for Cobalt. You only have to know format. To know format of the fields very simple thing is to make var_dump($_POST['jform']['fields']) after article submission form and see how fields pas information.

Работает на Cobalt