Commits

Laurent Jouanneau committed 51c3827

ticket #5: storage errors

Comments (0)

Files changed (14)

app/modules/rarangi/classes/raLogger.class.php

     public function getLog(){ return $this->log; }
 }
 
+/**
+ * a logger which stores messages in a SQL table
+ */
+class raInDaoLogger implements raILoggerDriver {
+
+    protected $projectId;
+
+    function __construct($project_id) {
+        $this->projectId = $project_id;
+    }
+
+    public function message($str, $f, $l){}
+    public function notice($str, $f, $l){ $this->save('notice', $str, $f, $l);}
+    public function warning($str, $f, $l){ $this->save('warning', $str, $f, $l);}
+    public function error($str, $f, $l){ $this->save('error', $str, $f, $l);}
+    protected function save($typeerr, $msg, $file, $line) {
+        $rec = jDao::createRecord('rarangi~errors');
+        $rec->message = $msg;
+        $rec->type = $typeerr;
+        $rec->file = $file;
+        $rec->line = $line;
+        $rec->project_id = $this->projectId;
+        jDao::get('rarangi~errors')->insert($rec);
+    }
+    
+    public function clear(){ jDao::get('rarangi~errors')->deleteByProject($this->projectId); }
+
+    public function getLog(){ return array(); }
+}

app/modules/rarangi/classes/raProject.class.php

             jDao::get('globals')->deleteByProject($this->projectRec->id);
             jDao::get('packages')->deleteByProject($this->projectRec->id);
         }
+        $dbLogger = new raInDaoLogger($this->projectRec->id);
+        $dbLogger->clear();
+        $this->_logger->addLogger($dbLogger);
     }
 
     public function id() {

app/modules/rarangi/controllers/default.cmdline.php

         $memBegin = memory_get_usage();
 
         $logger = jClasses::create("raLogger");
-        $logger->addLogger(new raInMemoryLogger());
+        //$logger->addLogger(new raInMemoryLogger());
         $logger->addLogger(new raConsoleLogger($rep, isset($this->_options['-v'])));
 
         jClasses::inc("raDocGenerator");

app/modules/rarangi/daos/errors.dao.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<dao xmlns="http://jelix.org/ns/dao/1.0">
+    <datasources>
+        <primarytable name="errors" realname="errors" primarykey="id" />
+    </datasources>
+    <record>
+        <property name="id" fieldname="id" datatype="autoincrement"/>
+        <property name="message" fieldname="message" datatype="string" required="true"/>
+        <property name="file" fieldname="file" datatype="string" maxlength="150"/>
+        <property name="line" fieldname="line" datatype="int" />
+        <property name="type" fieldname="type" datatype="string" required="true"/>
+        <property name="project_id" fieldname="project_id" datatype="int" required="true"/>
+    </record>
+    <factory>
+        <method name="deleteByProject" type="delete">
+            <parameter name="project" />
+            <conditions>
+                <eq property="project_id" expr="$project" />
+            </conditions>
+        </method>
+        <method name="findByProject" type="select">
+            <parameter name="project" />
+            <conditions>
+                <eq property="project_id" expr="$project" />
+            </conditions>
+        </method>
+        <method name="countByProject" type="count">
+            <parameter name="project" />
+            <conditions>
+                <eq property="project_id" expr="$project" />
+            </conditions>
+        </method>
+    </factory>
+</dao>

app/modules/rarangi/install/install.mysql.sql

   `name` varchar(50) NOT NULL,
   PRIMARY KEY  (`id`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
+
+-- --------------------------------------------------------
+
+CREATE TABLE `%%PREFIX%%errors` (
+`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
+`type` VARCHAR( 20 )  NOT NULL ,
+`message` TEXT NOT NULL ,
+`file` VARCHAR( 255 ) NULL ,
+`line` INT NULL ,
+`project_id` INT NOT NULL ,
+INDEX ( `project_id` )
+) ENGINE = MYISAM  DEFAULT CHARSET=utf8;
+

app/modules/rarangi/install/update_0.0.4.mysql.sql

+
+CREATE TABLE `%%PREFIX%%errors` (
+`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
+`type` VARCHAR( 20 )  NOT NULL ,
+`message` TEXT NOT NULL ,
+`file` VARCHAR( 255 ) NULL ,
+`line` INT NULL ,
+`project_id` INT NOT NULL ,
+INDEX ( `project_id` )
+) ENGINE = MYISAM  DEFAULT CHARSET=utf8;

app/modules/rarangi/install/upgrade_to_0.0.4_errors.php

+<?php
+/**
+* @package     rarangi
+* @subpackage  
+* @author      Laurent Jouanneau
+* @copyright   2010 Laurent Jouanneau
+* @licence     GNU General Public Licence see LICENCE file or http://www.gnu.org/licenses/gpl.html
+*/
+
+class rarangiModuleUpgrader_errors extends jInstallerModule {
+
+    function install() {
+      $this->execSQLScript('update_0.0.4');
+    }
+}

app/modules/rarangi/module.xml

 <?xml version="1.0" encoding="UTF-8"?>
 <module xmlns="http://jelix.org/ns/module/1.0">
     <info id="rarangi-module@forge.jelix.org" name="rarangi" createdate="2008-11-25">
-        <version stability="pre-alpha" date="">0.0.3</version>
+        <version stability="pre-alpha" date="">0.0.4</version>
         <label lang="en_EN">Rarangi</label>
         <description lang="en_EN"/>
         <licence URL="http://www.gnu.org/licenses/gpl.html">GNU General Public Licence</licence>

app/modules/rarangi_web/classes/project.urlhandler.php

                 return $urlact;
             }
 
+            if($match[3] == 'errors') {
+                $urlact->setParam('action', 'default:errors');
+                return $urlact;
+            }
+
             if(preg_match('!^sources(/(.*))?$!', $match[3], $m)) {
                 $urlact->setParam('action', 'sources:index');
                 $urlact->setParam('path', $m[2]);
         $url->delParam('project');
 
         switch($action) {
+            case 'default:errors':
+                $url->pathInfo .= 'errors';
+                break;
             case 'sources:index':
                 $url->pathInfo .= 'sources/';
                 $path = $url->getParam('path');

app/modules/rarangi_web/controllers/default.classic.php

             $dao_packages = jDao::get('rarangi~packages');
             $packages_counter = $dao_packages->countByProject($project->id);
             $tpl->assign('packages_counter', $packages_counter);
+
+            $tpl->assign('errors_counter', jDao::get('rarangi~errors')->countByProject($project->id));
+
         }
         
         $resp->body->assign('MAIN', $tpl->fetch('projects_details'));
 
         return $resp;
     }
-    
+
+    function errors() {
+        $resp = $this->getResponse('html');
+
+        $projectname = $this->param('project');
+        $resp->title = jLocale::get('default.page.project.errors.title', array($projectname));
+
+        // Get project
+        $dao = jDao::get('rarangi~projects');
+        $project = $dao->getByName($projectname);
+
+        $tpl = new jTpl();
+        $tpl->assign('project',$project);
+        $tpl->assign('projectname',$projectname);
+        
+        if (!$project) {
+            $resp->setHttpStatus('404','Not found');
+        } else {
+            $resp->body->assignZone('BREADCRUMB', 'location_breadcrumb', array(
+                    'mode' => 'projecthome',
+                    'projectname' => $projectname));
+            $resp->body->assignZone('MENUBAR', 'project_menubar', array(
+                    'project' => $project,
+                    'mode' => 'browse'));
+
+            $dao_errors = jDao::get('rarangi~errors');
+            $tpl->assign('errors', $dao_errors->findByProject($project->id));
+        }
+        
+        $resp->body->assign('MAIN', $tpl->fetch('errors'));
+
+        return $resp;
+    }
+
     /**
     * Display the help page
     */

app/modules/rarangi_web/locales/en_EN/default.UTF-8.properties

 
 page.home.title = Projects available
 page.project.home.title = Project %s
+page.project.errors.title = Parsing errors for the project %s
 page.help.title = Help about Rarangi
 page.about.title = About Rarangi
 packages.title = Packages for project %s
 seealso = See also
 
 footer.poweredby = Powered by Rarangi and Jelix
+
+errors.list=Parsing errors

app/modules/rarangi_web/templates/errors.tpl

+{if $project}
+    <h2>{@rarangi_web~default.errors.list@}</h2>
+    
+    <div class="block">
+
+    <dl>
+        {foreach $errors as $err}
+        <dt class="message-{$err->type}">{$err->type}: {$err->message|eschtml}</dt>
+        <dd>{$err->file} {$err->line}</dd>
+        {/foreach}
+    </dl>
+    </div>
+
+{else}
+    <h2>Project: {$projectname}</h2>
+    <div class="blockcontent">
+        <p>Error, unknow project</p>
+    </div>
+{/if}

app/modules/rarangi_web/templates/projects_details.tpl

     <ul>
         <li>{$files_counter} files</li>
         <li>{$lines_counter} lines of code</li>
+        {if $errors_counter}<li><a href="{jurl 'rarangi_web~default:errors', array('project'=>$projectname)}">{$errors_counter} errors/warnings</a> found during the parsing</li>{/if}
     </ul>
     </div>
     

app/var/config/urls.xml

         <url pathinfo="/about" module="rarangi_web" action="default:about" />
         
         <url handler="project" module="rarangi_web" action="default:project"
-            actionoverride="sources:index,packages:index,packages:details,packages:subpackdetails,packages:classes,packages:functions,components:functiondetails,components:classdetails,components:interfacedetails,components:globaldetails,components:constantdetails,packages:constants,packages:globals"/>
+            actionoverride="default:errors,sources:index,packages:index,packages:details,packages:subpackdetails,packages:classes,packages:functions,components:functiondetails,components:classdetails,components:interfacedetails,components:globaldetails,components:constantdetails,packages:constants,packages:globals"/>
     </classicentrypoint>
 
 </urls>