gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 1 | <?php |
| 2 | /******************************************************************************* |
| 3 | * Copyright (c) 2007-2008 Eclipse Foundation and others. |
| 4 | * All rights reserved. This program and the accompanying materials |
| 5 | * are made available under the terms of the Eclipse Public License v1.0 |
| 6 | * which accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Paul Colton (Aptana)- initial API and implementation |
| 11 | * Eclipse Foundation |
| 12 | *******************************************************************************/ |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 13 | //require("global.php"); |
| 14 | //InitPage(""); |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 15 | |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 16 | ini_set('memory_limit', '512M'); |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 17 | |
atoulme | 12882d5 | 2009-01-26 18:39:17 +0000 | [diff] [blame] | 18 | require(dirname(__FILE__) . "/../system/dbconnection.class.php"); |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 19 | $dbc = new DBConnection(); |
| 20 | $dbh = $dbc->connect(); |
| 21 | |
gobrien | 8e5fb17 | 2008-04-17 20:20:39 +0000 | [diff] [blame] | 22 | print "fetching translation to heal\n"; |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 23 | $query = "select translation_id,string_id,language_id,created_on,value from translations group by string_id,language_id order by created_on desc"; |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 24 | $res = mysql_query($query); |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 25 | |
| 26 | print "starting to heal the translations\n"; |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 27 | |
| 28 | while($row = mysql_fetch_assoc($res)){ |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 29 | $string_id = $row['string_id']; |
| 30 | $language_id = $row['language_id']; |
| 31 | |
| 32 | $query = "select translation_id from translations where string_id = $string_id and language_id = $language_id and is_active = 1"; |
| 33 | |
| 34 | $looking = mysql_query($query); |
| 35 | if(mysql_num_rows($looking) == 0){ |
| 36 | // print "found 0 ".$row['translation_id']."\n"; |
| 37 | }elseif(mysql_num_rows($looking) > 1){ |
| 38 | // print "found == ".mysql_num_rows($looking)." -- translation_id ".$row['translation_id']." string_id --- ".$row['string_id']." -- date : ".$row['created_on']."\n".$row['value']."\n"; |
| 39 | |
| 40 | $query = "select max(version) as max from translations where string_id = $string_id and language_id = $language_id "; |
| 41 | $max = mysql_fetch_assoc(mysql_query($query)); |
| 42 | $max = $max['max']; |
| 43 | $query = "update translations set is_active = 0 where string_id = $string_id and language_id = $language_id and version != $max"; |
| 44 | mysql_query($query); |
| 45 | |
| 46 | $query = "update translations set is_active = 1 where string_id = $string_id and language_id = $language_id and version = $max"; |
| 47 | mysql_query($query); |
| 48 | } |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 49 | } |
| 50 | |
gobrien | 8e5fb17 | 2008-04-17 20:20:39 +0000 | [diff] [blame] | 51 | print "deleting file_progress table data\n"; |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 52 | //drop all the old calced file progress |
| 53 | $query = "delete from file_progress"; |
| 54 | mysql_query($query); |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 55 | |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 56 | print "getting all the file ids and language ids\n"; |
| 57 | //get all the files |
| 58 | $query = "select file_id from files"; |
| 59 | $res = mysql_query($query); |
| 60 | while($row = mysql_fetch_assoc($res)){ |
| 61 | $file_ids[] = $row['file_id']; |
| 62 | } |
| 63 | //get all the langs |
| 64 | $query = "select language_id from languages"; |
| 65 | $res = mysql_query($query); |
| 66 | while($row = mysql_fetch_assoc($res)){ |
| 67 | $lang_ids[] = $row['language_id']; |
| 68 | } |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 69 | |
gobrien | 8e5fb17 | 2008-04-17 20:20:39 +0000 | [diff] [blame] | 70 | print "cleaning up the file progress of all 0 completed!\n"; |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 71 | //clean up all the pct_complete == 0 |
| 72 | $query = "delete from file_progress where pct_complete = 0"; |
| 73 | mysql_query($query); |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 74 | |
droy | 29b3096 | 2008-05-23 14:17:28 +0000 | [diff] [blame] | 75 | |
| 76 | print "Removing all files affected by bug 233305\n"; |
| 77 | print "This may take a while\n"; |
droy | f142fc3 | 2008-05-21 20:53:43 +0000 | [diff] [blame] | 78 | |
| 79 | # find lowest version |
| 80 | $file_count = 0; |
| 81 | $query = "select min(file_id) as file_id, project_id, version, name from files where version='unspecified' group by project_id, version, name"; |
| 82 | $res = mysql_query($query); |
| 83 | while($row = mysql_fetch_assoc($res)){ |
| 84 | $query = "select file_id from files |
| 85 | where project_id = '" . $row['project_id'] . "' |
| 86 | and version = 'unspecified' |
| 87 | and name = '" . $row['name'] . "' |
| 88 | and file_id <> " . $row['file_id']; |
| 89 | |
| 90 | $res_f = mysql_query($query); |
| 91 | while($row_f = mysql_fetch_assoc($res_f)){ |
| 92 | # find strings |
| 93 | $file_count++; |
| 94 | $query = "delete from translations where string_id in (select string_id from strings where file_id = '" . $row_f['file_id'] . "')"; |
| 95 | print $query . "... "; |
| 96 | mysql_query($query); |
| 97 | print mysql_affected_rows() . " rows deleted\n"; |
| 98 | |
| 99 | # delete strings |
| 100 | $query = "delete from strings where file_id = '" . $row_f['file_id'] . "'"; |
| 101 | print $query . "... "; |
| 102 | mysql_query($query); |
| 103 | print mysql_affected_rows() . " rows deleted\n"; |
| 104 | |
| 105 | # delete strings |
| 106 | $query = "delete from files where file_id = '" . $row_f['file_id'] . "'"; |
| 107 | print $query . "... "; |
| 108 | mysql_query($query); |
| 109 | print mysql_affected_rows() . " rows deleted\n"; |
| 110 | |
| 111 | } |
| 112 | |
| 113 | } |
| 114 | |
| 115 | print $file_count; |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 116 | print "done!\n"; |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 117 | |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 118 | /* |
| 119 | * OLD CODE |
| 120 | * |
| 121 | * foreach($found as $string_id => $v){ |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 122 | foreach($v as $language_id => $langs){ |
| 123 | $found_active = 0; |
| 124 | foreach($langs as $foo => $trans){ |
| 125 | if($trans['is_active'] == 1){ |
| 126 | $found_active++; |
| 127 | } |
| 128 | } |
| 129 | if( $found_active == 0){ |
| 130 | // print "0 - $string_id - $language_id<br>\n"; |
| 131 | $query = "select max(version) as max from translations where string_id = $string_id and language_id = $language_id "; |
| 132 | $max = mysql_fetch_assoc(mysql_query($query)); |
| 133 | $max = $max['max']; |
| 134 | $query = "update translations set is_active = 1 where string_id = $string_id and language_id = $language_id and version = $max"; |
| 135 | print $query."\n"; |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 136 | // mysql_query($query); |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 137 | print mysql_error(); |
| 138 | |
| 139 | }elseif($found_active > 1){ |
| 140 | $query = "select max(version) as max from translations where string_id = $string_id and language_id = $language_id "; |
| 141 | $max = mysql_fetch_assoc(mysql_query($query)); |
| 142 | $max = $max['max']; |
| 143 | $query = "update translations set is_active = 0 where string_id = $string_id and language_id = $language_id and version != $max"; |
| 144 | print $query."\n"; |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 145 | // mysql_query($query); |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 146 | print mysql_error(); |
| 147 | |
| 148 | $query = "update translations set is_active = 1 where string_id = $string_id and language_id = $language_id and version = $max"; |
| 149 | print $query."\n"; |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 150 | // mysql_query($query); |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 151 | print mysql_error(); |
| 152 | |
| 153 | } |
| 154 | } |
| 155 | } |
gobrien | 67c5a05 | 2008-04-17 19:03:42 +0000 | [diff] [blame] | 156 | */ |
| 157 | |
gobrien | 964d464 | 2008-02-16 00:30:26 +0000 | [diff] [blame] | 158 | |
| 159 | ?> |