blob: 4af28bc08a6ea1e114de1f7d2c84cf8e9c4d5593 [file] [log] [blame]
droy8d8c2ce2008-04-08 01:44:40 +00001<?php
2/*******************************************************************************
droyc0ace1b2019-09-23 16:12:05 -04003 * Copyright (c) 2008-2019 Eclipse Foundation and others.
droy8d8c2ce2008-04-08 01:44:40 +00004 * 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 * Foundation - initial API and implementation
syoshida7da3d822015-10-12 17:11:51 +090011 * Satoru Yoshida - [470121] scoreboard could be removed if no needed
droy8d8c2ce2008-04-08 01:44:40 +000012*******************************************************************************/
13
14class Scoreboard {
15
syoshida@git.eclipse.orgcd632392015-11-12 23:10:41 +090016 public function refresh($forceRefresh) {
droy010bf7f2008-04-08 14:07:44 +000017 global $dbh;
syoshida7da3d822015-10-12 17:11:51 +090018 $sql = "SELECT quantity FROM scoreboard " .
19 "WHERE itemid = 'LASGEN' " .
20 "AND quantity < (SELECT MAX(translation_id) as t FROM translations)";
21
kitlo2c8d8a92018-04-19 13:25:09 -040022 $result = mysqli_query($dbh, $sql);
kitlo1d027092018-04-19 17:44:07 -040023 if(($result && mysqli_num_rows($result) > 0) || $forceRefresh) {
droy010bf7f2008-04-08 14:07:44 +000024
droy8d8c2ce2008-04-08 01:44:40 +000025 # "lock" the scoreboard so that 2 clients don't update it simultaneously
kitlo2c8d8a92018-04-19 13:25:09 -040026 mysqli_query($dbh, "UPDATE scoreboard SET quantity = 9999999999 WHERE itemid = 'LASGEN'");
droy8d8c2ce2008-04-08 01:44:40 +000027
28 # rebuilding the scoreboard takes time ... dump stuff to tmp
kitlo2c8d8a92018-04-19 13:25:09 -040029 mysqli_query($dbh, "CREATE TEMPORARY TABLE _tmp_scoreboard LIKE scoreboard");
Denis Roy877a4e42019-09-24 09:35:04 -040030 $sql = "INSERT INTO _tmp_scoreboard SELECT NULL, 'LANGPR', IF(ISNULL(b.locale),b.name,CONCAT(b.name, CONCAT(' (', CONCAT(b.locale, ')')))) AS language, ROUND(COUNT(t.string_id) / COUNT(s.string_id) * 100,1) as tr_pct FROM strings as s inner join languages as b left join translations as t ON s.string_id = t.string_id AND t.is_active and t.language_id = b.language_id where s.created_on > (NOW() - INTERVAL 1 YEAR) and s.value <> '' and s.is_active = 1 group by b.language_id order by tr_pct desc limit 20";
kitlo2c8d8a92018-04-19 13:25:09 -040031 mysqli_query($dbh, $sql);
droyc0ace1b2019-09-23 16:12:05 -040032 $sql = "INSERT INTO _tmp_scoreboard SELECT NULL, 'TOPTR', CONCAT(first_name, IF(ISNULL(last_name),'',CONCAT(' ', last_name))) AS name, count(t.string_id) as cnt from translations as t inner join users as u on u.userid = t.userid where t.created_on > (NOW() - INTERVAL 1 YEAR) and t.value <> '' and t.is_active=1 group by first_name, last_name having name <> 'Babel Syncup' order by cnt desc limit 20";
kitlo2c8d8a92018-04-19 13:25:09 -040033 mysqli_query($dbh, $sql);
droy8d8c2ce2008-04-08 01:44:40 +000034
droy010bf7f2008-04-08 14:07:44 +000035 $sql = "INSERT INTO _tmp_scoreboard SELECT NULL, 'LASGEN', 'Scoreboard Last Generated', MAX(translation_id) FROM translations";
kitlo2c8d8a92018-04-19 13:25:09 -040036 mysqli_query($dbh, $sql);
droyd664f912008-05-14 15:45:10 +000037
38 $sql = "INSERT INTO _tmp_scoreboard SELECT NULL, 'LGNOW', 'Scoreboard Last Generated Date/Time', NOW()";
kitlo2c8d8a92018-04-19 13:25:09 -040039 mysqli_query($dbh, $sql);
droy010bf7f2008-04-08 14:07:44 +000040
kitlo2c8d8a92018-04-19 13:25:09 -040041 mysqli_query($dbh, "LOCK TABLES scoreboard WRITE");
42 mysqli_query($dbh, "DELETE FROM scoreboard");
43 mysqli_query($dbh, "INSERT INTO scoreboard SELECT * FROM _tmp_scoreboard");
44 mysqli_query($dbh, "UNLOCK TABLES");
45 mysqli_query($dbh, "DROP TABLE _tmp_scoreboard");
droy8d8c2ce2008-04-08 01:44:40 +000046 }
47 }
48}
syoshida7da3d822015-10-12 17:11:51 +090049?>