blob: 8909a79c24952a1aa46a2ea09c52a2c033db4603 [file] [log] [blame]
droy8d8c2ce2008-04-08 01:44:40 +00001<?php
2/*******************************************************************************
3 * Copyright (c) 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 * 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");
syoshida7da3d822015-10-12 17:11:51 +090030 $sql = "INSERT INTO _tmp_scoreboard SELECT NULL, 'LANGPR', IF(ISNULL(b.locale),b.name,CONCAT(b.name, CONCAT(' (', CONCAT(b.locale, ')')))), count(a.string_id) as cnt from translations as a inner join languages as b on b.language_id = a.language_id where a.created_on > (NOW() - INTERVAL 1 YEAR) and a.value <> '' and a.is_active = 1 group by a.language_id order by cnt desc limit 20";
kitlo2c8d8a92018-04-19 13:25:09 -040031 mysqli_query($dbh, $sql);
syoshida7da3d822015-10-12 17:11:51 +090032 $sql = "INSERT INTO _tmp_scoreboard SELECT NULL, 'TOPTR', CONCAT(first_name, IF(ISNULL(last_name),'',CONCAT(' ', last_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 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?>