blob: 9d54790f9b2865a0cc1875448f409f4fdd5aa257 [file] [log] [blame]
gobrien964d4642008-02-16 00:30:26 +00001<?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*******************************************************************************/
gobrien67c5a052008-04-17 19:03:42 +000013//require("global.php");
14//InitPage("");
gobrien964d4642008-02-16 00:30:26 +000015
gobrien67c5a052008-04-17 19:03:42 +000016ini_set('memory_limit', '512M');
gobrien964d4642008-02-16 00:30:26 +000017
atoulme12882d52009-01-26 18:39:17 +000018require(dirname(__FILE__) . "/../system/dbconnection.class.php");
gobrien67c5a052008-04-17 19:03:42 +000019$dbc = new DBConnection();
20$dbh = $dbc->connect();
21
gobrien8e5fb172008-04-17 20:20:39 +000022print "fetching translation to heal\n";
gobrien67c5a052008-04-17 19:03:42 +000023$query = "select translation_id,string_id,language_id,created_on,value from translations group by string_id,language_id order by created_on desc";
gobrien964d4642008-02-16 00:30:26 +000024$res = mysql_query($query);
gobrien67c5a052008-04-17 19:03:42 +000025
26print "starting to heal the translations\n";
gobrien964d4642008-02-16 00:30:26 +000027
28while($row = mysql_fetch_assoc($res)){
gobrien67c5a052008-04-17 19:03:42 +000029 $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 }
gobrien964d4642008-02-16 00:30:26 +000049}
50
gobrien8e5fb172008-04-17 20:20:39 +000051print "deleting file_progress table data\n";
gobrien67c5a052008-04-17 19:03:42 +000052//drop all the old calced file progress
53$query = "delete from file_progress";
54mysql_query($query);
gobrien964d4642008-02-16 00:30:26 +000055
gobrien67c5a052008-04-17 19:03:42 +000056print "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);
60while($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);
66while($row = mysql_fetch_assoc($res)){
67 $lang_ids[] = $row['language_id'];
68}
gobrien964d4642008-02-16 00:30:26 +000069
gobrien8e5fb172008-04-17 20:20:39 +000070print "cleaning up the file progress of all 0 completed!\n";
gobrien67c5a052008-04-17 19:03:42 +000071//clean up all the pct_complete == 0
72$query = "delete from file_progress where pct_complete = 0";
73mysql_query($query);
gobrien964d4642008-02-16 00:30:26 +000074
droy29b30962008-05-23 14:17:28 +000075
76print "Removing all files affected by bug 233305\n";
77print "This may take a while\n";
droyf142fc32008-05-21 20:53:43 +000078
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);
83while($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
115print $file_count;
gobrien67c5a052008-04-17 19:03:42 +0000116print "done!\n";
gobrien964d4642008-02-16 00:30:26 +0000117
gobrien67c5a052008-04-17 19:03:42 +0000118/*
119 * OLD CODE
120 *
121 * foreach($found as $string_id => $v){
gobrien964d4642008-02-16 00:30:26 +0000122 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";
gobrien67c5a052008-04-17 19:03:42 +0000136// mysql_query($query);
gobrien964d4642008-02-16 00:30:26 +0000137 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";
gobrien67c5a052008-04-17 19:03:42 +0000145// mysql_query($query);
gobrien964d4642008-02-16 00:30:26 +0000146 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";
gobrien67c5a052008-04-17 19:03:42 +0000150// mysql_query($query);
gobrien964d4642008-02-16 00:30:26 +0000151 print mysql_error();
152
153 }
154 }
155}
gobrien67c5a052008-04-17 19:03:42 +0000156 */
157
gobrien964d4642008-02-16 00:30:26 +0000158
159?>