I noticed that in the drafts table, the drafts keep creating over and over, never reusing the same ID. The problem relies in two parts:
- I have the devel module activated, and it sometimes uses the register_shutdown function. So, AFTER a die() it will append some garbage (its statistics). It will break the module ajax handler
- the eval in the ajax callback is wrong; it should read eval(result.responseText); not eval(result); (or use the jQuery helpers for that)

Here is the code to add to the module, just at the beginning of the draft_save():

  $GLOBALS['devel_shutdown'] = FALSE;

I'll check if the devel module has a way to not bad interact with ajax requests.

Comments

darren.ferguson’s picture

Status: Active » Fixed

Claudio, yes i never use the devel module, hence that could be the reason.

I will append that patch to the draft save module now and put it in the contributions.

/**
 * Ajax handler to save the draft into the system
 */
function draft_save() {
  global $user;
  $output = '';
  // added per Flexer (Claudio)'s suggestion so the Devel module will not break the draft id being returned
  $GLOBALS['devel_shutdown'] = FALSE;
  // getting the type of node we need
  $type = $_POST['node_type'];
  unset($_POST['node_type']);
  $draft_id = $_POST['draft_id'];
  unset($_POST['draft_id']);

  // data coming in via HTTP POST and we are serializing it
  $data = serialize($_POST);

  if (is_numeric($draft_id)) {
    db_query("UPDATE {drafts} SET data = '%s', updated = %d WHERE draft_id = %d", $data, time(), $draft_id);
  }
  else {
    db_query("INSERT INTO {drafts} (node_type, uid, updated, data) VALUES ('%s', %d, %d, '%s')", $type, $user->uid, time(), $data);
    $draft_id = db_last_insert_id('drafts', 'draft_id');
  }
  // if the draft id is set we will update the form hidden field with it so we know which form draft is being saved
  die($draft_id);
}


Have added at the begining of the module and put in reference what you told me. It will be in the nightly build tonight.

Respectfully,
Darren Ferguson

darren.ferguson’s picture

Status: Fixed » Closed (fixed)

Patch has been applied to the module and i have put in the reference to this issue in the cvs commit message.

Respectfully,
Darren Ferguson