blob: 23d448a0fe7b63badb4801e4cd462321d7c052c8 [file] [log] [blame]
droy010bf7f2008-04-08 14:07:44 +00001<?php
2
3/*******************************************************************************
4 * Copyright (c) 2008 Eclipse Foundation and others.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *
10 * Contributors:
11 * Eclipse Foundation - Initial API and implementation
syoshida@git.eclipse.orgcd632392015-11-12 23:10:41 +090012 * Satoru Yoshida - [470121] scoreboard could be removed if no needed
droy010bf7f2008-04-08 14:07:44 +000013*******************************************************************************/
14
15 /*
16 * This is a cronjob-driven database maintenance script
17 * It is run every 15 minutes
18 */
19
droy0fed43f2009-02-02 20:10:21 +000020 require_once(dirname(__FILE__) . "/../system/backend_functions.php");
atoulme3ac52612009-02-02 13:14:39 +000021 global $addon;
22 $context = $addon->callHook('context');
droy010bf7f2008-04-08 14:07:44 +000023
atoulme843359e2009-02-03 13:28:54 +000024 require(dirname(__FILE__) . "/../system/dbconnection.class.php");
droy010bf7f2008-04-08 14:07:44 +000025
atoulme3ac52612009-02-02 13:14:39 +000026
droy010bf7f2008-04-08 14:07:44 +000027 if($context == "") {
28 $context = "staging";
29 }
30 $dbc = new DBConnection();
31 $dbh = $dbc->connect();
32
33
droydc294842008-05-21 17:38:57 +000034 # refresh the scoreboard -- not every 15 minutes!
droy4da49d22008-10-08 20:33:50 +000035 $forceRefresh = strcasecmp(getenv("FORCE_BABEL_REFRESH"), "true");
droye77ad172009-05-04 17:35:56 +000036 if(rand(1, 100) < 25 || $forceRefresh) {
atoulmed5c6d612009-02-03 13:30:01 +000037 require_once(dirname(__FILE__) . "/../system/scoreboard.class.php");
droyb156beb2008-05-15 17:16:44 +000038 $sb = new Scoreboard();
syoshida@git.eclipse.orgcd632392015-11-12 23:10:41 +090039 $sb->refresh($forceRefresh);
droydc294842008-05-21 17:38:57 +000040
41 # Refresh file progress
42 # This only needs to happen once in a while too.
43 # See also: babel-setup.sql
droy55f7a262009-06-04 19:26:06 +000044 $sql = "select f.file_id, l.language_id, IF(COUNT(s.string_id) > 0, COUNT(t.string_id)/COUNT(s.string_id)*100,100) AS translate_percent
droydc294842008-05-21 17:38:57 +000045FROM files AS f
46 INNER JOIN languages as l ON l.is_active = 1
droy898d37d2008-09-24 15:08:23 +000047 LEFT JOIN strings as s ON (s.file_id = f.file_id AND s.is_active AND s.value <> '' AND s.non_translatable <> 1)
droydc294842008-05-21 17:38:57 +000048 LEFT JOIN translations AS t ON (s.string_id = t.string_id
49 AND t.language_id = l.language_id AND t.is_active = 1)
50WHERE f.is_active = 1
droy55f7a262009-06-04 19:26:06 +000051GROUP BY f.file_id, l.language_id
52HAVING translate_percent > 0";
kitlo2c8d8a92018-04-19 13:25:09 -040053 $rs = mysqli_query($dbh, $sql);
kitlo1d027092018-04-19 17:44:07 -040054 while($myrow = mysqli_fetch_assoc($rs)) {
kitlo2c8d8a92018-04-19 13:25:09 -040055 mysqli_query($dbh, "INSERT INTO file_progress (file_id, language_id, pct_complete)
droy55f7a262009-06-04 19:26:06 +000056 VALUES(" . $myrow['file_id'] . ", " . $myrow['language_id'] . ", " . $myrow['translate_percent'] . ")
kitlo2c8d8a92018-04-19 13:25:09 -040057 ON DUPLICATE KEY UPDATE pct_complete=" . $myrow['translate_percent']);
droy55f7a262009-06-04 19:26:06 +000058 }
kitlo2c8d8a92018-04-19 13:25:09 -040059 mysqli_query($dbh, "DELETE FROM file_progress WHERE pct_complete = 0");
droyb156beb2008-05-15 17:16:44 +000060 }
61
62 # Update project/version/language progress
63 $sql = "SELECT * FROM project_progress WHERE is_stale";
kitlo2c8d8a92018-04-19 13:25:09 -040064 $rs = mysqli_query($dbh, $sql);
kitlo1d027092018-04-19 17:44:07 -040065 while($myrow = mysqli_fetch_assoc($rs)) {
kitlo2c8d8a92018-04-19 13:25:09 -040066 mysqli_query($dbh, "LOCK TABLES project_progress WRITE,
droyb156beb2008-05-15 17:16:44 +000067 project_versions AS v READ,
68 files AS f READ,
69 strings AS s READ,
70 translations AS t READ,
71 languages AS l READ
kitlo2c8d8a92018-04-19 13:25:09 -040072 ");
droyb156beb2008-05-15 17:16:44 +000073 $sql = "DELETE /* dbmaintenance_15min.php */ FROM project_progress where project_id = '" . addslashes($myrow['project_id']) . "'
74 AND version = '" . addslashes($myrow['version']) . "'
75 AND language_id = " . $myrow['language_id'];
kitlo2c8d8a92018-04-19 13:25:09 -040076 mysqli_query($dbh, $sql);
droyb156beb2008-05-15 17:16:44 +000077
78 $sql = "INSERT /* dbmaintenance_15min.php */ INTO project_progress SET project_id = '" . addslashes($myrow['project_id']) . "',
79 version = '" . addslashes($myrow['version']) . "',
80 language_id = " . $myrow['language_id'] . ",
81 is_stale = 0,
82 pct_complete = (
83 SELECT IF(COUNT(s.string_id) > 0, ROUND(COUNT(t.string_id)/COUNT(s.string_id) * 100, 2), 0) AS pct_complete
84 FROM project_versions AS v
85 INNER JOIN files AS f
86 ON (f.project_id = v.project_id AND f.version = v.version AND f.is_active)
87 INNER JOIN strings AS s
droy1ddae592008-07-28 14:13:03 +000088 ON (s.file_id = f.file_id AND s.is_active AND s.value <> '' AND s.non_translatable = 0)
droyb156beb2008-05-15 17:16:44 +000089 INNER JOIN languages AS l ON l.language_id = " . $myrow['language_id'] . "
90 LEFT JOIN translations AS t
91 ON (t.string_id = s.string_id AND t.language_id = l.language_id AND t.is_active)
92 WHERE
droy1ddae592008-07-28 14:13:03 +000093 v.project_id = '" . addslashes($myrow['project_id']) . "'
droyb156beb2008-05-15 17:16:44 +000094 AND v.version = '" . addslashes($myrow['version']) . "'
95 )";
kitlo2c8d8a92018-04-19 13:25:09 -040096 mysqli_query($dbh, $sql);
kitloa59efea2018-05-11 12:40:40 -040097 echo mysqli_error($dbh);
droyb156beb2008-05-15 17:16:44 +000098
99 # Let's lock and unlock in the loop to allow other queries to go through. There's no rush on completing these stats.
kitlo2c8d8a92018-04-19 13:25:09 -0400100 mysqli_query($dbh, "UNLOCK TABLES");
droyb156beb2008-05-15 17:16:44 +0000101 sleep(2);
102 }
droy4da49d22008-10-08 20:33:50 +0000103?>