// Update scheduler record.
  $query = db_merge('simplenews_scheduler');
  $query->key(array(
      'nid' => $nid,
    ))
    ->fields($record)
    ->execute();

  if (!$query) {
    drupal_set_message(t('Saving or updating schedule settings for <em>@title</em> has been unsuccessful.', array(
        '@title' => $node->title,
      )), 'error');
  }
  else {
    drupal_set_message(t('Newsletter Schedule preferences have been saved.'));
  }

If I'm reading this correctly, then we'll never fail the if(). $query will always be a query object. What we seem to be trying to do here is check what execute() returns -- which appears not to be documented, see #1479220: Add return documentation for Merge::execute() -- and show a message based on how the merge query went. But I suspect we'll never see the error message!

(BTW: I think it's much better code style do say if (positive) {} else {}, rather than if (negative) {} else {}, as the latter form makes it potentially quite hard to figure out what the else bit means.)

CommentFileSizeAuthor
#2 remove_db_merge_check.patch862 bytesberdir

Comments

joachim’s picture

Possibly postponed / superseded by #1480328: no node API.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new862 bytes

Yep, that's all unecessary.

db_merge() returns if it was an insert or an update, but that's not relevant. And if it's actually going to fail then it will throw an exception. But that wouldn't be something we could do anything about.

joachim’s picture

Status: Needs review » Fixed

Committed. Thanks!

- #1479226 by Berdir: Fixed incorrect checking of return from db_merge().

Status: Fixed » Closed (fixed)

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