hi,
i am experiencing the following problems with simplenews-5.x-1.5 on drupal 5.16:

- when i create a new newsletter named 'NEWSLETTER', it is showing up in the list on ?q=admin/content/newsletters/types. i get the drupal_message 'Created new term NEWSLETTER.'
- when i hit the 'edit newsletter'-link (?q=admin/content/newsletters/types/edit/748) i get a drupal 404
- the database table simplenews_newsletters is still empty
- i cannot select the newsletter when setting up a new 'newsletter issue', new issues are shown as orphaned on ?q=admin/content/newsletters/notsent
- when i went checking inside the module's code, i found that function simplenews_insert() (as defined in line 408 in simplenews.module) is NOT called when a new newsletter or newsletter issue is created. i patched the module by changing the query row 416 by

$result = db_query("INSERT INTO {simplenews_newsletters} (nid, vid, tid, s_status, s_format, priority, receipt)
		  VALUES (%d, %d, %d, %d, '%s', %d, %d)", $node->nid, $node->vid, $node->simplenews_tid, $s_status, $node->s_format, $node->priority, $node->receipt);
  if ($result) {
    drupal_set_message(t('Newsletter %title was successfully added.', array('%title' => $node->title)));
  }

to get ANY reaction, but no. unfortunately i couldnt find out where this function actually is called, as it is not called inside simplenews.module

i have taxonomy module enabled and i do not use any of the modules with known incompatabilities (e.g. categories).

any ideas?

thank you in advance!

CommentFileSizeAuthor
#5 screen_nl.jpg59.54 KBmybinaryromance

Comments

sutharsan’s picture

Status: Active » Postponed (maintainer needs more info)

This does not ring a bell. You need to debug the code more to find out why the newsletter record is not saved. Do you use any taxonomy access control?

mybinaryromance’s picture

no, i dont use any taxonomy access control.

can you explain in a few words how simplenews is hooked into the taxonomy system? i am asking because the title i choose for a newsletter is saved as a taxonomy term in term_data but is not assigned to any vocabulary (vid in database is 0). as far as i can see the title is not saved anywhere else.

another thing i wonder about is the function simplenews_insert(). it is defined in line 408 in simplenews.module, but it NEVER gets called...

mybinaryromance’s picture

Status: Postponed (maintainer needs more info) » Active

i uninstalled and re-installed the module, with the effect that now i have a vocabulary named Newsletter in my taxonomy system which wasn't there before.

When i set up a new newsletter, the title still gets saved as a term but is not assigned to any vocabulary. the vid is still 0. the tid in term_data is 751 , and the edit-newsletter-link points to ?q=admin/content/newsletters/types/edit/751, which looks pretty okay to me, still the edit-link leads to a 404 error.

sutharsan’s picture

If the term is not assigned to a vocabulary then you have found the reason for the 404 error. But it is strange that the terms are not assigned to a vocab. At installation the vocabulary is created and further used to assign the terms to. You find this vocab on the simplenews general settings page. It is stored in the simplenews_vid variable.

mybinaryromance’s picture

StatusFileSize
new59.54 KB

hm.
the general settings page is ?q=admin/content/newsletters/settings ? i am asking because i don't see anything about vocabularies there... please check the screenshot attached.

mybinaryromance’s picture

another thing i tried is this:

the vocabulary added automatically is called 'newsletter', with the vid 30. so i went into the db and changed the vid (which was 0) of the term used for the newsletter title (tid 751) to the vid 30. what happens is:
- there are no newsletters available anymore (in ?q=admin/content/newsletters/settings)
- ?q=admin/content/taxonomy/30 contains one term, tid 751.

this leads me to the conclusion that the simplenews_vid variable you mentioned in #4 must definitely be causing the error. but where can i see what value is now set as simplenews_vid?
the variables table shows values for :
simplenews_time, simplenews_throttle, simplenews_test_address_override, simplenews_test_address simplenews_sync_account, simplenews_send, simplenews_receipt, simplenews_priority, simplenews_from_name, simplenews_from_address, simplenews_format, simplenews_debug. simplenews_vid is not set.

simplenews_vid is SUPPOSED to be set in in simplenews.install, lines 113 ff:

else {
    // Create the simplenews vocabulary if it does not exist.
    $vocabulary = array(
      'name' => t('Newsletter'),
      'multiple' => '0',
      'required' => '0',
      'hierarchy' => '0',
      'relations' => '0',
      'module' => 'simplenews',
      'nodes' => array('simplenews' => 1)
    );
    taxonomy_save_vocabulary($vocabulary);
    variable_set('simplenews_vid', $vocabulary['vid']); // <- ??? $vocabulary['vid'] has not been defined up to here... or am i missing something?
  }

at this point i am absolutely willing to add the variable manually to the database to get things up and running. can you please provide an example of how the db-field 'value' in the 'variable' table should look like (for vid 30)?

thanks a lot!

sutharsan’s picture

Sorry, the situation I described is for simplenews 6.x.

mybinaryromance’s picture

okay, my post #6 led me to this:

i just called variable_set('simplenews_vid', 30); in a drupal node with php input format

database now shows the variable simplenews_vid i:30;

everything seems to work :-)

sutharsan’s picture

bonzo meier, can you find out what caused this problem? For now I do not see what bug this is.

mybinaryromance’s picture

i am not so sure, either. what i found is what i posted above (#6): during setup (in simplenews.install, lines 113 ff), the array $vocabulary is defined, then you go taxonomy_save_vocabulary($vocabulary) (which is just fine and obviously working) and after that variable_set('simplenews_vid', $vocabulary['vid']); (which is obviously NOT working).

as far as i can see, the $vocabulary['vid'] as called in variable_set() must be empty at this stage, for taxonomy_save_vocabulary() will not return any vid.

this would be a suitable explanation for my problem as described above.

a solution would be to replace the above code (#6) with

else {
    // Create the simplenews vocabulary if it does not exist.
    $vocabulary = array(
      'name' => t('Newsletter'),
      'multiple' => '0',
      'required' => '0',
      'hierarchy' => '0',
      'relations' => '0',
      'module' => 'simplenews',
      'nodes' => array('simplenews' => 1)
    );
    taxonomy_save_vocabulary($vocabulary);
    //reload the relevant vocabularies to get the new vid
    $new_vocabularies = taxonomy_get_vocabularies($type = 'simplenews');
    //vid's are auto-incremented, so the newly set vid must be the largest index here:
    $new_vid = max(array_keys($new_vocabularies));
    variable_set('simplenews_vid', $new_vid);
  }

i am not sure is this is the complete solution, but it will get the right simplenews_vid set during install.

sutharsan’s picture

If your theory is right, every new simplenews install would fail. But it doesn't, I just tried the latest 5.x-1.x-dev release and it works. You can also check the taxonomy_save_vocabulary documentation. The function parameter is by reference and 'vid' is set somewhere halfway the code. So, it must be a system dependent problem.

mybinaryromance’s picture

hi sutharsan,

well i checked the taxonomy_save_vocabulary() before, actually that's what led me to the approach above. this function only returns a status (which in this case is 'SAVED_NEW'), but nothing else.

anyway, when i perform

<?php 
$vocabulary = array(
      'name' => t('Check'),
      'multiple' => '0',
      'required' => '0',
      'hierarchy' => '0',
      'relations' => '0',
      'module' => 'simplenews',
      'nodes' => array('simplenews' => 1)
    );
    taxonomy_save_vocabulary($vocabulary);
    print $vocabulary['vid'];
?>

in a drupal php-node, i get '31' printed out, which proofs that your original code is definitely correct and working - i don't really see why, maybe module_invoke_all() inside taxonomy_save_vocabulary() does the trick or it's pure voodoo :-)

so, as a conclusion: the error described in this thread is NOT inside the module's code but somewhere else in my individual drupal setup. anyway, i got around it by re-setting the simplenews_vid as described in #6.

sutharsan’s picture

Status: Active » Fixed

The function parameter is used by reference. Not the value of $vocabulary is passed to taxonomy_save_vocabulary() but a pointer to the variable. See 'Pass by Reference' in http://www.php.net/manual/en/language.references.whatdo.php for explanation of this voodoo

Status: Fixed » Closed (fixed)

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