From c9e3767d99f7d01d95e7030441af1becc81e39ae Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Thu, 7 Nov 2024 12:00:42 -0800 Subject: [PATCH 1/4] Move getting language info into library so no SQL queries in revcheck.php --- include/lib_revcheck.inc.php | 7 +++++++ www/revcheck.php | 28 +++++++++++++--------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/include/lib_revcheck.inc.php b/include/lib_revcheck.inc.php index ce534a0..2da551f 100644 --- a/include/lib_revcheck.inc.php +++ b/include/lib_revcheck.inc.php @@ -20,6 +20,13 @@ +----------------------------------------------------------------------+ */ +function get_language_intro($idx, $lang) +{ + $result = $idx->query("SELECT intro FROM descriptions WHERE lang = '$lang'"); + $answer = $result->fetchArray(); + return is_array($answer) ? $answer[0] : null; +} + // Return an array of directory containing outdated files function get_dirs($idx, $lang) { $sql = "SELECT diff --git a/www/revcheck.php b/www/revcheck.php index 41ccd35..ce16b02 100644 --- a/www/revcheck.php +++ b/www/revcheck.php @@ -33,24 +33,24 @@ $DBLANG = SQLITE_DIR . 'rev.php.sqlite'; -// Check if db connection can be established and if revcheck for requested lang exists -if ($dbhandle = new SQLite3($DBLANG)) { - $check_lang_tmp = $dbhandle->query("SELECT COUNT(lang) AS count FROM descriptions WHERE lang = '$lang'"); - $check_lang = $check_lang_tmp->fetchArray(); - if ($lang != 'en' && $check_lang['count'] < 0) { - site_header(); - echo "

This revision check doesn't exist yet.

"; - site_footer(); - die; - } -} -else { +$dbhandle = new SQLite3($DBLANG); +if (!$dbhandle) { site_header(); echo "

Database connection couldn't be established

"; site_footer(); die; } +// Check if db connection can be established and if revcheck for requested lang exists +$lang_intro = get_language_intro($dbhandle, $lang); + +if ($lang !== 'en' && is_null($lang_intro)) { + site_header(); + echo "

This revision check doesn't exist yet.

"; + site_footer(); + die; +} + site_header(); switch($tool) { case 'translators': @@ -428,10 +428,8 @@ $sidebar = nav_languages(); site_footer($sidebar); } else { - $intro_result = $dbhandle->query("SELECT intro FROM descriptions WHERE lang = '$lang'"); - $intro = $intro_result->fetchArray(); echo '

Intro for language

'; - echo '

'.$intro[0].'

'; + echo '

'.$lang_intro.'

'; echo 'info'; echo gen_date($DBLANG); echo '

Links to available tools are placed on the right sidebar.

'; From c9d711f8f384667474a67c1dc2718d62f7c4140a Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Thu, 7 Nov 2024 16:57:10 -0800 Subject: [PATCH 2/4] Handle new SQLite database format generated --- include/lib_revcheck.inc.php | 283 +++++++++++++++++------------------ www/img-status-all.php | 9 +- www/img-status-lang.php | 16 +- www/revcheck.php | 148 ++++++------------ 4 files changed, 194 insertions(+), 262 deletions(-) diff --git a/include/lib_revcheck.inc.php b/include/lib_revcheck.inc.php index 2da551f..882452b 100644 --- a/include/lib_revcheck.inc.php +++ b/include/lib_revcheck.inc.php @@ -20,27 +20,35 @@ +----------------------------------------------------------------------+ */ -function get_language_intro($idx, $lang) -{ - $result = $idx->query("SELECT intro FROM descriptions WHERE lang = '$lang'"); +$TRANSLATION_STATUSES = [ + 'TranslatedOk' => 'Up to date', + 'TranslatedOld' => 'Outdated', + 'TranslatedWip' => 'Work in progress', + 'RevTagProblem' => 'No revision tag', + 'NotInEnTree' => 'Not in EN tree', + 'Untranslated' => 'Available for translation', +]; + +function get_language_intro($idx, $lang) { + $result = $idx->query("SELECT intro FROM languages WHERE lang = '$lang'"); $answer = $result->fetchArray(); return is_array($answer) ? $answer[0] : null; } // Return an array of directory containing outdated files function get_dirs($idx, $lang) { - $sql = "SELECT - d.path AS dir - FROM - translated a, - dirs d - WHERE - a.lang = '$lang' - AND a.id = d.id - AND (a.syncStatus = 'TranslatedOld' - OR a.syncStatus = 'TranslatedWip') - ORDER BY - d.id"; + $sql = <<query($sql); @@ -55,34 +63,39 @@ function get_dirs($idx, $lang) { // return an array with the outdated files; can be optionally filtered by user or dir function get_outdated_files($idx, $lang, $filter = null, $value = null) { - $sql = "SELECT a.status, a.name AS file, a.maintainer, a.additions, a.deletions, c.revision AS en_rev, a.revision AS trans_rev, b.path AS dir - FROM translated a, dirs b, enfiles c - WHERE a.lang = '$lang' - AND c.name = a.name AND b.id = a.id AND b.id = c.id - AND (a.syncStatus = 'TranslatedOld' - OR a.syncStatus = 'TranslatedWip')"; - - if ($filter == 'dir') { - $sql .= " AND b.path = '$value'"; - } - elseif ($filter == 'translator') { - $sql .= ' AND a.maintainer = "'.SQLite3::escapeString($value).'"'; - } - - $sql .= ' ORDER BY b.path'; + $value = SQLite3::escapeString($value ?? ''); + + $sql_filter = match ($filter) { + 'dir' => "AND path = '{$value}'", + 'translator' => "AND maintainer = '{$value}'", + default => '' + }; + + $sql = <<query($sql); $tmp = array(); - while ($r = $result->fetchArray()) { - $tmp[] = array( - 'file' => $r['file'], - 'en_rev' => $r['en_rev'], - 'trans_rev' => $r['trans_rev'], - 'status' => $r['status'], - 'maintainer' => $r['maintainer'], - 'name' => $r['dir'], - 'additions' => $r['additions'], - 'deletions' => $r['deletions']); + while ($r = $result->fetchArray(SQLITE3_ASSOC)) { + $tmp[] = $r; } return $tmp; @@ -91,7 +104,7 @@ function get_outdated_files($idx, $lang, $filter = null, $value = null) // Return an array of available languages for manual function revcheck_available_languages($idx) { - $result = $idx->query('SELECT lang FROM descriptions'); + $result = $idx->query('SELECT lang FROM languages'); while ($row = $result->fetchArray(SQLITE3_NUM)) { $tmp[] = $row[0]; } @@ -99,39 +112,26 @@ function revcheck_available_languages($idx) return $tmp; } - -// Return en integer -function count_en_files($idx) -{ - $sql = "SELECT COUNT(name) FROM enfiles"; - $res = $idx->query($sql); - $row = $res->fetchArray(); - return $row[0]; -} - function get_missfiles($idx, $lang) { - $sql = "SELECT - d.path as dir, - a.name as file, - b.revision as revision, - a.size as size - FROM - Untranslated a, - enfiles b, - dirs d - WHERE - a.lang = '$lang' - AND - a.name = b.name - AND - a.id = b.id - AND - a.id = d.id"; + $sql = <<query($sql); - while ($r = $result->fetchArray()) { - $tmp[] = array('dir' => $r['dir'], 'size' => $r['size'], 'revision' => $r['revision'], 'file' => $r['file']); + while ($r = $result->fetchArray(SQLITE3_ASSOC)) { + $tmp[] = $r; } return $tmp; @@ -139,26 +139,36 @@ function get_missfiles($idx, $lang) function get_oldfiles($idx, $lang) { - $sql = "SELECT path, name, size - FROM notinen - WHERE lang = '$lang'"; + $sql = <<query($sql); $tmp = array(); - while ($r = $result->fetchArray()) { - $tmp[] = array('dir' => $r['path'], 'size' => $r['size'], 'file' => $r['name']); + while ($r = $result->fetchArray(SQLITE3_ASSOC)) { + $tmp[] = $r; } return $tmp; } function get_misstags($idx, $lang) { - $sql = "SELECT d.path AS dir, a.size AS en_size, b.size AS trans_size, a.name AS name - FROM enfiles a, translated b, dirs d - WHERE b.lang = '$lang' AND b.syncStatus = 'RevTagProblem' - AND a.id = b.id AND a.name = b.name AND a.id = d.id - ORDER BY dir, name"; + $sql = <<query($sql); while($row = $result->fetchArray()) { @@ -168,83 +178,62 @@ function get_misstags($idx, $lang) return $tmp; } -/** - * Returns translators' stats of specified $lang - * Replaces old translator_get_wip(), translator_get_old(), - * translator_get_critical() and translator_get_uptodate() functions - * - * @param string $status one of [uptodate, old, critical, wip] - * @return array - */ -function get_translators_stats($idx, $lang, $status) { - if ($status == 'wip') { // special case, ehh; does anyone still use this status? - $sql = "SELECT files_wip AS total, nick AS maintainer - FROM translators - WHERE lang = '$lang' - GROUP BY maintainer"; - } elseif ($status == 'uptodate') { - $sql = "SELECT files_uptodate AS total, nick AS maintainer - FROM translators - WHERE lang = '$lang' - GROUP BY maintainer"; - } elseif ($status == 'outdated') { - $sql = "SELECT files_outdated AS total, nick AS maintainer - FROM translators - WHERE lang = '$lang' - GROUP BY maintainer"; - } - $result = $idx->query($sql); - $tmp = array(); - while ($r = $result->fetchArray()) { - $tmp[$r['maintainer']] = $r['total']; - } - - return $tmp; -} - function get_translators($idx, $lang) { - $sql = "SELECT nick, name, mail, vcs FROM translators WHERE lang = '$lang' ORDER BY nick COLLATE NOCASE"; - $persons = array(); + $sql = <<query($sql); - while ($r = $result->fetchArray()) { - $persons[$r['nick']] = array('name' => $r['name'], 'mail' => $r['mail'], 'karma' => $r['vcs']); + while ($r = $result->fetchArray(SQLITE3_ASSOC)) { + $persons[$r['nick']] = $r; } return $persons; } -/** - * Returns statistics of specified $lang - * Replaces old get_stats_uptodate(), get_stats_old(), - * get_stats_critical(), get_stats_wip(), get_stats_notrans() - * and get_stats_notag() functions - * - * @param string $status one of [uptodate, old, critical, wip, notrans, norev] - * @return array +/* + * Returns statistics for specified language */ -function get_stats($idx, $lang, $status) { - $sql = "SELECT COUNT(a.name) AS total, SUM(b.size) AS size - FROM translated a, enfiles b - WHERE a.lang = '$lang' AND a.id = b.id AND a.name = b.name AND "; - if ($status == 'wip') { - $sql .= "a.syncStatus = 'TranslatedWip'"; - } elseif ($status == 'notrans') { - $sql = "SELECT COUNT(name) AS total, SUM(size) AS size - FROM Untranslated - WHERE lang = '$lang'"; - } elseif ($status == 'uptodate') { - $sql .= "a.syncStatus = 'TranslatedOk'"; - } elseif ($status == 'outdated') { - $sql .= "syncStatus = 'TranslatedOld'"; - } elseif ($status == 'norev') { - $sql .= "syncStatus = 'RevTagProblem'"; - } else { //notinen - $sql = "SELECT COUNT(name) AS total, SUM(size) AS size - FROM notinen WHERE lang = '$lang'"; +function get_lang_stats($idx, $lang) { + $sql = <<query($sql); + + $stats = []; + $total = [ 'total' => 0, 'size' => 0 ]; + while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + $stats[$row['status']] = $row; + if ($row['status'] != 'NotInEnTree') { + $total['total'] += $row['total']; + $total['size'] += $row['size']; + } + } + + if ($total['total'] > 0) { + $stats['total'] = $total; } - $result = $idx->query($sql)->fetchArray(); - return array($result['total'], $result['size']); + + return $stats; } function showdiff () diff --git a/www/img-status-all.php b/www/img-status-all.php index 6e2f5f8..59a5b4f 100644 --- a/www/img-status-all.php +++ b/www/img-status-all.php @@ -5,16 +5,17 @@ require_once __DIR__ . '/../include/init.inc.php'; require_once __DIR__ . '/../include/lib_revcheck.inc.php'; -$idx = new SQLite3(SQLITE_DIR . 'rev.php.sqlite'); +$idx = new SQLite3(SQLITE_DIR . 'status.sqlite'); $language = revcheck_available_languages($idx); sort($language); -$files_EN = count_en_files($idx); foreach ($language as $lang) { - $tmp = get_stats($idx, $lang, 'uptodate'); + $stats = get_lang_stats($idx, $lang); - $percent_tmp[] = round($tmp[0] * 100 / $files_EN); + if (!$stats) die("No stats for $lang"); + + $percent_tmp[] = round($stats['TranslatedOk']['total'] * 100 / $stats['total']['total']); $legend_tmp[] = $lang; } diff --git a/www/img-status-lang.php b/www/img-status-lang.php index 183223e..ba54520 100644 --- a/www/img-status-lang.php +++ b/www/img-status-lang.php @@ -8,7 +8,7 @@ require_once __DIR__ . '/../include/lib_revcheck.inc.php'; require_once __DIR__ . '/../include/lib_proj_lang.inc.php'; -$idx = new SQLite3(SQLITE_DIR . 'rev.php.sqlite'); +$idx = new SQLite3(SQLITE_DIR . 'status.sqlite'); $available_langs = revcheck_available_languages($idx); @@ -23,17 +23,15 @@ function generate_image($lang, $idx) { global $LANGUAGES; - $up_to_date = get_stats($idx, $lang, 'uptodate'); - $up_to_date = $up_to_date[0]; + $stats = get_lang_stats($idx, $lang); + + $up_to_date = $stats['TranslatedOk']['total'] ?? 0; // - $outdated = @get_stats($idx, $lang, 'outdated'); - $outdated = $outdated[0]; + $outdated = $stats['TranslatedOld']['total'] ?? 0; // - $missing = get_stats($idx, $lang, 'notrans'); - $missing = $missing[0]; + $missing = $stats['Untranslated']['total'] ?? 0; // - $no_tag = @get_stats($idx, $lang, 'norev'); - $no_tag = $no_tag[0]; + $no_tag = $stats['RevTagProblem']['total'] ?? 0; $data = array( $up_to_date, diff --git a/www/revcheck.php b/www/revcheck.php index ce16b02..28e2bc0 100644 --- a/www/revcheck.php +++ b/www/revcheck.php @@ -31,7 +31,7 @@ die; } -$DBLANG = SQLITE_DIR . 'rev.php.sqlite'; +$DBLANG = SQLITE_DIR . 'status.sqlite'; $dbhandle = new SQLite3($DBLANG); if (!$dbhandle) { @@ -60,18 +60,14 @@ echo '

Error: no translators info found in database.

'; } else { - $uptodate = get_translators_stats($dbhandle, $lang, 'uptodate'); - $outdated = get_translators_stats($dbhandle, $lang, 'outdated'); - $wip = get_translators_stats($dbhandle, $lang, 'wip'); - foreach($translators as $nick =>$data) { - $files_w[$nick] = array('uptodate' => '', 'outdated' => '', 'norev' => '', 'wip' => ''); - $files_w[$nick]['uptodate'] = isset($uptodate[$nick]) ? $uptodate[$nick] : ''; - $files_w[$nick]['wip'] = isset($wip[$nick]) ? $wip[$nick] : ''; - $files_w[$nick]['outdated'] = isset($outdated[$nick]) ? $outdated[$nick] : ''; - } + $files_w[$nick] = array('uptodate' => '', 'outdated' => '', 'norev' => '', 'wip' => ''); + $files_w[$nick]['uptodate'] = $data['countOk']; + $files_w[$nick]['wip'] = $data['countOther']; + $files_w[$nick]['outdated'] = $data['countOld']; + } - echo << Name @@ -87,19 +83,19 @@ TRANSLATORS_HEAD; - foreach ($translators as $nick => $data) { - echo '', - ''.$data['name'].'', - ''.$nick.'', - ''.(($data['karma'] == 'yes') ? '✓' : ' ').'', - '' , @$files_w[$nick]['uptodate'], '', - '' , $files_w[$nick]['outdated'], '', - '', $files_w[$nick]['wip'], '', - '' , @array_sum($files_w[$nick]), '', - ''; - } - echo ''; - } + foreach ($translators as $nick => $data) { + echo '', + ''.$data['name'].'', + ''.$nick.'', + ''.(($data['karma'] == 'yes') ? '✓' : ' ').'', + '' , @$files_w[$nick]['uptodate'], '', + '' , $files_w[$nick]['outdated'], '', + '', $files_w[$nick]['wip'], '', + '' , @array_sum($files_w[$nick]), '', + ''; + } + echo ''; + } echo gen_date($DBLANG); break; @@ -209,88 +205,36 @@ break; case 'filesummary': - $files_uptodate = get_stats($dbhandle, $lang, 'uptodate'); - $files_outdated = get_stats($dbhandle, $lang, 'outdated'); - $files_norev = get_stats($dbhandle, $lang, 'norev'); - $files_notrans = get_stats($dbhandle, $lang, 'notrans'); - $files_wip = get_stats($dbhandle, $lang, 'wip'); - $files_notinen = get_stats($dbhandle, $lang, 'notinen'); - - $files_outdated[1] = $files_outdated[1] > 0 ? $files_outdated[1] : 0; - $files_norev[1] = $files_norev[1] > 0 ? $files_norev[1] : 0; - $files_wip[1] = $files_wip[1] > 0 ? $files_wip[1] : 0; - $files_notinen[1] = $files_notinen[1] > 0 ? $files_notinen[1] : 0; + $stats = get_lang_stats($dbhandle, $lang); echo ''; echo ''; - $percent[0] = 0; - $percent[1] = 0; - $count = count_en_files($dbhandle); - - $percent[1] += $files_uptodate[1]; - $percent[1] += $files_outdated[1]; - $percent[1] += $files_norev[1]; - $percent[1] += $files_notrans[1]; - $percent[1] += $files_wip[1]; - - $num_uptodate_percent = number_format($files_uptodate[0] * 100 / $count, 2 ); - $num_outdated_percent = number_format($files_outdated[0] * 100 / $count, 2 ); - $num_wip_percent = number_format($files_wip[0] * 100 / $count, 2 ); - $num_norev_percent = number_format($files_norev[0] * 100 / $count, 2 ); - $num_notrans_percent = number_format($files_notrans[0] * 100 / $count, 2 ); - - $size_uptodate_percent = number_format($files_uptodate[1] * 100 / $percent[1], 2 ); - $size_outdated_percent = number_format($files_outdated[1] * 100 / $percent[1], 2 ); - $size_wip_percent = number_format($files_wip[1] * 100 / $percent[1], 2 ); - $size_norev_percent = number_format($files_norev[1] * 100 / $percent[1], 2 ); - $size_notrans_percent = number_format($files_notrans[1] * 100 / $percent[1], 2 ); - print << - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
File status typeNumber of filesPercent of filesSize of files (kB)Percent of size
Up to date files{$files_uptodate[0]}{$num_uptodate_percent}%{$files_uptodate[1]}{$size_uptodate_percent}%
Outdated files{$files_outdated[0]}{$num_outdated_percent}%{$files_outdated[1]}{$size_outdated_percent}%
Work in progress{$files_wip[0]}{$num_wip_percent}%{$files_wip[1]}{$size_wip_percent}%
Files without revision number{$files_norev[0]}{$num_norev_percent}%$files_norev[1]{$size_norev_percent}%
Not in EN tree{$files_notinen[0]}0.00%{$files_notinen[1]}0.00%
Files available for translation {$files_notrans[0]}{$num_notrans_percent}%{$files_notrans[1]}{$size_notrans_percent}%
Files total$count100%{$percent[1]}100%
-HTML; - echo gen_date($DBLANG); + foreach ($TRANSLATION_STATUSES as $status => $description) { + echo + '', + '', $description, '', + '', $stats[$status]['total'] ?? 0, '', + '', + sprintf('%.2f%%', 100 * (($stats[$status]['total'] ?? 0) / $stats['total']['total'])), + '', + '', $stats[$status]['size'] ?? 0, '', + '', + sprintf('%.2f%%', 100 * (($stats[$status]['size'] ?? 0) / $stats['total']['size'])), + '', + ''; + } + echo + '', + 'Total', + '', $stats['total']['total'] ?? 0, '', + '100.00%', + '', $stats['total']['size'] ?? 0, '', + '100.00%', + ''; + echo ''; + + echo gen_date($DBLANG); break; From 59a4a2e4ee7a874955125449c8570db467673dc8 Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Thu, 7 Nov 2024 17:01:44 -0800 Subject: [PATCH 3/4] Remove old scripts and 'build' config support --- build-ops.php.sample | 5 - build-ops.sample | 10 - include/init.inc.php | 27 +- scripts/gen_doc_activity_email.php | 198 --------- scripts/generation.sh | 20 - scripts/populatedocs.sh | 51 --- scripts/rev.php | 640 ----------------------------- www/redirect.php | 1 - 8 files changed, 11 insertions(+), 941 deletions(-) delete mode 100644 build-ops.php.sample delete mode 100644 build-ops.sample delete mode 100644 scripts/gen_doc_activity_email.php delete mode 100755 scripts/generation.sh delete mode 100755 scripts/populatedocs.sh delete mode 100644 scripts/rev.php diff --git a/build-ops.php.sample b/build-ops.php.sample deleted file mode 100644 index abbfd05..0000000 --- a/build-ops.php.sample +++ /dev/null @@ -1,5 +0,0 @@ - | -+----------------------------------------------------------------------+ - -Notes: - - This emails the documentation list each # days (7, via cron) with - PHP documentation activity information. - - These are only numbers/statistics, so there are no winners or - losers except for the documentation. -Todo: - - Add SVN lines changed/added/deleted instead of # commits - - Add other bug activities? So, not only bug->closed? - - Determine if posting statistics is wise (good or bad) -*/ - -// build-ops.php is generated by web/doc/trunk/ setup -require '../build-ops.php'; - -date_default_timezone_set('UTC'); - -define('DEBUG_MODE', FALSE); // Enable to not send emails. -define('DAYS_LOOKUP', 7); // Number of days, in the past, to search/use for the report - -$svn_modules = array('phpdoc', 'phd', 'web/doc-editor'); -$time_past = date('Y-m-d', strtotime('-'. DAYS_LOOKUP . ' days')); -$time_future = date('Y-m-d', strtotime('+'. DAYS_LOOKUP . ' days')); -$time_now = date('Y-m-d'); - -if (!function_exists('sqlite_open')) { - echo 'Fail. I require ext/sqlite to work.', PHP_EOL; - exit; -} -if (!function_exists('simplexml_load_string')) { - echo 'Fail. I require ext/simplexml to work.', PHP_EOL; - exit; -} - -$email_text = <<