1

Topic: Unexpected behaviour of Edit link in data entry form

Hi

I've recently set up a new website based on Instant Indicia 0.8.2 and my own Warehouse installation upgraded to 0.8.1. I built a data entry form based on "General Purpose Data Entry Forms > Sample with occurrences form".  Under "User Interface > Grid Report" the default " reports_for_prebuilt_forms/dynamic_sample_occurrence_samples" seems to have been removed so I used "reports_for_prebuilt_forms/simple_occurrence_list_1" instead. I find that if I click on the "Edit" link against a row in the grid, rather than being taken to a form where I can edit and existing record, I'm taken to the for entering a new record.

Incidentally, I tried downloading dynamic_sample_occurrence_samples.xml from subversion but this appears to have an SQL error in it.

Cheers

Alan

Alan Hale
Aberystwyth

2

Re: Unexpected behaviour of Edit link in data entry form

Hi Alan

Rather than look too deeply in to this, my recommendation is that you first upgrade your warehouse by downloading the code from branch 0.8.2 of the repository.

Development is galloping away ahead of the release cycle. Instant Indicia 0.8.2 came out recently to allow new features to be used but they may be dependent on changes to the warehouse since 0.8.1 was released.

Jim Bacon

3

Re: Unexpected behaviour of Edit link in data entry form

Thanks Jim - will do, and report back.

Alan Hale
Aberystwyth

4

Re: Unexpected behaviour of Edit link in data entry form

Mmm - just overwrote my warehouse installation with 0.8.2 from repository. I don't see the notification or the button to upgrade the database.

Alan Hale
Aberystwyth

5

Re: Unexpected behaviour of Edit link in data entry form

Hi Alan

I reckon that is because the version has not been changed in the version config file

You can make the update run simply by visiting index.php/home/upgrade  - but this may not run the 0.8.2 updates unless you first correct the version number in version.php

You certainly need to run the updates and well done for noticing. I think that is enough information for you to fix it. You can look in the database to confirm the updates have happened.

Please let us know if your original problem is resolved because I know of one other person with warehouse 0.8.1 and Instant Indicia 0.8.2.

Jim Bacon.

6

Re: Unexpected behaviour of Edit link in data entry form

Spot-on Jim. I corrected the version number and the upgrade prompt and button appeared.

However, the upgrade failed:

There was an SQL error: ERROR: relation "cache_taxon_searchterms" does not exist - ALTER TABLE cache_taxon_searchterms ADD CONSTRAINT fk_taxon_searchterms_taxon_list FOREIGN KEY (taxon_list_id) REFERENCES taxon_lists (id) ON UPDATE NO ACTION ON DELETE NO ACTION; CREATE INDEX fki_taxon_searchterms_taxon_list ON cache_taxon_searchterms(taxon_list_id)

Alan Hale
Aberystwyth

7

Re: Unexpected behaviour of Edit link in data entry form

Hi Alan.

The error is telling us the cache_taxon_searchterms table is missing.

This is created by the update in modules/cache_builder/db/version_0_1_1/201205201737_searchterms.sql

The update that failed (modules/indicia_setup/db/version_0_8_2/201301101936_cache_taxon_searchterms_taxon_list_index.sql) has been filed in the wrong place and should not have run without  the preceeding update having been run first. Please move that file to modules/cache_builder/db/version_0_1_2. I will update the repository.

You should now be able to go to index.php/home/upgrade and the updates should complete successfully.

Does this mean that you do not have the cache_builder module enabled in application/config/config.php? Entirely possible since you are upgrading from a warehouse that might predate the cache_builder. This may explain some of the problems that you began this thread with. Many of the newer reports depend upon the cache tables.

To enable it you need the $config['modules'] array to include a value of MODPATH.'cache_builder' as shown in config.php.example

I would be inclined to visit  index.php/home/upgrade again after enabling the module because I am not sure if enabling the module is sufficient to cause it to execute the database updates.

Jim Bacon

8

Re: Unexpected behaviour of Edit link in data entry form

Ah, thanks Jim.  I've been meaning to ask about cache_builder.

So:

I moved 201301101936_cache_taxon_searchterms_taxon_list_index.sql as you suggested and ran upgrade again and all went fine.

I then enabled cache_builder in config.php and ran the upgrade again. Also fine. (I noted in pgAdminIII that the cache tables were built).

Then reading in the documentation that I needed to run scheduled_tasks to populate the cache tables, I did so. Most of the table updates proceeded OK, but there was one error:

There was an SQL error: ERROR: column "searchterm_length" of relation "cache_taxon_searchterms" does not exist at character 824 - update cache_taxon_searchterms cts set taxa_taxon_list_id=cttl.id, taxon_list_id=cttl.taxon_list_id, searchterm=cttl.taxon, original=cttl.taxon, taxon_group_id=cttl.taxon_group_id, taxon_group=cttl.taxon_group, taxon_meaning_id=cttl.taxon_meaning_id, preferred_taxon=cttl.preferred_taxon, default_common_name=cttl.default_common_name, preferred_authority=cttl.preferred_authority, language_iso=cttl.language_iso, name_type=case when cttl.language_iso='lat' and cttl.preferred_taxa_taxon_list_id=cttl.id then 'L' when cttl.language_iso='lat' and cttl.preferred_taxa_taxon_list_id<>cttl.id then 'S' else 'V' end, simplified=false, code_type_id=null, source_id=null, preferred=cttl.preferred, searchterm_length=length(cttl.taxon), parent_id=cttl.parent_id, preferred_taxa_taxon_list_id=cttl.preferred_taxa_taxon_list_id from cache_taxa_taxon_lists cttl join needs_update_taxon_searchterms nuts on nuts.id=cttl.id where cts.taxa_taxon_list_id=cttl.id and cts.name_type in ('L','S','V') and cts.simplified=false

Cheers

Alan

Alan Hale
Aberystwyth

9

Re: Unexpected behaviour of Edit link in data entry form

Hi Alan

It seems that two updates were not copied from the trunk to the 0.8.2 branch. (We do development in the trunk and when a bug is fixed or some new feature is required which cannot wait to the next release, then it is copied to the branch.)

You need to download 20121113_taxon_searchterms_searchterm_length.sql and 201211271906_cache_ttl_sort_order_size.sql

Since these predate the updates that you have already applied, I wouldn't expect them to execute if you visit index.php/home/upgrade. Therefore you need to apply them manually by executing them in pgAdmin.

Sorry for the inconvenience. I think you must be the first person to be following this path.

Jim Bacon.

10

Re: Unexpected behaviour of Edit link in data entry form

Hi Jim

Thanks very much for that. No need to apologise for inconvenience - it's  all a learning experience.

Cheers

Alan

Alan Hale
Aberystwyth

11

Re: Unexpected behaviour of Edit link in data entry form

Good - that's all gone OK and scheduled_tasks now runs without problem. Many thanks Jim.

Alan Hale
Aberystwyth

12

Re: Unexpected behaviour of Edit link in data entry form

That is good, but all a preamble to addressing the original problem. How now?

Jim Bacon.

13

Re: Unexpected behaviour of Edit link in data entry form

Ah yes, nearly forgot. The original problem remains I'm afraid.

Alan

Alan Hale
Aberystwyth

14

Re: Unexpected behaviour of Edit link in data entry form

Right then, back to the begining. But we are now in the happy position that I should be able to replicate your problems as we are now running similar systems.

First of all, the missing form, reports_for_prebuilt_forms/dynamic_sample_occurrence_samples. This hasn't been removed but is absent from your system as it and the the Sample With Occurrence form were part of the development trunk and would have come together in a 0.9.0 release. This thing called Instant Indicia 0.8.2 might also be called a beta release of 0.9.0. Perhaps I better copy that report in to the 0.8.2 branch of the warehouse so that  there is compatibility between these two things labelled 0.8.2.

You did download this report but say there is an SQL error in it. I would hazard a guess that this relates to identifying the user for whom the report should list records as this is the only complicated bit of the thing. If there is no helpful error message I would be setting the warehouse log level to debug and looking to see what query is being attempted and what parameters it has been supplied with.

With regard to the edit link not working, this is a consequence of a bug introduced in r5205 and fixed a couple of days later in r5234. If you patch data_entry_helper.php you will make some headway although I am seeing another problem on my test system.

Jim Bacon

15 (edited by Alan Hale 08-03-2013 15:34:34)

Re: Unexpected behaviour of Edit link in data entry form

Hi Jim

OK, I've checkedout "dynamic_sample_occurrence_samples.xml" from the 0.8.2 branch (it looks as though you might have updated this earlier today). The SQL error I get when loading my data entry form is this:

There was an SQL error: ERROR: syntax error at or near ">" at character 891 - select s.id as sample_id, COALESCE(l.name, s.location_name) as location_name, s.entered_sref, s.date_start, s.date_end, s.date_type, ( select count(*) from occurrences o where o.sample_id = s.id and o.deleted = FALSE) as num_occurrences, ( select (count(*) > 0) from occurrences o where o.sample_id = s.id and o.deleted = FALSE and o.record_status = 'C') as completed from samples s LEFT JOIN locations l ON l.id=s.location_id WHERE s.survey_id=7 AND s.deleted = FALSE AND ((0 > 0 AND EXISTS ( select id from sample_attribute_values sav WHERE sav.sample_id = s.id AND sav.sample_attribute_id = 0 AND sav.int_value = 0)) OR (0 = -1 AND NOT EXISTS ( select id from sample_attribute_values sav WHERE sav.sample_id = s.id AND sav.sample_attribute_id = 0)) OR ( > 0 AND s.created_by_id = )) ORDER BY s.id DESC LIMIT 11

Looking at the xml it looks as though userid is assigned  0 and maybe the problem is the consequent attempt in the SQL to evaluate "0 > 0". That's my initial guess.

Alan

Alan Hale
Aberystwyth

16

Re: Unexpected behaviour of Edit link in data entry form

Hi Alan

The SQL error is a bit further down in the  ( > 0 AND s.created_by_id = ) filter. This is caused by a bug that is already fixed in the trunk.

To patch your copy of client_helpers/prebuilt_forms/dynamic_sample_occurrence.php (probably in sites/all/libraries/iform) locate the function getSampleListGrid and, around line 1296, change

if (isset($iUserId)) $filter = array (

to

if ($iUserId !== false) $filter = array (

I think that should do the trick although I confess to answering your question by inspection without actually trying it.

Also, I hope you understood from my last email that you need to modify your data_entry_helper.php by copying the changes made in r5234 which is done most easily by looking at the diff. You need to ammend your code with the green higlighted changes in the right hand listing in the region of line 4000.

Jim Bacon.

17

Re: Unexpected behaviour of Edit link in data entry form

Hi Jim

I've made the changes you suggest in both "dynamic_sample_occurrence.php" and  "data_entry_helper.php" but the same SQL error is still reported. (I have cleared caches).

Alan

Alan Hale
Aberystwyth

18

Re: Unexpected behaviour of Edit link in data entry form

Hi Alan

Just a quick thought. You probably have the client helpers installed in two places, one copy with your warehouse and one copy with your Instant Indicia. You are making the changes in the Instant Indicia copy aren't you? And also, in Drupal, the client_helpers could be in sites/all/modules/iform or sites/all/libraries/iform. Can you just check they only exist in the one place.

I was just going to paste what your patched getSampleListGrid function should look like and spotted another bug, also already fixed in the trunk. So what I am going to do is paste in the relevant bit of code from the trunk.

    // Get the CMS User ID attribute so we can filter the grid to this user
    foreach($attributes as $attrId => $attr) {
      if (strcasecmp($attr['caption'],'CMS User ID')==0) {
        $filter = array (
          'survey_id' => $args['survey_id'],
          'userID_attr_id' => $attr['attributeId'],
          'userID' => $user->uid,
          'iUserID' => 0);
        break;
      }
    }
    // Alternatively get the Indicia User ID and use that instead
    if (function_exists('hostsite_get_user_field')) {
      $iUserId = hostsite_get_user_field('indicia_user_id');
      if (isset($iUserId) && $iUserId!=false) $filter = array (
          'survey_id'=>$args['survey_id'],
          'userID_attr_id' => 0,
          'userID' => 0,
          'iUserID' => $iUserId);
    }

I hope it is clear to you the lines that need replacing with the above.

What this code is doing is finding the parameters to pass to the report. The first half gets the parameters that are relevant if you identify the recorder by saving their CMS User ID as a sample attribute, the second half is the alternative if you are using the EasyLogin module (which I assume you have not enabled).

Jim Bacon.

19

Re: Unexpected behaviour of Edit link in data entry form

Hi Jim

Yes, I clocked that potential pitfall but figured you meant for me to update the Instant Indicia versions, which is what I did.

Glad to say that your latest code modification has done the trick, in that the SQL error message has disappeared and I now get instead this message:

This form is configured to show the user a grid of their existing records which they can add to or edit. To do this, the form requires that either it must be used with a survey that includes the CMS User ID attribute in the list of attributes configured for the survey on the warehouse or that a function hostsite_get_user_field exists and returns their Indicia User ID. This allows records to be tagged against the user. Alternatively you can tick the box "Skip initial grid of data" in the "User Interface" section of the Edit page for the form

Now, I have enabled Easy Login but I haven't fully figured out how to configure it. At the moment it is showing status "Overridden". I need to take a look at this and maybe come back with any questions in new topic.

Many thanks for your persistence with this one.

Cheers

Alan

Alan Hale
Aberystwyth

20

Re: Unexpected behaviour of Edit link in data entry form

Ah! We seem to be OK. I've just tried logging out and then back in again and now the grid display appears. Even better - clicking on the Edit links does now take me to the previously entered record.

Phew!

Thanks very much once again Jim.

Alan

Alan Hale
Aberystwyth

21

Re: Unexpected behaviour of Edit link in data entry form

I've been looking at this again and have realised that the "Edit" link actually leads to an edit of the sample, not an occurrence. So if I follow the link, make some changes (or indeed don't make any changes) and click on submit, I'm actually creating a new occurrence within the sample, not editing a previously submitted record/occurrence.

How can I set up a form for editing and re-saving and occurrence?

(What I really want is to set up a link from a "record details" page which will allow me to edit the record I'm looking at).

Cheers

Alan

Alan Hale
Aberystwyth

22

Re: Unexpected behaviour of Edit link in data entry form

Hi Alan

Do your edit links point to the same form that you have used for the original data entry?

That is the way I have always used it so that it loads with the entered data, both sample and occurrences. It won't create new occurrences unless I add them in the form.

Adding an edit link from the "record details" page should not be hard - just needs a little PHP to concatenate the url of your data entry form with a query string that contains the occurrence_id which can be got from $_GET["occurrence_id"]. Just a question of whether you where to put that bit of code.

The programmers way would be to create a new prebuilt form that subclasses the one you currently use. A less daunting approach might be to enable the PHP input filter in Drupal and put the code in the "Page Introductory Text".

Jim.

23

Re: Unexpected behaviour of Edit link in data entry form

Hi Jim

Yes, the edit links point back to the original data entry form (it's one of the pre-built forms).

It doesn't seem to work in the way I would expect. For example, say I realise I have entered the grid-reference wrongly and I want to change it.  I click on Edit and get the form for original record up. If I change the grid-reference and then Submit the grid -reference is changed, but I end up with an additional occurrence. Same if I want to add a comment to the original record.

Cheers

Alan

Alan Hale
Aberystwyth

24

Re: Unexpected behaviour of Edit link in data entry form

Hi Alan

Are you using the "sample with occurrences form"?
What did you select as the method for entering species, single occurrence or multiple occurrences using a checklist?

Jim.

25

Re: Unexpected behaviour of Edit link in data entry form

Hi Jim

Yes, that's right.

I selected single occurrence (for this project I'm only interested in one species).

Cheers

Alan

Alan Hale
Aberystwyth