blob: 99782be51632241153e3f1d14d4f2909852792fd [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";
kitlo1d027092018-04-19 17:44:07 -040024$res = mysqli_query($dbh, $query);
gobrien67c5a052008-04-17 19:03:42 +000025
26print "starting to heal the translations\n";
gobrien964d4642008-02-16 00:30:26 +000027
kitlo1d027092018-04-19 17:44:07 -040028while($row = mysqli_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
kitlo1d027092018-04-19 17:44:07 -040034 $looking = mysqli_query($dbh, $query);
35 if(mysqli_num_rows($looking) == 0){
gobrien67c5a052008-04-17 19:03:42 +000036// print "found 0 ".$row['translation_id']."\n";
kitlo1d027092018-04-19 17:44:07 -040037 }elseif(mysqli_num_rows($looking) > 1){
38// print "found == ".mysqli_num_rows($looking)." -- translation_id ".$row['translation_id']." string_id --- ".$row['string_id']." -- date : ".$row['created_on']."\n".$row['value']."\n";
gobrien67c5a052008-04-17 19:03:42 +000039
40 $query = "select max(version) as max from translations where string_id = $string_id and language_id = $language_id ";
kitlo1d027092018-04-19 17:44:07 -040041 $max = mysqli_fetch_assoc(mysqli_query($dbh, $query));
gobrien67c5a052008-04-17 19:03:42 +000042 $max = $max['max'];
43 $query = "update translations set is_active = 0 where string_id = $string_id and language_id = $language_id and version != $max";
kitlo1d027092018-04-19 17:44:07 -040044 mysqli_query($dbh, $query);
gobrien67c5a052008-04-17 19:03:42 +000045
46 $query = "update translations set is_active = 1 where string_id = $string_id and language_id = $language_id and version = $max";
kitlo1d027092018-04-19 17:44:07 -040047 mysqli_query($dbh, $query);
gobrien67c5a052008-04-17 19:03:42 +000048 }
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";
kitlo1d027092018-04-19 17:44:07 -040054mysqli_query($dbh, $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";
kitlo1d027092018-04-19 17:44:07 -040059$res = mysqli_query($dbh, $query);
60while($row = mysqli_fetch_assoc($res)){
gobrien67c5a052008-04-17 19:03:42 +000061 $file_ids[] = $row['file_id'];
62}
63//get all the langs
64$query = "select language_id from languages";
kitlo1d027092018-04-19 17:44:07 -040065$res = mysqli_query($dbh, $query);
66while($row = mysqli_fetch_assoc($res)){
gobrien67c5a052008-04-17 19:03:42 +000067 $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";
kitlo1d027092018-04-19 17:44:07 -040073mysqli_query($dbh, $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";
kitlo1d027092018-04-19 17:44:07 -040082$res = mysqli_query($dbh, $query);
83while($row = mysqli_fetch_assoc($res)){
droyf142fc32008-05-21 20:53:43 +000084 $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
kitlo1d027092018-04-19 17:44:07 -040090 $res_f = mysqli_query($dbh, $query);
91 while($row_f = mysqli_fetch_assoc($res_f)){
droyf142fc32008-05-21 20:53:43 +000092 # 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 . "... ";
kitlo1d027092018-04-19 17:44:07 -040096 mysqli_query($dbh, $query);
97 print mysqli_affected_rows($dbh) . " rows deleted\n";
droyf142fc32008-05-21 20:53:43 +000098
99 # delete strings
100 $query = "delete from strings where file_id = '" . $row_f['file_id'] . "'";
101 print $query . "... ";
kitlo1d027092018-04-19 17:44:07 -0400102 mysqli_query($dbh, $query);
103 print mysqli_affected_rows($dbh) . " rows deleted\n";
droyf142fc32008-05-21 20:53:43 +0000104
105 # delete strings
106 $query = "delete from files where file_id = '" . $row_f['file_id'] . "'";
107 print $query . "... ";
kitlo1d027092018-04-19 17:44:07 -0400108 mysqli_query($dbh, $query);
109 print mysqli_affected_rows($dbh) . " rows deleted\n";
droyf142fc32008-05-21 20:53:43 +0000110
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 ";
kitlo1d027092018-04-19 17:44:07 -0400132 $max = mysqli_fetch_assoc(mysqli_query($dbh, $query));
gobrien964d4642008-02-16 00:30:26 +0000133 $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";
kitlo1d027092018-04-19 17:44:07 -0400136// mysqli_query($dbh, $query);
kitlo6c07cfa2018-05-11 01:46:03 -0400137 print mysqli_error();
gobrien964d4642008-02-16 00:30:26 +0000138
139 }elseif($found_active > 1){
140 $query = "select max(version) as max from translations where string_id = $string_id and language_id = $language_id ";
kitlo1d027092018-04-19 17:44:07 -0400141 $max = mysqli_fetch_assoc(mysqli_query($dbh, $query));
gobrien964d4642008-02-16 00:30:26 +0000142 $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";
kitlo1d027092018-04-19 17:44:07 -0400145// mysqli_query($dbh, $query);
kitlo6c07cfa2018-05-11 01:46:03 -0400146 print mysqli_error();
gobrien964d4642008-02-16 00:30:26 +0000147
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";
kitlo1d027092018-04-19 17:44:07 -0400150// mysqli_query($dbh, $query);
kitlo6c07cfa2018-05-11 01:46:03 -0400151 print mysqli_error();
gobrien964d4642008-02-16 00:30:26 +0000152
153 }
154 }
155}
gobrien67c5a052008-04-17 19:03:42 +0000156 */
157
gobrien964d4642008-02-16 00:30:26 +0000158
159?>