Closed (fixed)
Project:
Userpoints Badges
Version:
7.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
25 Oct 2011 at 15:28 UTC
Updated:
20 Nov 2015 at 02:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
nancydruComment #3
nancydruTry again, testbot.
Comment #5
berdirI think the problem is that you're using new\ instead of new/, git then looks for a folder caled "new\userpoints_badges".
Comment #6
Satori42 commentedI'm on a Windows 7 machine. Using patch.exe for GnuWin32, which has worked for me before:
userpoints_badges.info
Comment #7
berdirYes, because you're on Windows and on Windows, \ is a path delimiter but on Unix (and the test bot is on Linux), it is perfectly valid to have a path with the name "a\b".
Comment #8
Satori42 commentedThat's good to know when attempting to apply patches in general. Thank you, Berdir.
Comment #9
nancydruWell, I don't have Git. I just used the diff command. There is a full zip of the module in the first post, from which a patch that the tesbot might like can be created. Or you can just use that to commit.
Comment #10
berdirYou don't need git, just do replace all "\" in the patch with "/" with your favorite text editor :)
Below is a first review of your changes. Note that I have quite high expectations/standards, especially compared to the sad state of most stuff in the 6.x branch of this project. Even though the review seems to be long, your efforts are very much appreciated, keep it coming! :)
I've started a new userpoints 7.x-2.x branch with major API changes.
To avoid confusion, can you specify that this module is (for now) only compatible with 7.x-1.x by specifying the major version like the following example: "dependencies[] = exampleapi (1.x)". See http://drupal.org/node/542202 for more information.
This is something I need to do for all other modules too.
Let's add a "configure = admin/config/people/userpoints/settings" then a link to the configuration page is displayed directly on the modules pages.
No need to keep empty functions, just drop the _install implementation completely.
The _uninstall() hook should use variable_del() to delete all variables which are used by it. This doesn't work very well for dynamic ones, so you might need to do a db_delete() query directly.
Nitpicking, two spaces after Implements, same in other docblocks.
It is not necessary to convert simple queries like this one to db_select(). See http://drupal.stackexchange.com/questions/1200/given-that-db-select-is-m... for an explanation why and when db_select() needs to be used.
I am not sure about breaking translated sentences into multiple lines, is this a new coding standard?
You should instead use elseif, easier than another nested condition.
Also, might be worth to check if userpoints_badges 7.x provides any hooks for when badges are deleted, so that we can do this in a hook implementation. Uhm, looking at the module's code, there isn't a single module_invoke() in there, sad panda :(
Same here, as there are not even placeholders in this query, it should work as-is you just need to replace the while with a foreach loop. I agree on using $result instead of $sql, though.
If you want a total per user over all categories, you can query the new userpoints_total table. That avoids the need for the GROUP BY. Also, looks like this module doesn't support userpoints categories yet. Which is fine for now, although something I try to support everyhwere properly.
I guess this is based on #1306032: Cumulative D7 Changes. Since you're working on that too, I suggest you change it to admin/config/people/user_badges, because that's the place for user related configuration IMHO.
Not sure if the lower case like works since there are some defined special cases for this for PostgreSQL support. For consistency, let's use the uppper case version :)
Comment #11
nancydruCool beans! I hadn't yet run across the "configure" yet.
There don't seem to be any variables to delete.
I know I can still use db_query for simple selects, but I'd rather convert all for consistency.
Breaking the lines was for the standard of keeping within 80 characters, which is wide violated, even in core. I'm undoing that because I wonder if Locale can handle it.
I don't like elseif and never use it. I find it hard for me to read it properly. I don't think there is an execution penalty.
I originally put User Badges in admin/config/people, but then went back to my D6 installation to check something out and decided to move it to admin/people for consistency with D6.
I have never used Userpoints before, I only tackled this because of an issue someone was having with User Badges. I don't know the UP structure at all, having only installed it right after looking at that poster's issue. And it looks like the uerpoints_retroactive module hasn't been converted yet either, so that impacts my trying to learn it.
Comment #12
nancydruComment #14
berdirOk, two generic problems with the patch format remaining.
- Windows style file endings. The test bot doesn't like these nor does git.
- You are patching the -dev snapshot which contains the project/build information in the .info file. But the patch is applied against a git checkout which doesn't. After manually removing these parts (which is tricky), I was able to apply your patch successfully.
I suggest you look into learning some git basics sooner or later because you just don't have problems like this with git diff. I gladly provide any assistance you need, you just need to ask. It's really not that complicated :)
For reference, attaching the altered patch file that finally worked for me, this one should get past the bot (which is kinda pointless as there are no tests ;))
Comment #16
nancydruYeah, working on User Badges and the other maintainers are absent, so I'm going to have to install and learn Git (I will use a GUI). I may have call on you.
Comment #17
berdirAbout People/Configuration. It doesn't need to be like Drupal 6. But it should follow the UX Guidelines/Information Architecture of Drupal 7. Have a look at http://drupal.org/node/549094#people.
I don't know Git GUI's in detail (Although I've heard that EGit which is a Eclipse plugin is pretty good), but I can still help to explain Git in general. I can also recommend #drupal-gitsupport if there are questions.
Comment #18
spaceknight commenteduserpoints_badges_7.x.patch queued for re-testing.
Comment #19
berdirThere are no tests, this is not going to get any better than that message :)
Comment #20
spaceknight commentedBerdir,
I can't make your patch work with TortoiseSVN on Windows.
I had installed following userpoints_contrib module:
http://ftp.drupal.org/files/projects/userpoints_contrib-7.x-1.x-dev.tar.gz
I am getting following error when TortoiseMerge is run:
'C:\xampp\htdocs\drupal7\sites\all\modules\userpoints_contrib\userpoints_badges' is not a working copy.
Comment #21
berdirNo idea about that error, but as I said, my patch is against the git checkout, it doesn't apply against the -dev snapshot.
Comment #22
spaceknight commentedThat error is because I have not checked out first. I don't get it, can't I apply patches to local copies only, without any version control repository involved?
Comment #23
berdirIn theory yes, you can.
This case differs because the .info file is changed when the package is built, so it is not the same file.
Try the patch from NancyDru, that is against the snapshot.
Comment #24
spaceknight commentedI have directly used the userpoints_badges.zip from NancyDru.
It works better than the untouched 6.x version.
Here is my report as of now:
EDIT:
- Cannot edit a badge: Trying to edit a badge, although the URL seems to be correct (program/admin/people/user_badges/edit/2), it takes me to People page.
ADD:
- Notice when add is clicked: "Notice: Undefined variable: userpoints_goal in userpoints_badges_form_alter() (line 29 of C:\xampp\htdocs\drupal\sites\all\modules\userpoints_contrib\userpoints_badges\userpoints_badges.module)."
- There are two form buttons named (Save Badge) at the bottom.
LIST:
- Can we put Userpoints Goal as a column?
Comment #25
nancydruLet us, please, try to separate the issues as to which module is causing them. User Badges issues belong in #1306032: Cumulative D7 Changes.
Comment #26
nancydruHere's the zip after applying Berdir's list, and from which the patch was made.
Comment #27
nancydruADD:
After
if ('user_badges_edit_form' === $form_id) {(first line of code), add$userpoints_goal = '0';I suspect this is a difference in what 7.x returns from the query as opposed to what 6.x returns.
The save buttons will be fixed on my next patch update.
Comment #28
nancydruCan one of you give me an idea of how to set up a test case in UP?
Comment #29
nancydru@Berdir: Can you remove
$form['submit']['#weight'] = 10;from the form_alter(), please. I am changing the form to add weights so that this module gets its field in the right place, rather than at the bottom of the image list. Thanks.Comment #30
berdirHave a look at http://blog.worldempire.ch/story/writing-automated-tests-drupal-7 and check out the existing UserpointsTests in userpoints.test.
Basically, you will need to implement what you would do in a manual test in PHP with the methods provided by Simpletest. However, writing tests takes quite some time and it might might make more sense to write tests for User Badges itself first. Then it would be easy to adapt and extend those with stuff added by this module.
Not having tests is IMHO fine for the moment, just ignore the testbot for now. You can use a something-d7.patch name, then the test bot will ignore but I can still do a manual review.
Comment #31
nancydruSorry, I didn't mean that kind of test, but thanks for the tutorial. I need to configure UP on my site so that I can test whether or not UPB is working with UB.
But, yes, I guess Simpletest is something else to get back to. I wrote some in Web Links some time ago.
Comment #32
berdirAh sorry, misunderstood you. A test case for me is something related to Simpletest :)
I think all you need is at admin/config/people/userpoints. You can see how many points each user has, the transactions, grant/remove points for a user and configure the settings.
Comment #33
nancydruOkay. I set a badge to 10 points and then gave a user 10 points, and he didn't get the badge. So I created a transaction for 10 more poonts (both show in the list), still no badge. So I found UP_nc module and tried that. I don't even see the points being granted.
Comment #34
berdirNot sure, but my suggestion is to fix user_badges first and then work on UP/User Badges integration :)
Comment #35
berdirFrom #871114: Drupal 7 port (userpoints_invite), let's not add versioned dependencies until it works for dev snapshots and git checkouts..
Comment #36
davidcsonka commentedJust curious, should interested parties assume that a port to Drupal 7 is indefinitely postponed? Was hoping to utilize points with badges for an upcoming project being developed in D7.
Comment #37
hoporr commentedThe zip file in #26 worked well against the dev branch.
It did raise an error when the user_badges-edit_form came up as part of creating a NEW badge, and userpoints_goal was not yet found in the dB, and thus not properly initialized. I added an extra line to initialize the varialbe and the error went away.
Comment #38
nancydruIIRC, I've committed all the changes that were in the zip file, so the -dev should be at the same point.
Comment #39
hoporr commentedStill appears to be a problem (new?). We were getting an error when submitting comments:
Fatal error: Call to a member function orderBy() on a non-object in .../userpoints_contrib/userpoints_badges/userpoints_badges.module on line 68
It appears that the join in that statement destroys the object.
I then found this comment in a discussion on db_select:
http://api.drupal.org/api/drupal/includes!database!database.inc/function...
Following the example, I rewrote the statement as shown here, and this appears to work fine:
Here is the output from dpq($result), to check the SQL that is generated:
Comment #40
Youblob commented..so changing this will make it work?
Im really keen on using this module :D
Comment #41
jordan8037310 commentedI can confirm that the fix in #39 fixes the error about the non-object.
I have to do some more testing but will post again to confirm functionality.
Comment #42
jordan8037310 commentedI have found an error while adding the badges.
and a second error
and a third:
Have yet to investigate further as it does not prohibit the uploading of the badges, but I'm sure it's breaking something—I just don't know what, yet.
Comment #43
socialnicheguru commentedfix in #39 totally worked for me on my issue,https://drupal.org/node/2266699, which is a duplicate of #39.
Comment #44
jay.lee.bio commentedWhile trying to figure out how to give users special badges when they accumulate a certain amount of points, I found something interesting to share. Basically I figured out how to give users new badges each time they were awarded points. Per screenshot, all you need are Rules (7.x-2.8), User Badges (7.x-4.x-dev) & User Points (7.x-1.0) to reproduce what I did. Here's what I found:
1) #26 causes WSOD for the purpose of this test, so I disabled it.
2) In "Data Comparison", I used "userpoints-transaction:points" and set it to 1. This successfully added a badge each time a user was awarded 1 point.
It looked like the important pieces of code that made this possible were found in lines 22 - 26 of userpoints_rules.rules.inc from User Points, which gets data from the userpoints_txn table in the database. So here's the million dollar question to achieve what I (and hopefully most of you guys) really want to achieve, which is to give users badges when they accumulate a certain amount of points:
Don't we just need to make the total amount of points a user has, from the userpoints_total table in the database, to show up as a token under "Data Comparison"? Or has this already been mentioned somewhere before?
P.S. I haven't done testing with User Badges 7.x-3.2 yet, but I have a feeling it'll actually work since even the newest & unstable 7.x-4.x-dev works.
Comment #45
albert volkman commentedComment #47
albert volkman commentedMerged a modified version of #1321082: Userpoints_badges for 7.x