svn: /web/doc-editor/trunk/ php/RepositoryFetcher.php scripts/cron/send_work_to_list.php
[email protected] (Yannick Torres)
| Newsgroups | php.doc.web |
|---|---|
| Message-ID | <[email protected]> |
yannick Wed, 29 Dec 2010 19:42:35 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=306829
Log:
New cron script to send an email each week to the lang list and inform there is some pending work into the editor
Changed paths:
U web/doc-editor/trunk/php/RepositoryFetcher.php
A web/doc-editor/trunk/scripts/cron/send_work_to_list.php
Modified: web/doc-editor/trunk/php/RepositoryFetcher.php
===================================================================
--- web/doc-editor/trunk/php/RepositoryFetcher.php 2010-12-29 19:08:15 UTC (rev 306828)
+++ web/doc-editor/trunk/php/RepositoryFetcher.php 2010-12-29 19:42:35 UTC (rev 306829)
@@ -658,7 +658,87 @@
return $a->total;
}
+
/**
+ * Get all files in Work module (progress work and patches for review).
+ * Actually only used in scripts/cron/send_work_to_list.php
+ *
+ * @return An associated array containing informations about files in work
+ */
+ public function getRawWork($lang)
+ {
+ $am = AccountManager::getInstance();
+ $project = $am->project;
+
+ /**** We start by the work in progress module ****/
+
+ // We exclude item witch name == '-' ; this is new folder ; We don't display it.
+ $s = sprintf(
+ 'SELECT
+ CONCAT(`lang`, `path`, `name`) as filePath,
+ `user`,
+ `date`,
+ `type`
+ FROM
+ `work`
+ WHERE
+ `module` = "workInProgress" AND
+ `lang` = "%s" AND
+ `project` = "%s"',
+ $lang,
+ $project
+ );
+ $r = DBConnection::getInstance()->query($s);
+
+ $workInProgress = Array('nb'=>0,'data'=>Array());
+
+ if( $r->num_rows != 0 )
+ {
+ $workInProgress['nb'] = $r->num_rows;
+ while ($a = $r->fetch_array(MYSQLI_ASSOC)) {
+ $workInProgress['data'][] = $a;
+ }
+ }
+
+ /**** then, by the patches for review module ****/
+
+ // We exclude item witch name == '-' ; this is new folder ; We don't display it.
+ $s = sprintf(
+ 'SELECT
+ CONCAT(`lang`, `path`, `name`) as filePath,
+ `user`,
+ `date`,
+ `type`
+ FROM
+ `work`
+ WHERE
+ `module` = "PatchesForReview" AND
+ `lang` = "%s" AND
+ `project` = "%s"',
+ $lang,
+ $project
+ );
+ $r = DBConnection::getInstance()->query($s);
+
+ $PatchesForReview = Array('nb'=>0,'data'=>Array());
+
+ if( $r->num_rows != 0 )
+ {
+ $PatchesForReview['nb'] = $r->num_rows;
+ while ($a = $r->fetch_array(MYSQLI_ASSOC)) {
+ $PatchesForReview['data'][] = $a;
+ }
+ }
+
+ // We return the result now
+ return Array(
+ "total" => ($workInProgress['nb'] + $PatchesForReview['nb']),
+ "workInProgress" => $workInProgress,
+ "PatchesForReview" => $PatchesForReview
+ );
+ }
+
+ /**
* Get all files in Work module (progress work or patches for review).
*
* @return An associated array containing informations about files in work
Added: web/doc-editor/trunk/scripts/cron/send_work_to_list.php
===================================================================
--- web/doc-editor/trunk/scripts/cron/send_work_to_list.php (rev 0)
+++ web/doc-editor/trunk/scripts/cron/send_work_to_list.php 2010-12-29 19:42:35 UTC (rev 306829)
@@ -0,0 +1,104 @@
+<?php
+
+/***
+* This script is intended to be placed in a cronjob.
+* It must be run every Monday, at 08hOO for example.
+* On Unix, you can use crontab -e and place this :
+* 00 08 * * 1 /path/php/binary /path/to/your/vcs/dir/doc-editor/scripts/cron/send_work_to_list.php
+****/
+
+require_once dirname(__FILE__) . '/../../php/Conf.php';
+require_once dirname(__FILE__) . '/../../php/AccountManager.php';
+require_once dirname(__FILE__) . '/../../php/LogManager.php';
+require_once dirname(__FILE__) . '/../../php/ProjectManager.php';
+require_once dirname(__FILE__) . '/../../php/RepositoryFetcher.php';
+require_once dirname(__FILE__) . '/../../php/RepositoryManager.php';
+
+$rf = RepositoryFetcher::getInstance();
+$rm = RepositoryManager::getInstance();
+$pm = ProjectManager::getInstance();
+$availableProject = $pm->getAvailableProject();
+
+while( list($key, $project) = each($availableProject) ) {
+
+ // Actually, only PHP project support to be automatically checked for the build. Skip all others projects
+ if( $project['code'] != "php" ) {
+ continue;
+ }
+
+ echo "enter into ".$project['code']."\n";
+
+ // We must delete this var to be re-generated
+ unset($rm->existingLanguage);
+
+ // Define it as a project
+ $pm->setProject($project['code']);
+
+ $existingLanguage = $rm->getExistingLanguage();
+
+ // For all language, we check the build
+ foreach ($existingLanguage as $lang) {
+
+ echo "Is there some work to send to the ".$lang["code"]." list ?\n";
+
+ $lang = $lang["code"];
+
+ $data = $rf->getRawWork($lang);
+
+
+ // What we must do when the build failed
+ if( $data["total"] != 0 ) {
+
+
+ $msg = "Hello Php ".strtoupper($lang)." Documentation team,
+
+There are contributions within the online editor queue for this language.
+Please review, then commit or delete these patches.
+
+";
+
+
+ if( $data['workInProgress']['nb'] != 0 ) {
+ $msg .= " Work in progress : \n -----------------------\n";
+
+ for( $i=0; $i < count($data['workInProgress']['data']); $i++) {
+ $msg .= " * (".$data['workInProgress']['data'][$i]['type'].") On ".$data['workInProgress']['data'][$i]['date']." by ".$data['workInProgress']['data'][$i]['user']." : ".$data['workInProgress']['data'][$i]['filePath']."\n";
+ }
+ $msg .="\n\n";
+ }
+
+
+ if( $data['PatchesForReview']['nb'] != 0 ) {
+ $msg .= " Patches for review : \n -----------------------\n";
+
+ for( $i=0; $i < count($data['PatchesForReview']['data']); $i++) {
+ $msg .= " * (".$data['PatchesForReview']['data'][$i]['type'].") On ".$data['PatchesForReview']['data'][$i]['date']." by ".$data['PatchesForReview']['data'][$i]['user']." : ".$data['PatchesForReview']['data'][$i]['filePath']."\n";
+ }
+ $msg .="\n\n";
+
+ }
+
+
+
+ $msg .= "
+--
+https://edit.php.net/
+This email is send automatically by the Php Docbook Online Editor.
+ ";
+
+ //Usefull for language like pt_BR for example, because doc-pt_br don't exist, it's doc-pt-br
+ $emailLang = str_replace("_", "-", strtolower($lang));
+
+ $to = ( $lang === 'en' ) ? "[email protected]" : "[email protected]";
+
+ $subject = "Contributions are ready for review";
+
+ // We send an email for this failed build
+ AccountManager::getInstance()->email($to, $subject, $msg, 'www');
+
+ echo "email send !\n";
+
+ }
+ }
+}
+?>