BOINC /
boinc
| 1 | <?php |
||
| 2 | |||
| 3 | // repair user.global_prefs fields that were corrupted |
||
| 4 | // (non-parsable XML) by a bug at some point. |
||
| 5 | // |
||
| 6 | // This fixes 2 types of corruption: |
||
| 7 | // - missing </venue> tag before closing </global_preferences> |
||
| 8 | // - \" instead of " |
||
| 9 | |||
| 10 | require_once("../inc/boinc_db.inc"); |
||
| 11 | |||
| 12 | // insert "\n</venue>\n" before "</global_preferences>" |
||
| 13 | // This fixes an XML error introduced at some point in the past |
||
| 14 | // |
||
| 15 | function repair_prefs($prefs) { |
||
| 16 | if (strstr($prefs, '\"')) { |
||
| 17 | return str_replace('\"', '"', $prefs); |
||
| 18 | } |
||
| 19 | $x = strstr($prefs, "</global_preferences>", true); |
||
| 20 | if (!$x) return null; |
||
| 21 | return "$x\n </venue>\n</global_preferences>\n"; |
||
| 22 | } |
||
| 23 | |||
| 24 | function process_set($users) { |
||
| 25 | foreach ($users as $user) { |
||
| 26 | if (!$user->global_prefs) { |
||
| 27 | //echo "$user->id: no prefs\n"; |
||
| 28 | continue; |
||
| 29 | } |
||
| 30 | $retval = @simplexml_load_string($user->global_prefs); |
||
| 31 | if ($retval) { |
||
| 32 | //echo "$user->id: good\n"; |
||
| 33 | } else { |
||
| 34 | echo "repairing prefs for user $user->id\n"; |
||
| 35 | $p = repair_prefs($user->global_prefs); |
||
| 36 | if ($p) { |
||
| 37 | $xml_obj = @simplexml_load_string($p); |
||
| 38 | if ($xml_obj) { |
||
| 39 | // increase mod_time by 1 second so new preferences are propagated to the Client |
||
| 40 | $xml_obj->mod_time = 1 + intval($xml_obj->mod_time); |
||
| 41 | $p = $xml_obj->asXML(); |
||
| 42 | // remove XML header |
||
| 43 | $p = implode("\n", array_slice(explode("\n", $p), 1)); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 44 | $user->update("global_prefs='$p'"); |
||
| 45 | echo " repair succeeded\n"; |
||
| 46 | } else { |
||
| 47 | echo " repair failed\n"; |
||
| 48 | } |
||
| 49 | } else { |
||
| 50 | echo " prefs are missing end tag\n"; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | |||
| 57 | $n = 0; |
||
| 58 | $maxid = BoincUser::max("id"); |
||
| 59 | while ($n <= $maxid) { |
||
| 60 | $m = $n + 1000; |
||
| 61 | $users = BoincUser::enum("id >= $n and id < $m"); |
||
| 62 | //echo "processing from $n\n"; |
||
| 63 | if (!$users) break; |
||
| 64 | process_set($users); |
||
| 65 | $n = $m; |
||
| 66 | } |
||
| 67 | ?> |
||
| 68 |