Closed (won't fix)
Project:
Privatemsg
Version:
6.x-2.x-dev
Component:
Code
Priority:
Minor
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
26 Jun 2009 at 04:46 UTC
Updated:
26 Jul 2016 at 14:48 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
berdirThis code should use privatemsg_new_thread(), as relying on the form functions is imho a bad idea.
http://blog.worldempire.ch/api/function/privatemsg_new_thread/1
Comment #2
berdirComment #3
litwol commentedWhile i wholeheartedly welcome devel generate for pmsg, i know some issues will arise (or rather some important issues will be made more hidden) if we provide and rely only on 1 generic generate method.
To explain what i mean i have to remind of those tricky bugs we've encountered when amount of content was distributed between authors and recipients in a particular way.
Consider this table of number of messages between author and recipients( i only write one matrix as an example, but consider that sometimes Recipient is also an Author of the message he receives):
A | R
--+--
1 | 1
1 | n << recent bug we fixed in #490650: Message sent to oneself breaks new/#replies data loading
n | 1
n | n
We recently fixed a bug that appeared when author was sending message to self as well as some other people. This bug would be impossible to catch if devel generate not allow to generate content differently.
We need to proceed bearing the above in mind. I would also welcome a dedicated privatemsg_debug.module that encompases all of the possible message usage scenarios to be thorough. i realize that 'all of the possible message usage scenarios' sound loaded and like it is *alot* of scenarios, but really this number is rather finite and if we take care to resolving this first then we will be able to write more encompasing tests moving forward.
Comment #4
crea commentedSubscribing
Comment #5
nagiek commentedHere's a reroll of the patch, a few changes to add replies to the threads, plus comments by Berdir.
Comment #7
nagiek commentedUrgh, this is my first patch. Guess I didn't get it right.
Comment #8
nagiek commentedComment #9
berdirSome don't like git format-patch style patches, but it's fine with me, *if*:
- You make sure that you only work on a single commit so that follow-up changes aren't split up into multiple "mails". You can do this using git commit --append.
- The commit message follows the guidines and loos something like this: "Issue #502666 by nagiek, other_persons, ...: Added devel_generate integration."
No idea what .DS_Store is, but I'm pretty sure it's not needed here :)
Googling it, looks like it's some Mac OSX Stuff: http://en.wikipedia.org/wiki/.DS_Store
You probably need to remove that from your commit and best add it to a .gitignore file.
Should end with a ., also think the default is "Form builder; ..", see http://api.drupal.org/api/drupal/modules--user--user.module/function/use... and the corresponding validate/submit docblocks.
Trailing space. Below are more, look at the output of git diff (directly, not at a generated patch file) or use dreditor to see them easily.
The keys num_messages and max_thread don't really make sense. Maybe num_threads and max_thread_length?
Generate instead of Do it! ? :)
Comments should be a real sentence and end with a ., something like "Ignore anonymous and admin for user count check."
The first argument to form_set_error() is the name of the form field for which this error is. In your case, 'recipients][max_recipients' (missing brackets at end/start are not a type, that's how it must be for nested elements).
thread instead of messages?
Thinking about it, some time ago, we were talking about using "conversion" instead of "thread" in user facing strings, but this is not really user facing, so thread is fine.
using array('uid' => ) is deprecated in D6 and doesn't work anymore in D7, so just user_load($user...
user_load() isn't statically cached in D6. But you can use privatemsg_user_load(), which does. See http://api.worldempire.ch/api/privatemsg/privatemsg.module/function/priv...
Same here, you count the number of new threads, not messages.
Comment #10
nagiek commentedThanks! That's a great review. Will come back.
Comment #11
nagiek commentedI know it's weird language, but that's in the other devel_generate forms.
Was in the original patch, had just left it. Changed.
Sure.
Patch is as a single commit.
Comment #12
nagiek commentedI know it's weird language, but that's in the other devel_generate forms.
Was in the original patch, had just left it. Changed.
Sure.
Patch is as a single commit.
Comment #13
berdirRe "Do it", I originally checked 7.x, which uses "Generate", while 6.x uses "Do it", as you said. I'd say we should do it the 7.x way, or it is another thing that would need to be updated when porting the patch to 7.x. But I don't really care...
The recipients fieldset doesn't have #tree set to TRUE, so it's just $form_state['values']['max_recipients']
$users is just an array with the user id's, the ->uid part is unecessary.
Because the same mistake is also made a bit below with the recipients, it currently loops forever when trying to generate messages.
privatemsg_user_load() also supports an array of user id's, so you can just write $recipients = privatemgs_user_load($recipient_uids);
I tried out the patch and it didn't really work yet, the function privatemsg_devel_generate_new_thread() was overcomplicated quite a bit and also had multiple errors (it e.g. the mentioned uid thing above), so I fixed the function, this one actually works:
I've created ~5500 threads without any errors with this.
I also noticed on a clean d6 site, that it only works if users have the write privatemsg permission because the API verifies the permissions. Maybe add a validation check to see if authenticated users have that permission?
Comment #14
nagiek commentedOK, using your function. Added a check for 'write privatemsg' permission. Drupal 6 doesn't have a user_role_permissions function, so created one. Seems to work fine.
Comment #15
nagiek commentedSorry, whitespace errors. Use this.
Comment #16
nagiek commentedOne more time!
Comment #17
berdirCommited to 6.x-2.x, thanks for working on this!
Are you up for a 7.x-2.x port? :)
Comment #18
nagiek commented7.x patch. I'm not sure how to see whitespace before actually doing an upload...
Comment #19
nagiek commentedAlso, sometimes, I don't know why, it spits an error that recipients column is NULL. I can't figure out why.
Comment #21
nagiek commentedComment #22
berdirThanks!
Re whitespaces, doing git diff returns by default a colored diff which also highlights trailing whitespaces (At least it does so under linux). Not sure about Windows.
Many editors/IDE's can be configured to remove them automatically or e.g. only from changed lines which is very helpful. Netbeans for example can be configured to format code automatically almost perfectly according to the coding standards.
Patch looks good, will try it out and commit when I find the time.
Comment #23
nagiek commentedbump
Comment #24
berdirSorry for letting you wait for so long!
Our usage (or maybe my simplifcation above) is the problem of the NULL problem.
We're currently using the key of the $uids array but it's a numerical array. So we always used an integer between 0 and 49 for the users and you might or might not have users with such id's :)
I fixed that and commited the patch. We probably need the same fix for 6.x-2.x as well, can you check that?
Comment #25
nagiek commentedNo worries!
Oh yeah, user check. Do you have the patch you committed? Would be easier to see.
Comment #26
berdirI simply changed a single line of code, using drupal_map_assoc() to make sure that the keys are uid's as well., see http://drupalcode.org/project/privatemsg.git/blob/refs/heads/7.x-2.x:/pr....
Comment #27
oadaeh commentedThis issue is being closed because it is against a branch for a version of Drupal that is no longer supported.
If you feel that this issue is still valid, feel free to re-open and update it (and any possible patch) to work with the 7.x-1.x branch (bug fixes only) or the 7.x-2.x branch.
Thank you.