blob: 570f9a34c92dc8ead45f2c1b855c3f45e3f190df [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
12*******************************************************************************/
13
14 /*
15 * This is a cronjob-driven database maintenance script
16 * It is run every 15 minutes
17 */
18
droy0fed43f2009-02-02 20:10:21 +000019 require_once(dirname(__FILE__) . "/../system/backend_functions.php");
atoulme3ac52612009-02-02 13:14:39 +000020 global $addon;
21 $context = $addon->callHook('context');
droy010bf7f2008-04-08 14:07:44 +000022
atoulme843359e2009-02-03 13:28:54 +000023 require(dirname(__FILE__) . "/../system/dbconnection.class.php");
droy010bf7f2008-04-08 14:07:44 +000024
atoulme3ac52612009-02-02 13:14:39 +000025
droy010bf7f2008-04-08 14:07:44 +000026 if($context == "") {
27 $context = "staging";
28 }
29 $dbc = new DBConnection();
30 $dbh = $dbc->connect();
31
32
droydc294842008-05-21 17:38:57 +000033 # refresh the scoreboard -- not every 15 minutes!
droy4da49d22008-10-08 20:33:50 +000034 $forceRefresh = strcasecmp(getenv("FORCE_BABEL_REFRESH"), "true");
droye77ad172009-05-04 17:35:56 +000035 if(rand(1, 100) < 25 || $forceRefresh) {
atoulmed5c6d612009-02-03 13:30:01 +000036 require_once(dirname(__FILE__) . "/../system/scoreboard.class.php");
droyb156beb2008-05-15 17:16:44 +000037 $sb = new Scoreboard();
38 $sb->refresh();
droydc294842008-05-21 17:38:57 +000039
40 # Refresh file progress
41 # This only needs to happen once in a while too.
42 # See also: babel-setup.sql
droy55f7a262009-06-04 19:26:06 +000043 $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 +000044FROM files AS f
45 INNER JOIN languages as l ON l.is_active = 1
droy898d37d2008-09-24 15:08:23 +000046 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 +000047 LEFT JOIN translations AS t ON (s.string_id = t.string_id
48 AND t.language_id = l.language_id AND t.is_active = 1)
49WHERE f.is_active = 1
droy55f7a262009-06-04 19:26:06 +000050GROUP BY f.file_id, l.language_id
51HAVING translate_percent > 0";
52 $rs = mysql_query($sql, $dbh);
53 while($myrow = mysql_fetch_assoc($rs)) {
54 mysql_query("INSERT INTO file_progress (file_id, language_id, pct_complete)
55 VALUES(" . $myrow['file_id'] . ", " . $myrow['language_id'] . ", " . $myrow['translate_percent'] . ")
56 ON DUPLICATE KEY UPDATE pct_complete=" . $myrow['translate_percent'], $dbh);
57 }
droydc294842008-05-21 17:38:57 +000058 mysql_query("DELETE FROM file_progress WHERE pct_complete = 0", $dbh);
droyb156beb2008-05-15 17:16:44 +000059 }
60
61 # Update project/version/language progress
62 $sql = "SELECT * FROM project_progress WHERE is_stale";
63 $rs = mysql_query($sql, $dbh);
64 while($myrow = mysql_fetch_assoc($rs)) {
65 mysql_query("LOCK TABLES project_progress WRITE,
66 project_versions AS v READ,
67 files AS f READ,
68 strings AS s READ,
69 translations AS t READ,
70 languages AS l READ
71 ", $dbh);
72 $sql = "DELETE /* dbmaintenance_15min.php */ FROM project_progress where project_id = '" . addslashes($myrow['project_id']) . "'
73 AND version = '" . addslashes($myrow['version']) . "'
74 AND language_id = " . $myrow['language_id'];
75 mysql_query($sql, $dbh);
76
77 $sql = "INSERT /* dbmaintenance_15min.php */ INTO project_progress SET project_id = '" . addslashes($myrow['project_id']) . "',
78 version = '" . addslashes($myrow['version']) . "',
79 language_id = " . $myrow['language_id'] . ",
80 is_stale = 0,
81 pct_complete = (
82 SELECT IF(COUNT(s.string_id) > 0, ROUND(COUNT(t.string_id)/COUNT(s.string_id) * 100, 2), 0) AS pct_complete
83 FROM project_versions AS v
84 INNER JOIN files AS f
85 ON (f.project_id = v.project_id AND f.version = v.version AND f.is_active)
86 INNER JOIN strings AS s
droy1ddae592008-07-28 14:13:03 +000087 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 +000088 INNER JOIN languages AS l ON l.language_id = " . $myrow['language_id'] . "
89 LEFT JOIN translations AS t
90 ON (t.string_id = s.string_id AND t.language_id = l.language_id AND t.is_active)
91 WHERE
droy1ddae592008-07-28 14:13:03 +000092 v.project_id = '" . addslashes($myrow['project_id']) . "'
droyb156beb2008-05-15 17:16:44 +000093 AND v.version = '" . addslashes($myrow['version']) . "'
94 )";
droyb156beb2008-05-15 17:16:44 +000095 mysql_query($sql, $dbh);
96 echo mysql_error();
97
98 # Let's lock and unlock in the loop to allow other queries to go through. There's no rush on completing these stats.
99 mysql_query("UNLOCK TABLES", $dbh);
100 sleep(2);
101 }
droy4da49d22008-10-08 20:33:50 +0000102?>