processing existing votingapi data
| Project: | User Points Voting API |
| Version: | 5.x-2.2 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | reviewed & tested by the community |
Hi,
I added code to allow the module to process existing votingapi data.
The code is mainly a copy from the content recommendation module.
The code adds the following options:
On installation it stores the highest vote_id in userpoints_votingapi_starting_position
and then on each cron job it process up to userpoints_votingapi_max_install_votes votes.
I added an option to set userpoints_votingapi_max_install_votes in the settings of the userpoints_votingapi.
here is the diff:
diff ./userpoints_votingapi.install /cygdrive/d/Downloads/userpoints_votingapi/userpoints_votingapi.install
10,13d9
<
< $voting_result = db_query("SELECT id FROM {sequences} WHERE name='votingapi_vote'");
< $vote_obj = db_fetch_object($voting_result);
< variable_set('userpoints_votingapi_starting_position', $vote_obj->id + 1);
25,26d20
< variable_del('userpoints_votingapi_starting_position');
< variable_del('userpoints_votingapi_max_install_votes');
diff ./userpoints_votingapi.module /cygdrive/d/Downloads/userpoints_votingapi/userpoints_votingapi.module
50,56d49
<
< $form['votingapi']['userpoints_votingapi_max_install_votes'] = array(
< '#type' => 'textfield',
< '#title' => t('Number of votes to process in one install run'),
< '#description' => t('Specifies the number of votes to process in one cron run to further installation the module. This is only important for sites that install userpoints_votingapi over existing votingapi data'),
< '#default_value' => variable_get('userpoints_votingapi_max_install_votes', 5),
< );
111,128d103
< }
<
< function userpoints_votingapi_cron(){
< $starting_pos = variable_get('userpoints_votingapi_starting_position',-1);
< $vote_limit = variable_get('userpoints_votingapi_max_install_votes', 5);
<
< // for every vote within range...^
< $db_result = db_query("SELECT vote_id, uid, content_id, content_type FROM votingapi_vote
< WHERE vote_id < %d
< ORDER BY vote_id DESC LIMIT %d", $starting_pos, $vote_limit);
< while ($vote_obj = db_fetch_object($db_result)) {
< userpoints_votingapi_votingapi_insert($vote_obj);
< $vid = $vote_obj->vote_id;
< }
< // now save the starting position for next run
< variable_set('userpoints_votingapi_starting_position', $vid);
<
<

#1
Hi eliweiss,
Can you attach a patch or your modified copy of the module?
Thanks,
Kevin
#2
Here is my modified version of the module.
It is not based on HEAD but on the released version 5.x 2.2.
#3
Committed to dev.