The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
![]()
Hey all, I've stumbled across an issue that has got me totally stumped.
What I have is a script that will run via the scheduled task system that will update a users membergroups based on whether they have a particular award assigned to them. (and removes if they no longer have that award) This was working great when it was done for a couple of awards as I simply hardcoded in the award and group id's. Now, as there are many awards and groups to assign I modified the script and put all of the values into an array, which will then loop through that and update everyone accordingly. Sounds simple, and when I echo to screen all of the data it looks like it is working perfectly. However it is not updating everyone as per what is being displayed on the screen. It is almost as if the PHP Code:
As mentioned above, if I hard code the group and award id's it works perfectly. So it appears to be something to do with the looping of the array that is upsetting the datamanager. Just wondering if this is a limitation or just something I'm doing wrong! I've tried several variants of looping the array from foreach, do while, and finally a simple count array and then a for loop until count. All the same result! Below is the first half of the script that has the add users. The delete is essentially the same problem. This is the latest test with the count array and for until count option. Here's a sample of the many echos (being very thorough!) that is produced when the script is run. The first ID user 66 is being assigned to group 50 as he has that award, but when I check the account after the script has been run it is not there even though it says it's been saved. Any ideas at all? Code:
18| Award=3, Group=50 Existing Groups=27,43 | UserID=66 Membergroups=27,43,50 | Account updated! | UserID=66 Membergroups=27,43,50 Existing Groups=52 | UserID=806 Membergroups=52,50 | Account updated! | UserID=806 Membergroups=50,52 Existing Groups=37,48,50 | UserID=234 Membergroups=37,48,50 | Account updated! | UserID=234 Membergroups=37,48,50 Existing Groups=48,50 | UserID=800 Membergroups=48,50 | Account updated! | UserID=800 Membergroups=48,50 PHP Code:
|
#2
|
|||
|
|||
![]()
I think this is where you go wrong:
PHP Code:
However there is not entry $awardarr[1], you only have 3, 5, 6, .... Instead of using a for loop, why not act on the arracy directly, ie: PHP Code:
|
#3
|
|||
|
|||
![]()
The foreach loop was my first attempt which didn't work either. It was giving exactly the same results. It looked like everything was working as the correct values were being echoed to the screen but on checking only some users were being updated.
So in theory there is nothing stopping the datamanager save command working within a loop? If not then I'll keep experimenting! So glad we're allowed a testvb install ![]() Actually, just checked and my foreach was as; PHP Code:
--------------- Added [DATE]1234436902[/DATE] at [TIME]1234436902[/TIME] --------------- Unfortunatly same result. There is something about the loop that it doesn't like. I'll keep digging, but figured I'd post here incase it's something I'm doing really silly. |
#4
|
|||
|
|||
![]()
You should be calling pre_save() (I think that is the name of the function off the top of my head) before doing any error calling - it is there where the error array is populated.
|
#5
|
|||
|
|||
![]() Quote:
--------------- Added [DATE]1234439530[/DATE] at [TIME]1234439530[/TIME] --------------- ok, getting somewhere now. It's not the loop failing as I've tried removing that part and copying the code out three times then setting the award id manually like so; PHP Code:
--------------- Added [DATE]1234442124[/DATE] at [TIME]1234442124[/TIME] --------------- ok, it's the arrays at the top thats causing the problem. A follow on from the 'three stage' test that I done still referenced one array. I commented out the following line at the beginning of each step like so; PHP Code:
PHP Code:
Looks like I need to do some more reading on arrays which I've not used in php too much. Finally getting somewhere! |
#6
|
|||
|
|||
![]()
$aw2gr = $grouparr[$awardval];
What data are you trying to lookup in the $grouparr array? I have the feeling that you don't need that array at all as it seems you are trying to use the same value that is already available as $key. |
#7
|
|||
|
|||
![]() Quote:
the $grouparr is set with the key being the relevant award ID and the value is the vb usergroup ID that needs to be assigned to the user in question. I see what you're saying though. With that in mind I now have; PHP Code:
|
#8
|
|||
|
|||
![]()
Instead of doing all the str_replace's on the membergroupids, why not explode it to an array, manipulate and implode back again.
Ie. something like: PHP Code:
|
#9
|
|||
|
|||
![]() Quote:
--------------- Added [DATE]1234453404[/DATE] at [TIME]1234453404[/TIME] --------------- ok, struggling with this and I think it's either because of the amount of updates or the length of the script. I've blocked it out as explained above and set the group id's manually for each block and it works fine upto a point. Once I get to four blocks it stops working, even though the echo to screen is fine. I'm sure this is what is happening with the array loop too. Are there any limitations to the schedule tasks at all? --------------- Added [DATE]1234453821[/DATE] at [TIME]1234453821[/TIME] --------------- just confirmed. Added the array loop back in with a much shorter array (two entries) and it runs perfectly. So I'm guessing the amount of updates that the script is trying to do is overwhelming something. But what, the datamanager? or the server? There are no errors showing in the error log at all. PHP Code:
/facepalm! I am so dumb! Solved it! ok, so this is to be a scheduled task that updates users membergroups. However, if they're already a member then there is no reason to do anything with them. However, I totally neglected to take this into account with the query! So, give awards query becomes; PHP Code:
![]() well, it's been a fun afternoon, please don't laugh at me too much! ![]() |
![]() |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|