I'm working on a site with usasearch and usasearch_api modules enabled. Everything appears to be functioning correctly - new nodes that are created as published are indexed, nodes that are created as unpublished and then later published are indexed on cron, updated nodes are updated in the index correctly.

The issue is that whenever a published node is updated, and it is not changing from unpublished to published in the update, usasearch_api errors appear in watchdog. I've narrowed down the cause to code in usasearch_api.module:

 18 /**
 19  * Implements hook_node_update().
 20  */
 21 function usasearch_api_node_update($node) {
 22   //  Delete from index if node has been unpublished
 23   if ($node->status == 0) {
 24     usasearch_api_node_delete($node);
 25     return;
 26   } else {
 27     // attempt insert in case the node is changing from unpublished to published
 28     usasearch_api_node_insert($node);
 29   }
 30   $document = usasearch_api_convert_node_to_document($node);
 31   if ($document) {
 32     usasearch_api_request('put', 'api/v1/documents/' . $document->getDocumentId(), array('json' => $document->json()));
 33   }
 34 }

Specifically, line 28 where it attempts to force an insert in the index without checking if the node status actually changed (and therefore needs to be inserted). So nodes that are already indexed are triggering an error from the API, which is added to watchdog. Line 32 then performs an update request on the index, which works. So functionality isn't affected, but there are unnecessary errors appearing in the logs.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

faerysteel created an issue. See original summary.

lisagodare’s picture

I've attached a patch that looks at $node->original->status and $node->status to determine if an insert is required. It'll insert or update depending on the original status.

lisagodare’s picture

Issue summary: View changes
schiavone’s picture

Looks like this will work. I'll check it out. We're also going to starting logging indexing operations so we'll know whether a node has been pushed to the index.

  • schiavone committed 2687396 on 7.x-5.x authored by faerysteel
    Issue #2745101 by faerysteel: watchdog errors present when updating a...
  • schiavone committed 2ed866d on 7.x-5.x
    Issue #2745101 by schiavone: watchdog errors present when updating a...
schiavone’s picture

Assigned: Unassigned » schiavone
Status: Active » Fixed

Changes from the patch have been incorporated along with index logging so that unnecessary REST calls are not made reducing errors

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.