summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-28 17:29:38 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-28 17:29:38 +0100
commit01a1dd09a8ee02250905a80d2662bfe811c09f09 (patch)
tree9cfdd9c26f3f3b9b3d3ce44d36110c6ed41d0d9f /app
parent9ac1496d63da32524a33696187342ce061e9ef28 (diff)
Minz : refactorisation ModelArray et Log
Utilisation de fonctions natives de PHP comme file_put_contents et var_export Évite de garder un descripteur de fichier ouvert tout le temps Et ModelTxt n'est plus utilisé
Diffstat (limited to 'app')
-rwxr-xr-xapp/Controllers/indexController.php9
-rw-r--r--app/Models/ConfigurationDAO.php9
-rw-r--r--app/Models/LogDAO.php28
3 files changed, 19 insertions, 27 deletions
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php
index 0c229aedb..4677787c1 100755
--- a/app/Controllers/indexController.php
+++ b/app/Controllers/indexController.php
@@ -225,14 +225,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
file_put_contents(LOG_PATH . '/application.log', '');
}
- $logs = array();
- try {
- $logDAO = new FreshRSS_LogDAO ();
- $logs = $logDAO->lister ();
- $logs = array_reverse ($logs);
- } catch (Minz_FileNotExistException $e) {
-
- }
+ $logs = FreshRSS_LogDAO::lines(); //TODO: ask only the necessary lines
//gestion pagination
$page = Minz_Request::param ('page', 1);
diff --git a/app/Models/ConfigurationDAO.php b/app/Models/ConfigurationDAO.php
index fa4d3338f..53312f043 100644
--- a/app/Models/ConfigurationDAO.php
+++ b/app/Models/ConfigurationDAO.php
@@ -146,12 +146,9 @@ class FreshRSS_ConfigurationDAO extends Minz_ModelArray {
}
}
- public function update ($values) {
- foreach ($values as $key => $value) {
- $this->array[$key] = $value;
- }
-
- $this->writeFile($this->array);
+ public function update($values) {
+ $this->array = array_merge($this->array, $values);
invalidateHttpCache();
+ return parent::writeFile();
}
}
diff --git a/app/Models/LogDAO.php b/app/Models/LogDAO.php
index 06855ec66..e57e0b1b9 100644
--- a/app/Models/LogDAO.php
+++ b/app/Models/LogDAO.php
@@ -1,21 +1,23 @@
<?php
-class FreshRSS_LogDAO extends Minz_ModelTxt {
- public function __construct () {
- parent::__construct (LOG_PATH . '/application.log', 'r+');
- }
+class FreshRSS_LogDAO {
+ private static $filename = '/application.log';
- public function lister () {
+ public static function lines() {
$logs = array ();
- while (($line = $this->readLine ()) !== false) {
- if (preg_match ('/^\[([^\[]+)\] \[([^\[]+)\] --- (.*)$/', $line, $matches)) {
- $myLog = new FreshRSS_Log ();
- $myLog->_date ($matches[1]);
- $myLog->_level ($matches[2]);
- $myLog->_info ($matches[3]);
- $logs[] = $myLog;
+ $handle = @fopen(LOG_PATH . self::$filename, 'r');
+ if ($handle) {
+ while (($line = fgets($handle)) !== false) {
+ if (preg_match ('/^\[([^\[]+)\] \[([^\[]+)\] --- (.*)$/', $line, $matches)) {
+ $myLog = new FreshRSS_Log ();
+ $myLog->_date ($matches[1]);
+ $myLog->_level ($matches[2]);
+ $myLog->_info ($matches[3]);
+ $logs[] = $myLog;
+ }
}
+ fclose($handle);
}
- return $logs;
+ return array_reverse($logs);
}
}