svn: /web/doc/trunk/ scripts/gen_doc_activity_email.php templates/emails/email-template-doc-activity.txt
[email protected] (Philip Olson)
| Newsgroups | php.doc.web |
|---|---|
| Message-ID | <[email protected]> |
philip Mon, 09 May 2011 21:40:31 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=310866
Log:
Added script to check doc activity (notes, svn commits, and closed bugs.) Will test it out as a weekly email to phpdoc@.
Changed paths:
A web/doc/trunk/scripts/gen_doc_activity_email.php
A web/doc/trunk/templates/emails/
A web/doc/trunk/templates/emails/email-template-doc-activity.txt
Added: web/doc/trunk/scripts/gen_doc_activity_email.php
===================================================================
--- web/doc/trunk/scripts/gen_doc_activity_email.php (rev 0)
+++ web/doc/trunk/scripts/gen_doc_activity_email.php 2011-05-09 21:40:31 UTC (rev 310866)
@@ -0,0 +1,174 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
++----------------------------------------------------------------------+
+| PHP Documentation Site Source Code |
++----------------------------------------------------------------------+
+| Copyright (c) 1997-2011 The PHP Group |
++----------------------------------------------------------------------+
+| This source file is subject to version 3.01 of the PHP license, |
+| that is bundled with this package in the file LICENSE, and is |
+| available through the world-wide-web at the following url: |
+| http://www.php.net/license/3_01.txt. |
+| If you did not receive a copy of the PHP license and are unable to |
+| obtain it through the world-wide-web, please send a note to |
+| [email protected] so we can mail you a copy immediately. |
++----------------------------------------------------------------------+
+| Author: Philip Olson <[email protected]> |
++----------------------------------------------------------------------+
+$Id$
+
+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
+ - Research the bugs api and ensure it works
+ - 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', TRUE); // Enable to not send emails.
+define('EMAIL_TEMPLATE_FILENAME', '../templates/emails/email-template-doc-activity.txt');
+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_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;
+}
+
+if (!is_readable(EMAIL_TEMPLATE_FILENAME)) {
+ echo 'Fail. No email template', PHP_EOL;
+ exit;
+}
+
+$email_text = file_get_contents(EMAIL_TEMPLATE_FILENAME);
+
+/****************************************************************************/
+/**** Weekly commits ********************************************************/
+/****************************************************************************/
+
+$counts = array();
+$text = '';
+foreach ($svn_modules as $svn_module) {
+
+ $command = "svn log http://svn.php.net/repository/$svn_module --revision \{$time_past}:\{$time_now} --non-interactive --xml";
+ $results = shell_exec($command);
+
+ // Elementless XML file has strlen of 35
+ if (!$results || strlen($results) < 35) {
+ continue;
+ }
+
+ $xml = new SimpleXMLElement($results);
+
+ if (empty($xml->logentry)) {
+ continue;
+ }
+
+ foreach ($xml as $info) {
+ @$counts[ (string) $info->author ]++;
+ }
+}
+
+if ($counts && !empty($counts)) {
+
+ arsort($counts);
+
+ $text = '';
+ foreach ($counts as $name => $count) {
+ $text .= sprintf("%20s %5s\n", $name, $count);
+ }
+
+} else {
+ $text = 'No commits made last week. So sad. :(';
+}
+
+$email_text = str_replace('SVN_COMMIT_COUNTS', $text, $email_text);
+
+/****************************************************************************/
+/**** Weekly closed bugs ****************************************************/
+/****************************************************************************/
+
+$rawbuginfo = file_get_contents('http://bugs.php.net/api.php?type=docs&action=closed&interval=week');
+
+$text = '';
+if (!empty($rawbuginfo)) {
+
+ $buginfo = unserialize($rawbuginfo);
+
+ if (!is_array($buginfo)) {
+ $text = 'Incorrect bugs information gathered.';
+ } else {
+ if (count($buginfo) > 0) {
+ foreach ($buginfo as $info) {
+ $text .= sprintf("%20s %5s\n", $info['reporter_name'], $info['count']);
+ }
+ } else {
+ $text = 'No closed bugs last week. So sad. :(';
+ }
+ }
+} else {
+ $text = 'Bug information could not be gathered.';
+}
+
+$email_text = str_replace('BUGS_CLOSED', $text, $email_text);
+
+/****************************************************************************/
+/**** Weekly notes stats ****************************************************/
+/****************************************************************************/
+
+// Note: notes_stats.sqlite is generated via web/doc/trunk/scripts/notes*.php
+// It's used for other note related activities, but we're using it for this too.
+$dbfile = SQLITE_DIR . 'notes_stats.sqlite';
+$text = '';
+if (is_readable($dbfile) && $db = sqlite_open($dbfile, 0666)) {
+
+ $sql = "SELECT who, count(*) as count FROM notes WHERE time > (strftime('%s', 'now')-604800) GROUP BY who ORDER BY count DESC";
+
+ $res = sqlite_query($db, $sql);
+ if ($res) {
+
+ if (sqlite_num_fields($res) > 0) {
+
+ $rows = sqlite_fetch_all($res, SQLITE_ASSOC);
+
+ foreach ($rows as $row) {
+ $text .= sprintf("%20s %5s\n", $row['who'], $row['count']);
+ }
+ } else {
+ $text = 'No notes were edited last week. So sad. :(';
+ }
+ } else {
+ $text = 'Unable to query the notes database';
+ }
+
+} else {
+ $text = 'The notes data cannot be found';
+}
+
+$email_text = str_replace('NOTES_HANDLED', $text, $email_text);
+
+/**** Misc ******************************************************************/
+$email_text = str_replace('SVN_MODULES_LIST', implode($svn_modules, ', '), $email_text);
+$email_text = str_replace('DATES_ACTIVITY', "$time_past to $time_now", $email_text);
+
+if (!DEBUG_MODE) {
+ mail('[email protected]', 'Last weeks PHP documentation activity report', $email_text, 'From: [email protected]');
+} else {
+ echo $email_text;
+}
Property changes on: web/doc/trunk/scripts/gen_doc_activity_email.php
___________________________________________________________________
Added: svn:keywords
+ Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL
Added: svn:eol-style
+ native
Added: web/doc/trunk/templates/emails/email-template-doc-activity.txt
===================================================================
--- web/doc/trunk/templates/emails/email-template-doc-activity.txt (rev 0)
+++ web/doc/trunk/templates/emails/email-template-doc-activity.txt 2011-05-09 21:40:31 UTC (rev 310866)
@@ -0,0 +1,23 @@
+
+Hello!
+
+This lists some of the activity found within the PHP documentation over at php.net. Of course numbers mean nothing alone, but they do show general activity around the PHP documentation. Dates of activity include: DATES_ACTIVITY
+
+Those who made SVN commits:
+-----------------------------------------------
+ (php.net svn modules: SVN_MODULES_LIST)
+
+SVN_COMMIT_COUNTS
+
+Those who closed documentation bugs:
+-----------------------------------------------
+ (bug categories: problem, translation, phd, editor)
+
+BUGS_CLOSED
+
+Those who handled with user notes:
+-----------------------------------------------
+ (actions: delete, reject, edit)
+
+NOTES_HANDLED
+
Property changes on: web/doc/trunk/templates/emails/email-template-doc-activity.txt
___________________________________________________________________
Added: svn:keywords
+ Id Rev Revision
Added: svn:eol-style
+ native