From b41fffb9ccc1247bdcfbdf14363d127228ee01ff Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles Date: Mon, 4 Jan 2016 15:38:09 -0500 Subject: [PATCH 01/19] Huge dashboard refactor + preselect of the watch on call to actions #36 --- application/controllers/Measures.php | 27 ++- application/models/Measure.php | 79 ++++--- application/models/Watch.php | 3 +- application/views/measure/all.php | 196 ------------------ application/views/measure/dashboard.php | 87 ++++++++ .../measure/dashboard/call-to-action.php | 38 ++++ .../measure/dashboard/check-accuracy.php | 6 + .../measure/dashboard/delete-measure.php | 6 + .../views/measure/dashboard/delete-watch.php | 5 + .../measure/dashboard/end-action-button.php | 2 + .../measure/dashboard/start-action-button.php | 6 + .../measure/dashboard/start-new-measure.php | 5 + application/views/measure/dashboard/steps.php | 16 ++ application/views/measure/new-measure.php | 16 +- assets/js/application.js | 9 + 15 files changed, 247 insertions(+), 254 deletions(-) delete mode 100644 application/views/measure/all.php create mode 100644 application/views/measure/dashboard.php create mode 100644 application/views/measure/dashboard/call-to-action.php create mode 100644 application/views/measure/dashboard/check-accuracy.php create mode 100644 application/views/measure/dashboard/delete-measure.php create mode 100644 application/views/measure/dashboard/delete-watch.php create mode 100644 application/views/measure/dashboard/end-action-button.php create mode 100644 application/views/measure/dashboard/start-action-button.php create mode 100644 application/views/measure/dashboard/start-new-measure.php create mode 100644 application/views/measure/dashboard/steps.php diff --git a/application/controllers/Measures.php b/application/controllers/Measures.php index 2db8ac68..8f113fb1 100644 --- a/application/controllers/Measures.php +++ b/application/controllers/Measures.php @@ -42,12 +42,10 @@ private function constructMeasurePage(){ $this->_headerData['headerClass'] = 'blue'; $this->load->view('header', $this->_headerData); - $this->_bodyData['watches'] = $this->watch->getWatches( - $this->session->userdata('userId')); $this->_bodyData['allMeasure'] = $this->measure->getMeasuresByUser( - $this->session->userdata('userId'), $this->_bodyData['watches']); + $this->session->userdata('userId')); - $this->load->view('measure/all', $this->_bodyData); + $this->load->view('measure/dashboard', $this->_bodyData); $this->load->view('footer'); } @@ -94,7 +92,7 @@ public function add_watch(){ */ public function delete_watch(){ - if($this->expectsPost(array('deleteWatch'))){ + if($this->expectsPost(array('watchId'))){ if ($this->watch->deleteWatch($this->watchId)) { $this->_bodyData['success'] = 'Watch successfully deleted!'; @@ -148,18 +146,35 @@ public function new_watch() { */ public function new_measure() { + $this->_bodyData['watches'] = $this->watch->getWatches( + $this->session->userdata('userId')); + $this->event->add(MEASURE_LOAD); $this->_headerData['headerClass'] = 'blue'; $this->load->view('header', $this->_headerData); - $this->_bodyData['watches'] = $this->watch->getWatches($this->session->userdata('userId')); $this->load->view('measure/new-measure', $this->_bodyData); $this->load->view('measure/audio.php'); $this->load->view('footer'); } + /** + * Serves the new measure form (1/2) for a watch + * with existing measures. + */ + public function new_measure_for_watch(){ + + if($this->expectsPost(array('watchId'))){ + + $this->_bodyData['selected_watch'] = $this->watchId; + + $this->new_measure(); + + } + } + /** * Serves the new accuracy form (2/2) */ diff --git a/application/models/Measure.php b/application/models/Measure.php index e881a3e6..b184715e 100644 --- a/application/models/Measure.php +++ b/application/models/Measure.php @@ -35,46 +35,17 @@ function __construct() { * Get the last measure of each $userWatches * * @param int $userId id of the user - * @param array $userWatches watches of the user - * @return array The last measure per $userWatches for $userId + * @return array The last measure per of $userId */ - function getMeasuresByUser($userId, $userWatches) { - - $data = array(); - - if (is_array($userWatches) && sizeof($userWatches) > 0) { - - foreach ($userWatches as $watch) { - //Get measure couple that are on measure or accuracy status - $watchMeasures = $this->select() - ->join("watch", "watch.watchId = ".$watch->watchId) - ->where('measure.watchId', $watch->watchId) - ->where('(`statusId` = 1 OR `statusId` = 2)', null, false) - ->find_all(); - - if ($watchMeasures) { - - foreach ($watchMeasures as $watchMeasure) { - - //If the first measure is less than 12 hours old - if ($watchMeasure->statusId === "1" && - (((time()-$watchMeasure->measureReferenceTime)/3600) < 12)) { - - $watchMeasure->statusId = 1.5; - $ellapsedTime = ((time()-$watchMeasure->measureReferenceTime)/3600); - $watchMeasure->accuracy = round(12-round($ellapsedTime, 1)); - if ($watchMeasure->accuracy <= 1) { - $watchMeasure->accuracy = " < 1"; - } - } - - array_push($data, $watchMeasure); - } - } - } - } - - return $data; + function getMeasuresByUser($userId) { + + return $this->select() + ->join("watch", "watch.watchId = measure.watchId + AND measure.statusId < 3", "right") + ->where("watch.userId", $userId) + ->where("watch.status <", 4) + ->group_by("watch.watchId") + ->find_all(); } /** @@ -96,11 +67,31 @@ public function computeAccuracy($watchMeasure) { $wasArray = true; } - $userDelta = $watchMeasure->accuracyUserTime-$watchMeasure->measureUserTime; - $refDelta = $watchMeasure->accuracyReferenceTime-$watchMeasure->measureReferenceTime; - $accuracy = ($userDelta*86400/$refDelta)-86400; - $accuracy = sprintf("%.1f", $accuracy); - $watchMeasure->accuracy = $accuracy; + //Compute the accuracy if all the data are available + //Both measure have been performed + if(is_numeric($watchMeasure->accuracyUserTime) + && is_numeric($watchMeasure->measureUserTime) + && is_numeric($watchMeasure->accuracyReferenceTime) + && is_numeric($watchMeasure->measureReferenceTime)) + { + $userDelta = $watchMeasure->accuracyUserTime-$watchMeasure->measureUserTime; + $refDelta = $watchMeasure->accuracyReferenceTime-$watchMeasure->measureReferenceTime; + $accuracy = ($userDelta*86400/$refDelta)-86400; + $accuracy = sprintf("%.1f", $accuracy); + $watchMeasure->accuracy = $accuracy; + } + + //Compute 1.5 status. When a measure is less than 12 hours old + if ($watchMeasure->statusId === "1" && + (((time()-$watchMeasure->measureReferenceTime)/3600) < 12)) { + + $watchMeasure->statusId = 1.5; + $ellapsedTime = ((time()-$watchMeasure->measureReferenceTime)/3600); + $watchMeasure->accuracy = round(12-round($ellapsedTime, 1)); + if ($watchMeasure->accuracy <= 1) { + $watchMeasure->accuracy = " < 1"; + } + } //If the measure was an array, //I typecast it back to array. diff --git a/application/models/Watch.php b/application/models/Watch.php index 97f22f4b..3a099f03 100644 --- a/application/models/Watch.php +++ b/application/models/Watch.php @@ -62,7 +62,6 @@ function getWatches($userId) { ->where('status', 1) ->order_by('brand', 'asc') ->find_all(); - } /** @@ -89,7 +88,7 @@ function getWatchByMeasureId($measureId){ * Soft delete watch $watchId * * @param int $watchId The watch to delete - * @return boolean + * @return boolean */ function deleteWatch($watchId) { $data = array('status' => 4); diff --git a/application/views/measure/all.php b/application/views/measure/all.php deleted file mode 100644 index 81612f6d..00000000 --- a/application/views/measure/all.php +++ /dev/null @@ -1,196 +0,0 @@ -
-
-

My measures

-
-
-
-
-
-
Step 1
Step 1
Add a watch to the list
-
-
Step 2
Step 2
Synchronize with our accuracy system (first measure)
-
-
Step 2
Step 3
Get your accuracy (second measure)
-
- -
-
- - - '.$error.'
'; - - } - else if(isset($success)) - { - echo ''; - } - var_dump($allMeasure); - ?> - - - - - - - - - - - - '; - echo ''; - echo ''; - - if($measure->statusId == '0') - { - echo ''; - echo ''; - echo ''; - } - else if($measure->statusId == '1') - { - echo ''; - echo ''; - echo ''; - } - else if($measure->statusId == '1.5') - { - echo ''; - echo ''; - echo ''; - } - else if($measure->statusId == '2') - { - if($measure->accuracy > 0) - $accuracy = "+".$measure->accuracy; - else - $accuracy = $measure->accuracy; - - if(($measure->accuracy > 99.9) || (($measure->accuracy < -99.9))) - { - - echo ''; - } - else - { - echo ''; - } - - echo ''; - echo ''; - } - } - } - else - { - echo ''; - } - ?> - -
Watch brandWatch nameAccuracyActions
'.$measure->brand.''.$measure->name.'Measure me!
- - -
Check the accuracy
- - -
Check the accuracy in '.$measure->accuracy.' hour(s)
- - -
'.$accuracy.' seconds a day
Looks like there was an error measuring your watch, why not try another measure?
'.$accuracy.' seconds a day
- - -
You don\'t have any measure yet!
-
-
-
-
-
- Add a watch

- - - Start a new measure - - - - -
-
-
- diff --git a/application/views/measure/dashboard.php b/application/views/measure/dashboard.php new file mode 100644 index 00000000..79d6ade5 --- /dev/null +++ b/application/views/measure/dashboard.php @@ -0,0 +1,87 @@ +
+ + load->view("measure/dashboard/steps"); ?> + +
+
+ + + '.$error.'
'; + + } + else if(isset($success)) + { + echo ''; + } + var_dump($allMeasure); + ?> + + + + + + + + + + + + '; + echo ''; + echo ''; + + $this->load->view("measure/dashboard/call-to-action.php", $measure); + + $this->load->view("measure/dashboard/start-action-button"); + + if($measure->statusId === "1"){ + $this->load->view("measure/dashboard/check-accuracy", $measure); + } + + if($measure->statusId > 0){ + $this->load->view("measure/dashboard/delete-measure", $measure); + } + + $this->load->view("measure/dashboard/start-new-measure", $measure); + + + $this->load->view("measure/dashboard/delete-watch", $measure); + $this->load->view("measure/dashboard/end-action-button"); + + } + } + else + { + echo ''; + } + ?> + +
Watch brandWatch nameAccuracyActions
'.$measure->brand.''.$measure->name.'
You don\'t have any measure yet!
+
+
+
+
+
+ Add a watch

+ + + Start a new measure + + + + +
+
+
+ diff --git a/application/views/measure/dashboard/call-to-action.php b/application/views/measure/dashboard/call-to-action.php new file mode 100644 index 00000000..50d61f68 --- /dev/null +++ b/application/views/measure/dashboard/call-to-action.php @@ -0,0 +1,38 @@ +Measure me! +
+ +
'; + +}else if($statusId == '1'){ + + echo 'Check the accuracy'; + +}else if($statusId == '1.5'){ + + echo 'Check the accuracy in + '.$accuracy.' hour(s) '; + +}else if($statusId == '2'){ + + if($accuracy > 0){ + $accuracy = "+".$accuracy; + }else{ + $accuracy = $accuracy; + } + + if(($accuracy > 99.9) || (($accuracy < -99.9))) + { + + echo ''.$accuracy.' seconds a day
Looks like there was + an error measuring your watch, why not try another measure?'; + } + else + { + echo ''.$accuracy.' seconds a day'; + } +} +?> diff --git a/application/views/measure/dashboard/check-accuracy.php b/application/views/measure/dashboard/check-accuracy.php new file mode 100644 index 00000000..faa3a6d6 --- /dev/null +++ b/application/views/measure/dashboard/check-accuracy.php @@ -0,0 +1,6 @@ +
  • Check the accuracy +
    + + +
    +
  • diff --git a/application/views/measure/dashboard/delete-measure.php b/application/views/measure/dashboard/delete-measure.php new file mode 100644 index 00000000..76be74e7 --- /dev/null +++ b/application/views/measure/dashboard/delete-measure.php @@ -0,0 +1,6 @@ +
  • + Delete this measure +
    + +
    +
  • diff --git a/application/views/measure/dashboard/delete-watch.php b/application/views/measure/dashboard/delete-watch.php new file mode 100644 index 00000000..dad61e72 --- /dev/null +++ b/application/views/measure/dashboard/delete-watch.php @@ -0,0 +1,5 @@ +
  • + Delete watch +
    +
    +
  • diff --git a/application/views/measure/dashboard/end-action-button.php b/application/views/measure/dashboard/end-action-button.php new file mode 100644 index 00000000..78aedd48 --- /dev/null +++ b/application/views/measure/dashboard/end-action-button.php @@ -0,0 +1,2 @@ + + diff --git a/application/views/measure/dashboard/start-action-button.php b/application/views/measure/dashboard/start-action-button.php new file mode 100644 index 00000000..cb5d50d4 --- /dev/null +++ b/application/views/measure/dashboard/start-action-button.php @@ -0,0 +1,6 @@ + +
    + +
    - \ No newline at end of file + diff --git a/assets/js/application.js b/assets/js/application.js index ca378c47..eefdf199 100644 --- a/assets/js/application.js +++ b/assets/js/application.js @@ -470,6 +470,15 @@ $(document).ready(function() } }); + $('body').on('click', '.submitNewMeasure', function(e) + { + e.preventDefault(); + var watchId = $(this).attr('data-watch'); + + $('form[name="start-new-measure-'+watchId+'"]').submit(); + + }); + $('body').on('click', '.submitDeleteMeasures', function(e) { e.preventDefault(); From c4c3a2efd3c585ca1695ea55aacbfee1f8247f72 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles Date: Mon, 4 Jan 2016 15:48:42 -0500 Subject: [PATCH 02/19] enchance unit test #36 --- application/tests/controllers/Measures_test.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/application/tests/controllers/Measures_test.php b/application/tests/controllers/Measures_test.php index 6339c304..605919e0 100644 --- a/application/tests/controllers/Measures_test.php +++ b/application/tests/controllers/Measures_test.php @@ -81,7 +81,7 @@ public function test_indexDeleteWatch(){ 'POST', ['Measures', 'delete_watch'], [ - 'deleteWatch' => $watch->watchId + 'watchId' => $watch->watchId ] ); @@ -164,6 +164,8 @@ public function test_accuracyMeasure() { $measure = $CI->Measure->find_by('watchId', self::$watchId); + $CI->session->set_userdata('referenceTime', time()); + $output = $this->request( 'POST', ['Measures', 'accuracyMeasure'], @@ -174,6 +176,8 @@ public function test_accuracyMeasure() { ] ); + + $this->assertContains('true', $output); } From 455327575def2a3d07419cf0edc87c75e5f339fa Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles Date: Mon, 4 Jan 2016 17:14:28 -0500 Subject: [PATCH 03/19] remove debug print #36 --- application/views/measure/dashboard.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/views/measure/dashboard.php b/application/views/measure/dashboard.php index 79d6ade5..7593db2a 100644 --- a/application/views/measure/dashboard.php +++ b/application/views/measure/dashboard.php @@ -19,7 +19,6 @@ '.$success.''; } - var_dump($allMeasure); ?> From 7d763bd81fa7c7bb68ed344f89279ba72058e9d2 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles Date: Mon, 4 Jan 2016 19:43:09 -0500 Subject: [PATCH 04/19] add debug print for session #36 --- application/controllers/Ajax.php | 3 +++ application/views/header.php | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/application/controllers/Ajax.php b/application/controllers/Ajax.php index a1354e30..623fcedf 100644 --- a/application/controllers/Ajax.php +++ b/application/controllers/Ajax.php @@ -61,7 +61,10 @@ function login() { } echo json_encode($result); + }else{ + echo "POST FAIL"; } + } /** diff --git a/application/views/header.php b/application/views/header.php index 5f772f8a..ce167b48 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -148,4 +148,5 @@ - \ No newline at end of file + +session->userdata());?> From 6dc902bfbcf571f1e29843101654df67c9692657 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles Date: Mon, 4 Jan 2016 19:48:47 -0500 Subject: [PATCH 05/19] remove tests for php 7.0 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b5c2555f..d03bc3b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - '5.6' - - '7.0' notifications: slack: toolwatchapp:AfvHCPE9Em1MY3j04gdlqbYe From 9906b851faac23a200cdcbb092e64d4013fe1775 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles Date: Mon, 4 Jan 2016 20:25:13 -0500 Subject: [PATCH 06/19] session from master + log --- application/config/config.php | 16 ++++++++-------- application/tests/phpunit.xml | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index c77a6c51..b42c1b46 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -216,7 +216,7 @@ | your log files will fill up very fast. | */ -$config['log_threshold'] = 0; +$config['log_threshold'] = 2; /* |-------------------------------------------------------------------------- @@ -360,13 +360,13 @@ | except for 'cookie_prefix' and 'cookie_httponly', which are ignored here. | */ -$config['sess_driver'] = 'database'; -$config['sess_cookie_name'] = 'ci_session'; -$config['sess_save_path'] = 'ci_sessions'; -$config['sess_expiration'] = 1440; -$config['sess_match_ip'] = TRUE; -$config['sess_time_to_update'] = 300; -$config['sess_regenerate_destroy'] = FALSE; + $config['sess_driver'] = 'database'; + $config['sess_cookie_name'] = 'ci_session'; + $config['sess_expiration'] = 1440; + $config['sess_save_path'] = 'ci_sessions'; + $config['sess_match_ip'] = FALSE; + $config['sess_time_to_update'] = 300; + $config['sess_regenerate_destroy'] = FALSE; /* |-------------------------------------------------------------------------- diff --git a/application/tests/phpunit.xml b/application/tests/phpunit.xml index 8dabe1df..950dc5e2 100644 --- a/application/tests/phpunit.xml +++ b/application/tests/phpunit.xml @@ -20,6 +20,9 @@ ../helpers ../hooks + + ../libraries/Mandrill + From 72cf72eeaf5a94623d5e644b452be6adb194610f Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles Date: Mon, 4 Jan 2016 20:31:12 -0500 Subject: [PATCH 07/19] debug messages --- application/views/header.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/application/views/header.php b/application/views/header.php index ce167b48..ac27ea49 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -1,4 +1,10 @@ +session->userdata());?> +
    +"; +echo "RA CF" . $_SERVER["HTTP_CF_CONNECTING_IP"]; +?> Toolwatch • <?php if (isset($title)) {echo $title; @@ -149,4 +155,3 @@ </div> </div> </header> -<?php var_dump($this->session->userdata());?> From 7cc44ad44b611ee2cdff235b1bbbb732d7dc94b8 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles <mathieu.nayrolles@gmail.com> Date: Mon, 4 Jan 2016 20:38:23 -0500 Subject: [PATCH 08/19] debug messages --- application/views/header.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/application/views/header.php b/application/views/header.php index ac27ea49..4c21df02 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -3,7 +3,13 @@ <br /> <?php echo "RA" . $_SERVER['REMOTE_ADDR']; echo "<br />"; -echo "RA CF" . $_SERVER["HTTP_CF_CONNECTING_IP"]; +echo "RA CF " . $_SERVER["HTTP_CF_CONNECTING_IP"]; +echo "<br />"; +echo "RA HK "; +if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { + trim(end(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']))); +} + ?> <html lang="en"> <head> From 6fea8e05c4f4b716afd3acbbf9586e707925b465 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles <mathieu.nayrolles@gmail.com> Date: Mon, 4 Jan 2016 20:42:38 -0500 Subject: [PATCH 09/19] debug messages --- application/views/header.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/application/views/header.php b/application/views/header.php index 4c21df02..a2ecb173 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -7,7 +7,9 @@ echo "<br />"; echo "RA HK "; if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { - trim(end(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']))); + echo trim(end(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']))); + echo "<br />"; + echo $_SERVER['HTTP_X_FORWARDED_FOR']; } ?> From b4c071b583a82ff8e6ea6b1389e44fcd461b0ed3 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles <mathieu.nayrolles@gmail.com> Date: Mon, 4 Jan 2016 20:52:10 -0500 Subject: [PATCH 10/19] Hack index.php to use the cf ip or the heroku forwarded ip as remote_add --- index.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.php b/index.php index 1f4199bd..39680772 100644 --- a/index.php +++ b/index.php @@ -256,6 +256,12 @@ define('VIEWPATH', $view_folder); +if(isset($_SERVER["HTTP_CF_CONNECTING_IP"])){ + $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"]; +}else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){ + $_SERVER['REMOTE_ADDR'] = trim(end(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']))); +} + /* * -------------------------------------------------------------------- * LOAD THE BOOTSTRAP FILE From 4708ea7414438fcbecd13c53a076de3691d78c58 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles <mathieu.nayrolles@gmail.com> Date: Mon, 4 Jan 2016 20:52:58 -0500 Subject: [PATCH 11/19] remove ip switch in the event library --- application/libraries/Event.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/application/libraries/Event.php b/application/libraries/Event.php index a6155a0a..d7b4dc8a 100644 --- a/application/libraries/Event.php +++ b/application/libraries/Event.php @@ -9,9 +9,6 @@ public function updateObserver($subject, $event, $data) { public function add($event) { if (ENVIRONMENT === 'production') { - if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) { - $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"]; - } $country = "undefined"; @@ -48,4 +45,4 @@ public function add($event) { $result = curl_exec($ch); } } -} \ No newline at end of file +} From 01cf3bef7bd1116e70fd63884d674491dae162ee Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles <mathieu.nayrolles@gmail.com> Date: Tue, 5 Jan 2016 11:53:27 -0500 Subject: [PATCH 12/19] remove useless call to get_env --- application/libraries/Event.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/application/libraries/Event.php b/application/libraries/Event.php index d7b4dc8a..65630532 100644 --- a/application/libraries/Event.php +++ b/application/libraries/Event.php @@ -30,8 +30,6 @@ public function add($event) { $data_string = json_encode($data); - event_url(); - $ch = curl_init(event_url()); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); From 5a7d42f0a9a99d1671a40f5d8eec92b37f3f83b8 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles <mathieu.nayrolles@gmail.com> Date: Wed, 6 Jan 2016 11:59:34 -0500 Subject: [PATCH 13/19] updated app.json with newrelic --- app.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app.json b/app.json index de7bdfc5..4ecdc509 100644 --- a/app.json +++ b/app.json @@ -12,9 +12,16 @@ }, "TW_EVENT_URL": { "required": true + }, + "NEW_RELIC_APP_NAME": { + "required": true + }, + "NEW_RELIC_CONFIG_FILE": { + "required": true } }, "addons": [ - "cleardb" + "cleardb", + "newrelic" ] } From 266de45449465efd09cad382ab698ef43dac2cab Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles <mathieu.nayrolles@gmail.com> Date: Wed, 6 Jan 2016 11:59:34 -0500 Subject: [PATCH 14/19] updated app.json with newrelic --- app.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app.json b/app.json index de7bdfc5..4ecdc509 100644 --- a/app.json +++ b/app.json @@ -12,9 +12,16 @@ }, "TW_EVENT_URL": { "required": true + }, + "NEW_RELIC_APP_NAME": { + "required": true + }, + "NEW_RELIC_CONFIG_FILE": { + "required": true } }, "addons": [ - "cleardb" + "cleardb", + "newrelic" ] } From 9640ac12c36b831cd98d202812428da26d191851 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles <mathieu.nayrolles@gmail.com> Date: Wed, 6 Jan 2016 13:08:42 -0500 Subject: [PATCH 15/19] change error reporting --- index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/index.php b/index.php index 39680772..9b309211 100644 --- a/index.php +++ b/index.php @@ -65,7 +65,6 @@ */ switch (ENVIRONMENT) { case 'development': - error_reporting(-1); error_reporting(E_ALL&~E_NOTICE&~E_DEPRECATED&~E_STRICT&~E_USER_NOTICE&~E_USER_DEPRECATED); ini_set('display_errors', 1); break; From abc6e04a4ec927293a272f1cd4bec45f0ba74295 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles <mathieu.nayrolles@gmail.com> Date: Wed, 6 Jan 2016 13:10:21 -0500 Subject: [PATCH 16/19] insert obvious php error to check heroku error reporting --- index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/index.php b/index.php index 9b309211..bfffa979 100644 --- a/index.php +++ b/index.php @@ -67,6 +67,7 @@ case 'development': error_reporting(E_ALL&~E_NOTICE&~E_DEPRECATED&~E_STRICT&~E_USER_NOTICE&~E_USER_DEPRECATED); ini_set('display_errors', 1); + va break; case 'testing': From 08779d64c678a700b72d5e0da977fa13262a4d5d Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles <mathieu.nayrolles@gmail.com> Date: Wed, 6 Jan 2016 13:13:15 -0500 Subject: [PATCH 17/19] remove the error --- index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/index.php b/index.php index bfffa979..9b309211 100644 --- a/index.php +++ b/index.php @@ -67,7 +67,6 @@ case 'development': error_reporting(E_ALL&~E_NOTICE&~E_DEPRECATED&~E_STRICT&~E_USER_NOTICE&~E_USER_DEPRECATED); ini_set('display_errors', 1); - va break; case 'testing': From ed64c7606192e5f111ce1d8fa179ec5e1cb96768 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles <mathieu.nayrolles@gmail.com> Date: Wed, 6 Jan 2016 17:43:49 -0500 Subject: [PATCH 18/19] Optional post variables were treated as required + logging on controllers --- application/core/MY_Controller.php | 54 ++++++++++++++++++- application/core/MY_Log.php | 84 ++++++++++++++++++++++++++++++ application/core/MY_Model.php | 6 --- 3 files changed, 137 insertions(+), 7 deletions(-) create mode 100644 application/core/MY_Log.php diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 1a073c4e..56397d51 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -1,12 +1,22 @@ <?php if (!defined('BASEPATH')) {exit('No direct script access allowed'); } +/** + * Specialisation of CI_Controller that provided some additional services + * - headerdata + * - login gestion + * - post data check + * - logging + */ class MY_Controller extends CI_Controller { protected $_headerData = array(); protected $_bodyData = array(); protected $_footerData = array(); protected $_needLoggedIn = false; + /** + * Default constructor + */ public function __construct() { parent::__construct(); @@ -21,16 +31,58 @@ public function __construct() { } } + /** + * Convenient method to check that variables have been posted. + * In addition, all the variables contained in $postNames are copied in + * this. So you can access it by $this->myPostVariable. + * + * @param Array $postNames name of the variables expected to be posted + * @return Boolean returns true if all the variables were present + */ protected function expectsPost($postNames){ foreach ($postNames as $postName) { - if(!$this->input->post($postName)){ + + //If the variable is NULL (not posted), we log and exit + if($this->input->post($postName) === NULL){ + log_message('error', "Was expecting " . print_r($postNames, true) . + " got " . print_r($_POST, true)); return false; } + + //Add the variable in $this $this->{$postName} = $this->input->post($postName); } return true; } + /** + * Intercepts all method call on controller in order to provide logging + * capabilities. + * + * @param String $method the method name + * @param Array $params An array of get parameters (segments following the + * method segment) + * @return mixed Result of the method call + */ + public function _remap($method, $params = array()){ + + //Entry logging + $begin = new DateTime(); + log_message('info', 'Entering ' . get_class($this).':' + .$method .'->'.print_r($param, true)); + + //method execution + $result = call_user_func_array(array($this, $method), $params); + + //Exit logging + $end = new DateTime(); + $diff = $begin->diff($end); + log_message('info', 'Exiting ' . get_class($this).':' + .$method .' after '.$diff->format( '%H:%I:%S' ).'->' + .print_r($result, true) + ); + } + } diff --git a/application/core/MY_Log.php b/application/core/MY_Log.php new file mode 100644 index 00000000..825740ae --- /dev/null +++ b/application/core/MY_Log.php @@ -0,0 +1,84 @@ +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); + +// this class is adapted from system/libraries/Log.php +/** + * CodeIgniter + * + * An open source application development framework for PHP 5.1.6 or newer + * + * @package CodeIgniter + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. + * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com + * @since Version 1.0 + * @filesource + */ + +// ------------------------------------------------------------------------ + +/** + * Logging Class + * + * @package CodeIgniter + * @subpackage Libraries + * @category Logging + * @author EllisLab Dev Team + * @link http://codeigniter.com/user_guide/general/errors.html + */ +class MY_Log { + + protected $_threshold = 1; + protected $_date_fmt = 'Y-m-d H:i:s'; + protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + + /** + * Constructor + */ + public function __construct() + { + $config =& get_config(); + + if (is_numeric($config['log_threshold'])) + { + $this->_threshold = $config['log_threshold']; + } + + if ($config['log_date_format'] != '') + { + $this->_date_fmt = $config['log_date_format']; + } + } + + // -------------------------------------------------------------------- + + /** + * Write Log to php://stderr + * + * Generally this function will be called using the global log_message() function + * + * @param string the error level + * @param string the error message + * @param bool whether the error is a native PHP error + * @return bool + */ + public function write_log($level = 'error', $msg, $php_error = FALSE) + { + $level = strtoupper($level); + + if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) + { + return FALSE; + } + + file_put_contents('php://stderr', $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n"); + + return TRUE; + } + +} +// END Log Class + +/* End of file MY_Log.php */ +/* Location: ./application/libraries/MY_Log.php */ diff --git a/application/core/MY_Model.php b/application/core/MY_Model.php index 175138ff..f342a78a 100644 --- a/application/core/MY_Model.php +++ b/application/core/MY_Model.php @@ -557,8 +557,6 @@ public function find_all_by($field = null, $value = null, $type = 'and') { */ public function find_by($field = '', $value = '', $type = 'and') { if (empty($field) || (!is_array($field) && empty($value))) { - $this->error = lang('ff_model_find_error'); - $this->logit('['.get_class($this).': '.__METHOD__ .'] '.lang('ff_model_find_error')); return false; } @@ -980,8 +978,6 @@ public function delete_where($where = null) { */ public function is_unique($field = '', $value = '') { if (empty($field) || empty($value)) { - $this->error = lang('ff_model_unique_error'); - $this->logit('['.get_class($this).': '.__METHOD__ .'] '.lang('ff_model_unique_error')); return false; } @@ -1024,8 +1020,6 @@ public function count_all() { */ public function count_by($field = '', $value = null) { if (empty($field)) { - $this->error = lang('ff_model_count_error'); - $this->logit('['.get_class($this).': '.__METHOD__ .'] '.lang('ff_model_count_error')); return false; } From 62d221103bfecd05f9275e82bfa43d7e9b1313d0 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles <mathieu.nayrolles@gmail.com> Date: Wed, 6 Jan 2016 17:47:21 -0500 Subject: [PATCH 19/19] remove debug print of session --- application/views/header.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/application/views/header.php b/application/views/header.php index a2ecb173..b000c76c 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -1,18 +1,4 @@ <!DOCTYPE html> -<?php var_dump($this->session->userdata());?> -<br /> -<?php echo "RA" . $_SERVER['REMOTE_ADDR']; -echo "<br />"; -echo "RA CF " . $_SERVER["HTTP_CF_CONNECTING_IP"]; -echo "<br />"; -echo "RA HK "; -if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { - echo trim(end(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']))); - echo "<br />"; - echo $_SERVER['HTTP_X_FORWARDED_FOR']; -} - -?> <html lang="en"> <head> <title>Toolwatch • <?php if (isset($title)) {echo $title;