1 | <?php |
||
2 | // $Id$ |
||
3 | |||
4 | /** |
||
5 | * @file |
||
6 | * A special, detachable routine for importing teams. |
||
7 | * |
||
8 | * The process of importing teams relies on Drupal API calls that may not |
||
9 | * be intended for large batch processing. This script is intended to be called |
||
10 | * via exec() by a higher level import routine to handle a small subset of teams |
||
11 | * at a time and avoid exhausting memory. |
||
12 | */ |
||
13 | |||
14 | require_once('./includes/bootstrap.inc'); |
||
15 | drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); |
||
16 | require_boinc('db'); |
||
17 | |||
18 | // Parse arguments |
||
19 | $team_id = isset($argv[1]) ? $argv[1] : null; |
||
20 | $team_type_tid = isset($argv[2]) ? $argv[2] : null; |
||
21 | $input_format = isset($argv[3]) ? $argv[3] : null; |
||
22 | |||
23 | $count = 0; |
||
24 | |||
25 | // Get teams from BOINC |
||
26 | db_set_active('boinc_rw'); |
||
27 | $boincteam = db_fetch_object(db_query('SELECT * FROM team WHERE id=%d', array($team_id))); |
||
28 | $boincteam_members = db_query('SELECT id FROM user WHERE teamid=%d', array($team_id)); |
||
29 | $boincteam_admin = (int) db_result(db_query('SELECT userid FROM team_admin WHERE teamid=%d', array($team_id))); |
||
30 | db_set_active('default'); |
||
31 | |||
32 | $team_exists = db_query('SELECT team_id FROM {boincteam} WHERE team_id = %d', $boincteam->id); |
||
33 | // FIXME: $team_exists==FALSE should be handled as an error and return an error code! |
||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
34 | |||
35 | if ($team_exists != FALSE && db_fetch_object($team_exists) == FALSE) { |
||
36 | $boincteam->description = _boincimport_text_sanitize($boincteam->description); |
||
37 | $teaser = node_teaser($boincteam->description); |
||
38 | |||
39 | // Construct the team as an organic group node |
||
40 | $node = array( |
||
41 | 'type' => 'team', |
||
42 | 'title' => $boincteam->name, |
||
43 | 'body' => $boincteam->description, |
||
44 | 'teaser' => $teaser, |
||
45 | 'uid' => boincuser_lookup_uid($boincteam->userid), |
||
46 | 'path' => null, |
||
47 | 'status' => 1, // published or not - always publish |
||
48 | 'promote' => 0, |
||
49 | 'created' => $boincteam->create_time, |
||
50 | 'comment' => 0, // comments disabled |
||
51 | 'moderate' => 0, |
||
52 | 'sticky' => 0, |
||
53 | 'format' => $input_format |
||
54 | ); |
||
55 | |||
56 | // Use pathauto function, if available, to clean up the path |
||
57 | if (module_exists('pathauto')) { |
||
58 | module_load_include('inc', 'pathauto', 'pathauto'); |
||
59 | $node['path'] = pathauto_cleanstring($boincteam->name); |
||
60 | } |
||
61 | else { |
||
62 | echo 'Pathauto module is required!'; |
||
63 | exit; |
||
64 | } |
||
65 | |||
66 | $node = (object) $node; // node_save requires an object form |
||
67 | |||
68 | $node->taxonomy[] = taxonomy_get_term($team_type_tid); |
||
69 | |||
70 | // Save the team node |
||
71 | node_save($node); |
||
72 | |||
73 | // Save the team IDs to a BOINC <--> Drupal reference table. |
||
74 | db_query('INSERT INTO {boincteam} (team_id, nid) VALUES (%d, %d)', $boincteam->id, $node->nid); |
||
75 | } |
||
76 | |||
77 | // Determine team membership |
||
78 | db_set_active('boinc_rw'); |
||
79 | $boincteam_member_ids = array(); |
||
80 | while ($boincuser = db_fetch_object($boincteam_members)) $boincteam_member_ids[] = $boincuser->id; |
||
81 | db_set_active('default'); |
||
82 | if ($boincteam_member_ids) { |
||
83 | $team_members = db_query('SELECT uid FROM {boincuser} WHERE boinc_id IN(%s)', implode(',', $boincteam_member_ids)); |
||
84 | $team_admin = (int) db_result(db_query('SELECT uid FROM {boincuser} WHERE boinc_id=%d', $boincteam_admin)); |
||
85 | |||
86 | while ($drupal_user = db_fetch_object($team_members)) { |
||
87 | // Add action to take on member accounts? |
||
88 | $count++; |
||
89 | } |
||
90 | } |
||
91 | |||
92 | echo $count; |
||
93 | |||
94 |