// 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.)
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | remove_db_merge_check.patch | 862 bytes | berdir |
Comments
Comment #1
joachim commentedPossibly postponed / superseded by #1480328: no node API.
Comment #2
berdirYep, 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.
Comment #3
joachim commentedCommitted. Thanks!
- #1479226 by Berdir: Fixed incorrect checking of return from db_merge().