Skip to content

Commit

Permalink
pre insert last batch in case something goes wrong during batch + jso…
Browse files Browse the repository at this point in the history
…n_encode error for slack #35
  • Loading branch information
MathieuNls committed Feb 17, 2016
1 parent e3107a3 commit 3a0b23e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion application/core/MY_Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function show_php_error($severity, $message, $filepath, $line)
.' at Line '.$line
.' at URL '.$_SERVER['HTTP_HOST'];

$data = '{"text": "'.$header.'"}';
$data = json_encode(["text"=>$header]);

$ch = curl_init(exception_url());

Expand Down
2 changes: 1 addition & 1 deletion application/core/MY_Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function write_log($level = 'error', $msg, $php_error = FALSE)
}

if($level === 'error' || $level === 'ERROR'){
$data = '{"text": "'.$_SERVER['HTTP_HOST'].'\n\r'.$msg.'"}';
$data = json_encode(["text"=>$_SERVER['HTTP_HOST'].'\n\r'.$msg]);

$ch = curl_init(exception_url());

Expand Down
22 changes: 14 additions & 8 deletions application/libraries/Auto_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,25 @@ public function cronCheck($timeOffset = 0) {

$this->lastBatchDate = $this->findLastBatchDate();

$emailBatchId = $this->emailBatchModel->insert(
array("time"=>$this->time,
"amount" => -1
)
);

//Apply all the rules for emails
//The emails arrays are sent by references and
//updated in the different methods
//$this->inactiveUser($emailsUserSent);

$this->inactiveUser($emailsUserSent);
$this->userWithoutWatch($emailsUserSent);
$this->userWithWatchWithoutMeasure($emailsWatchSent);
$this->userWithOneCompleteMeasureAndOneWatch($emailsUserSent);
$this->checkAccuracy($emailsMeasureSent);
$this->checkAccuracyOneWeek($emailsMeasureSent);
$this->startANewMeasure($emailsWatchSent);


if(ENVIRONMENT === "development" ||
ENVIRONMENT === "testing"){
$date = new DateTime("@".$this->time);
Expand All @@ -172,15 +180,13 @@ public function cronCheck($timeOffset = 0) {
}


$this->emailBatchModel->insert(
array("time"=>$this->time,
"amount" => sizeof($emailsMeasureSent)
+ sizeof($emailsWatchSent)
+ sizeof($emailsMeasureSent)
)
$this->emailBatchModel->update($emailBatchId,
["amount"=> sizeof($emailsMeasureSent)
+ sizeof($emailsWatchSent)
+ sizeof($emailsMeasureSent)
]
);


return array(
'users' => $emailsUserSent,
'watches' => $emailsWatchSent,
Expand Down

0 comments on commit 3a0b23e

Please sign in to comment.