In the Beta version, I attempted to use Show Diff between two nodes but it resulted in a WSOD.

In the 7.x-2.x version, the Show Diff seems to work, but there are errors reported in the log messages:

  • Notice: Trying to get property of non-object in diff_diffs_show() (line 172 of /sites/all/modules/diff/diff.pages.inc).
  • Warning: date_timezone_set() expects parameter 1 to be DateTime, boolean given in format_date() (line 1938 of /includes/common.inc).
  • Warning: date_format() expects parameter 1 to be DateTime, boolean given in format_date() (line 1948 of /includes/common.inc).
  • Notice: Trying to get property of non-object in diff_diffs_show() (line 172 of /sites/all/modules/diff/diff.pages.inc).
  • Notice: Undefined index: images in diff_diffs_show() (line 173 of /sites/all/modules/diff/diff.pages.inc).
  • Notice: Trying to get property of non-object in diff_diffs_show() (line 177 of /sites/all/modules/diff/diff.pages.inc).
  • Notice: Trying to get property of non-object in node_diff() (line 16 of /sites/all/modules/diff/includes/node.inc).
  • Notice: Trying to get property of non-object in node_diff() (line 18 of /sites/all/modules/diff/includes/node.inc).
  • Notice: Undefined index: field_name in node_diff() (line 29 of /sites/all/modules/diff/includes/node.inc).
  • EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7539 of /includes/common.inc).

I'm not sure why $new_node->revision_timestamp; results in a Notice: Trying to get property of non-object.
$old_node->revision_timestamp works fine, as does $node->revision_timestamp. $node->revision_timestamp matches $new_node->revision_timestamp.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mitchell’s picture

Version: 7.x-2.x-dev » 7.x-3.0-alpha1
Status: Active » Fixed

7.x-3.x introduced support for diffs between different nodes. Please reopen if problem persists in 7.x-3.x branch.

Alan D.’s picture

Status: Fixed » Postponed (maintainer needs more info)

No direct comparison was included. Can you let me know how you were doing this please?

It may point to an unknown bug within the code although at this stage I think it is a GIGO bug...

mitchell’s picture

Title: Revisions Page Show Diff » Diff between two different entities
Alex Andrascu’s picture

Interested in this one aswell. Can you please provide an example of how to diff between 2 entities.
Thanks.

Alan D.’s picture

Category: bug » task
Status: Postponed (maintainer needs more info) » Needs review
FileSize
5.39 KB

I am writing a administrative logging module and I'm needing entity diff's for the logs too.

This first patch abstracts out the logic from _diff_body_rows() into diff_entity_body_rows(). This has most of the logic for the UI and internally calls diff_compare_entities() for the actual comparison. This function does not cover the header row.

I'm using a custom CTool plugin that calls this to render the diff as a string for insertion into the log.

class EntityCRUDLogOperation extends LogOperation {
  function logUpdate($entity_type, $entity) {
    $original = empty($entity->original) || !is_object($entity->original) ? entity_load_unchanged($entity_type, $entity) : $entity->original;
    $diff_html = $this->diffEntity($entity_type, $original, $entity);
  }

  function diffEntity($entity_type, $entity_one, $entity_two) {
    if (!module_exists('diff')) {
      return '';
    }

    switch ($entity_type) {
      case 'node':
        $old_header = t('<strong>@title</strong><br />!date by !username', array(
          '@title' => $entity_one->title,
          '!date' => l(format_date($entity_one->created), "node/$entity_one->nid"),
          '!username' => theme('username', array('account' => user_load($entity_one->uid))),
        ));
        $new_header = t('<strong>@title</strong><br />!date by !username', array(
          '@title' => $entity_two->title,
          '!date' => l(format_date($entity_two->created), "node/$entity_two->nid"),
          '!username' => theme('username', array('account' => user_load($entity_two->uid))),
        ));
        break;

      default:
        $old_header = '<strong>' . entity_label($entity_type, $entity_one) . '</strong>';
        $new_header = '<strong>' . entity_label($entity_type, $entity_two) . '</strong>';
        break;
    }

    module_load_include('pages.inc', 'diff');
    $header = _diff_default_header($old_header, $new_header);
    $rows = diff_entity_body_rows($entity_type, $entity_one, $entity_two);

    $build['diff_table'] = array(
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $rows,
      '#attributes' => array('class' => array('diff')),
      '#colgroups' => _diff_default_cols(),
      '#sticky' => FALSE,
    );

    return drupal_render($build);
  }
}
Alan D.’s picture

A smaller example for user entities (should work without #2110371: Providing User entity support) but requires the above patch.

$account_a = user_load(1);
$account_b = user_load(5);
module_load_include('pages.inc', 'diff');
$header = _diff_default_header(entity_label('user', $account_a), entity_label('user', $account_b));
$rows = diff_entity_body_rows('user', $account_a, $account_b);

$build['diff_table'] = array(
  '#theme' => 'table',
  '#header' => $header,
  '#rows' => $rows,
  '#attributes' => array('class' => array('diff')),
  '#colgroups' => _diff_default_cols(),
  '#sticky' => FALSE,
);

print drupal_render($build['diff_table']);
Alan D.’s picture

Status: Needs review » Fixed

Added in cdee341

Status: Fixed » Closed (fixed)

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