droy | 010bf7f | 2008-04-08 14:07:44 +0000 | [diff] [blame] | 1 | <?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.org | cd63239 | 2015-11-12 23:10:41 +0900 | [diff] [blame] | 12 | * Satoru Yoshida - [470121] scoreboard could be removed if no needed |
droy | 010bf7f | 2008-04-08 14:07:44 +0000 | [diff] [blame] | 13 | *******************************************************************************/ |
| 14 | |
| 15 | /* |
| 16 | * This is a cronjob-driven database maintenance script |
| 17 | * It is run every 15 minutes |
| 18 | */ |
| 19 | |
droy | 0fed43f | 2009-02-02 20:10:21 +0000 | [diff] [blame] | 20 | require_once(dirname(__FILE__) . "/../system/backend_functions.php"); |
atoulme | 3ac5261 | 2009-02-02 13:14:39 +0000 | [diff] [blame] | 21 | global $addon; |
| 22 | $context = $addon->callHook('context'); |
droy | 010bf7f | 2008-04-08 14:07:44 +0000 | [diff] [blame] | 23 | |
atoulme | 843359e | 2009-02-03 13:28:54 +0000 | [diff] [blame] | 24 | require(dirname(__FILE__) . "/../system/dbconnection.class.php"); |
droy | 010bf7f | 2008-04-08 14:07:44 +0000 | [diff] [blame] | 25 | |
atoulme | 3ac5261 | 2009-02-02 13:14:39 +0000 | [diff] [blame] | 26 | |
droy | 010bf7f | 2008-04-08 14:07:44 +0000 | [diff] [blame] | 27 | if($context == "") { |
| 28 | $context = "staging"; |
| 29 | } |
| 30 | $dbc = new DBConnection(); |
| 31 | $dbh = $dbc->connect(); |
| 32 | |
| 33 | |
droy | dc29484 | 2008-05-21 17:38:57 +0000 | [diff] [blame] | 34 | # refresh the scoreboard -- not every 15 minutes! |
droy | 4da49d2 | 2008-10-08 20:33:50 +0000 | [diff] [blame] | 35 | $forceRefresh = strcasecmp(getenv("FORCE_BABEL_REFRESH"), "true"); |
droy | e77ad17 | 2009-05-04 17:35:56 +0000 | [diff] [blame] | 36 | if(rand(1, 100) < 25 || $forceRefresh) { |
atoulme | d5c6d61 | 2009-02-03 13:30:01 +0000 | [diff] [blame] | 37 | require_once(dirname(__FILE__) . "/../system/scoreboard.class.php"); |
droy | b156beb | 2008-05-15 17:16:44 +0000 | [diff] [blame] | 38 | $sb = new Scoreboard(); |
syoshida@git.eclipse.org | cd63239 | 2015-11-12 23:10:41 +0900 | [diff] [blame] | 39 | $sb->refresh($forceRefresh); |
droy | dc29484 | 2008-05-21 17:38:57 +0000 | [diff] [blame] | 40 | |
| 41 | # Refresh file progress |
| 42 | # This only needs to happen once in a while too. |
| 43 | # See also: babel-setup.sql |
droy | 55f7a26 | 2009-06-04 19:26:06 +0000 | [diff] [blame] | 44 | $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 |
droy | dc29484 | 2008-05-21 17:38:57 +0000 | [diff] [blame] | 45 | FROM files AS f |
| 46 | INNER JOIN languages as l ON l.is_active = 1 |
droy | 898d37d | 2008-09-24 15:08:23 +0000 | [diff] [blame] | 47 | LEFT JOIN strings as s ON (s.file_id = f.file_id AND s.is_active AND s.value <> '' AND s.non_translatable <> 1) |
droy | dc29484 | 2008-05-21 17:38:57 +0000 | [diff] [blame] | 48 | 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) |
| 50 | WHERE f.is_active = 1 |
droy | 55f7a26 | 2009-06-04 19:26:06 +0000 | [diff] [blame] | 51 | GROUP BY f.file_id, l.language_id |
| 52 | HAVING translate_percent > 0"; |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 53 | $rs = mysqli_query($dbh, $sql); |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 54 | while($myrow = mysqli_fetch_assoc($rs)) { |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 55 | mysqli_query($dbh, "INSERT INTO file_progress (file_id, language_id, pct_complete) |
droy | 55f7a26 | 2009-06-04 19:26:06 +0000 | [diff] [blame] | 56 | VALUES(" . $myrow['file_id'] . ", " . $myrow['language_id'] . ", " . $myrow['translate_percent'] . ") |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 57 | ON DUPLICATE KEY UPDATE pct_complete=" . $myrow['translate_percent']); |
droy | 55f7a26 | 2009-06-04 19:26:06 +0000 | [diff] [blame] | 58 | } |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 59 | mysqli_query($dbh, "DELETE FROM file_progress WHERE pct_complete = 0"); |
droy | b156beb | 2008-05-15 17:16:44 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | # Update project/version/language progress |
| 63 | $sql = "SELECT * FROM project_progress WHERE is_stale"; |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 64 | $rs = mysqli_query($dbh, $sql); |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 65 | while($myrow = mysqli_fetch_assoc($rs)) { |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 66 | mysqli_query($dbh, "LOCK TABLES project_progress WRITE, |
droy | b156beb | 2008-05-15 17:16:44 +0000 | [diff] [blame] | 67 | 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 |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 72 | "); |
droy | b156beb | 2008-05-15 17:16:44 +0000 | [diff] [blame] | 73 | $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']; |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 76 | mysqli_query($dbh, $sql); |
droy | b156beb | 2008-05-15 17:16:44 +0000 | [diff] [blame] | 77 | |
| 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 |
droy | 1ddae59 | 2008-07-28 14:13:03 +0000 | [diff] [blame] | 88 | ON (s.file_id = f.file_id AND s.is_active AND s.value <> '' AND s.non_translatable = 0) |
droy | b156beb | 2008-05-15 17:16:44 +0000 | [diff] [blame] | 89 | 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 |
droy | 1ddae59 | 2008-07-28 14:13:03 +0000 | [diff] [blame] | 93 | v.project_id = '" . addslashes($myrow['project_id']) . "' |
droy | b156beb | 2008-05-15 17:16:44 +0000 | [diff] [blame] | 94 | AND v.version = '" . addslashes($myrow['version']) . "' |
| 95 | )"; |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 96 | mysqli_query($dbh, $sql); |
kitlo | a59efea | 2018-05-11 12:40:40 -0400 | [diff] [blame] | 97 | echo mysqli_error($dbh); |
droy | b156beb | 2008-05-15 17:16:44 +0000 | [diff] [blame] | 98 | |
| 99 | # Let's lock and unlock in the loop to allow other queries to go through. There's no rush on completing these stats. |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 100 | mysqli_query($dbh, "UNLOCK TABLES"); |
droy | b156beb | 2008-05-15 17:16:44 +0000 | [diff] [blame] | 101 | sleep(2); |
| 102 | } |
droy | 4da49d2 | 2008-10-08 20:33:50 +0000 | [diff] [blame] | 103 | ?> |