You are here

function node_gallery_api_items_check_update in Node Gallery 7

Check if we need to update this image.

1 call to node_gallery_api_items_check_update()
node_gallery_api_manage_items_submit in ./node_gallery_api.pages.inc
Submit handler for Manage Items form.

File

./node_gallery_api.inc, line 921
Node Gallery API function

Code

function node_gallery_api_items_check_update($old_image, $_new_image, $compare_fields) {

  // a list of node attributes that are flattened one level by node_save
  $flattened_attributes = array(
    'options',
  );
  $new_image = clone $_new_image;
  $new_image = node_submit($new_image);
  if ($extra = node_invoke($new_image, 'presave')) {
    foreach ($extra as $key => $value) {
      $new_image->{$key} = $value;
    }
  }
  if ($extra = module_invoke_all('node_presave', $new_image)) {
    foreach ($extra as $key => $value) {
      $new_image->{$key} = $value;
    }
  }
  if ($extra = node_invoke($old_image, 'presave')) {
    foreach ($extra as $key => $value) {
      $old_image->{$key} = $value;
    }
  }
  if ($extra = module_invoke_all('node_presave', $old_image)) {
    foreach ($extra as $key => $value) {
      $old_image->{$key} = $value;
    }
  }
  foreach ($compare_fields as $f) {
    if (in_array($f, $flattened_attributes)) {

      // We make the old node look like the new one,
      // ie $old_node->options['status'] = $old_node->status
      foreach (array_keys($new_image->{$f}) as $option) {
        $old_image->{$f}[$option] = $old_image->{$option};
      }
    }

    //a hack for cck field validate;
    if (is_array($new_image->{$f})) {
      foreach ($new_image->{$f} as &$ff) {
        if (is_array($ff)) {
          unset($ff['_error_element']);
        }
      }
    }
    if ($new_image->{$f} != $old_image->{$f}) {
      return TRUE;
    }
  }
  return FALSE;
}