1

Topic: Update an entry

Hi,

when I try to update an entry (sample in this case), I send a submission including "updated_by_id", but when I read the updated sample there is still the old value for updated_by, the updated_on value is set correct.

I use Indicia 0.8.1b.

The submission:

submission: {
   "id": "sample",
   "fields": {
      "smpAttr:23": {"value": "20"},
      "id": {"value": "129512"},
      "entered_sref_system": {"value": "258337"},
      "updated_by_id": {"value": "8"},
      "created_by_id": {"value": "8"},
      "geom": {"value": "0106000..."},
      "date": {"value": "2003-04-17"},
      "record_status": {"value": "C"},
      "survey_id": {"value": "6"},
      "date_type": {"value": "D"},
      "entered_sref": {"value": "3387176.4765820922, 5852800.5869723605"},
      "website_id": {"value": "2"}
   }
}

Regards Daniel

P.S.: Is this forum the right place to report bugs? Because I have on in the bugtacker which seems to be not seen?

2

Re: Update an entry

Hi Daniel
The easiest solution is to edit the public function called validate, in My_ORM.php, and move the line $this->set_metadata(); above the loop which goes through $fields_to_copy. I.e. the top of the function can now look like this:

public function validate(Validation $array, $save = FALSE) {
    // the created_by_id field can be specified by web service calls if the caller knows which Indicia user
    // is making the post.
    $fields_to_copy=array_merge(array('created_by_id'), $this->unvalidatedFields);
    $this->set_metadata();
    foreach ($fields_to_copy as $a)
    {
      if (array_key_exists($a, $array->as_array())) {
        // When a field allows nulls, convert empty values to null. Otherwise we end up trying to store '' in non-string
        // fields such as dates.
        if ($array[$a]==='' && isset($this->table_columns[$a]['null']) && $this->table_columns[$a]['null']==1) {
          $array[$a]=null;
        }
        $this->__set($a, $array[$a]);
      }
    }
    try {
      ...

I'll put that in a commit once I've had a chance to ensure that it works OK. Thanks again!

Best wishes
John

John van Breda
Biodiverse IT

3

Re: Update an entry

Hi John,

should it not be:

$fields_to_copy=array_merge(array('created_by_id'), array('updated_by_id'), $this->unvalidatedFields);

At least that is what works for me.

Best wishes

Daniel

4

Re: Update an entry

Hi Daniel,
Sorry, didn't spot this one as the forum notifications seem a bit unreliable. The trunk version of the My_ORM class now contains the possibility to set both created_by_id and updated_by_id (though the solution is slightly different).
Best wishes
John

John van Breda
Biodiverse IT