You are here

function node_gallery_image_save in Node Gallery 6.2

1 call to node_gallery_image_save()
image_upload_process in ./node_gallery.module
We can't put this function to node_gallery.pages.inc because the batch was started after reboot.

File

./node_gallery.inc, line 230
Node gallery models

Code

function node_gallery_image_save($image_node) {
  module_load_include('inc', 'node', 'node.pages');
  node_object_prepare($image_node);
  $form_state['values'] = (array) $image_node;

  //orignal form;
  $form = drupal_retrieve_form($image_node->type . '_node_form', $form_state, $image_node);

  //form's hook #submit and form_alter;
  drupal_prepare_form($image_node->type, $form, $form_state);
  node_form_submit($form, $form_state);
  $image_node->nid = $image_node->nid = $form_state['nid'];
  file_set_status($image_node, FILE_STATUS_PERMANENT);
  if ($image_node->gid && $image_node->nid) {

    //remove the currently cover flag;
    if ($image_node->is_cover) {
      db_query("UPDATE {node_galleries} SET is_cover = 0 WHERE gid = %d", $image_node->gid);
    }

    //update
    if (db_result(db_query("SELECT nid FROM {node_galleries} WHERE nid = %d", $image_node->nid))) {
      drupal_write_record('node_galleries', $image_node, 'nid');
    }
    else {
      drupal_write_record('node_galleries', $image_node);
    }
  }
}