Skip to content

Commit

Permalink
app metrics batch
Browse files Browse the repository at this point in the history
  • Loading branch information
Praesidiarius committed Apr 21, 2021
1 parent 27061d4 commit fae2941
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to oneplace-faucet-batch will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.4] - 2021-04-21

### Added
- App Metrics Batch

## [1.0.3] - 2021-04-15

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "onePlace Faucet Batch Module",
"type": "oneplace-module",
"license": "BSD-3-Clause",
"version": "1.0.3",
"version": "1.0.4",
"keywords": [
"laminas",
"mvc",
Expand Down
43 changes: 43 additions & 0 deletions src/Controller/BatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,47 @@ public function parsemailAction()

return $this->redirect()->toRoute('home');
}

public function appstatsAction()
{
$this->layout('layout/json');

$oMetricTbl = $this->getCustomTable('core_metric');
$aAppMetrics = [];
$oMetricSel = new Select($oMetricTbl->getTable());
$oMetricWh = new Where();
$oMetricWh->like('action', 'app-%');
$oMetricWh->greaterThanOrEqualTo('date', date('Y-m-d H:i:s',strtotime('-24 hours')));
$oMetricSel->where($oMetricWh);
$oAppMetricsDB = $oMetricTbl->selectWith($oMetricSel);
foreach($oAppMetricsDB as $oMet) {
if(!array_key_exists($oMet->action,$aAppMetrics)) {
$aAppMetrics[$oMet->action] = ['success' => 0,'error' => 0];
}
$aAppMetrics[$oMet->action][$oMet->type]++;
}


$oStatsTbl = new TableGateway('core_statistic', CoreEntityController::$oDbAdapter);
$oCheckWh = new Where();
$oCheckWh->like('stat-key', 'appmetrics-daily');
$oCheckWh->like('date', date('Y-m-d', time()).'%');
$oStatsCheck = $oStatsTbl->select($oCheckWh);

if(count($oStatsCheck) == 0) {
$oStatsTbl->insert([
'stat-key' => 'appmetrics-daily',
'date' => date('Y-m-d H:i:s', time()),
'stat-data' => json_encode($aAppMetrics),
]);
} else {
$oStatsTbl->update([
'stat-data' => json_encode($aAppMetrics),
],$oCheckWh);
}

echo 'done';

return false;
}
}
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Module {
*
* @since 1.0.0
*/
const VERSION = '1.0.3';
const VERSION = '1.0.4';

/**
* Load module config file
Expand Down

0 comments on commit fae2941

Please sign in to comment.