Skip to content

Commit 2a3810d

Browse files
authored
Add mongodb (#23)
1 parent 9389000 commit 2a3810d

File tree

7 files changed

+482
-315
lines changed

7 files changed

+482
-315
lines changed

.github/workflows/php.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
services:
15+
mongo:
16+
image: mongo:latest
17+
env:
18+
MONGO_INITDB_ROOT_USERNAME: testing
19+
MONGO_INITDB_ROOT_PASSWORD: password
20+
MONGO_INITDB_DATABASE: testing
21+
ports:
22+
- 27017:27017
23+
1524
mssql:
1625
image: mcr.microsoft.com/mssql/server:2022-latest
1726
env:

app/Http/Controllers/DashboardStatsController.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public function index() {
5858
]);
5959
})
6060
->first();
61-
$maxDurationWorkflow->id = $maxDurationWorkflow->_id;
61+
if ($maxDurationWorkflow) {
62+
$maxDurationWorkflow->id = $maxDurationWorkflow->_id;
63+
}
6264
} else {
6365
$maxDurationWorkflow = config('workflows.stored_workflow_model', StoredWorkflow::class)::select('*')
6466
->when($dbDriverName === 'sqlite', function ($q) {
@@ -79,21 +81,24 @@ public function index() {
7981
}
8082

8183
if ($dbDriverName === 'mongodb') {
82-
$maxExceptionsWorkflow = null;
83-
84-
$mostExceptionWorkflowId = StoredWorkflowException::raw(function ($collection) {
84+
$maxExceptionsWorkflow = StoredWorkflowException::raw(function ($collection) {
8585
return $collection->aggregate([
8686
['$group' => ['_id' => '$stored_workflow_id', 'count' => ['$sum' => 1]]],
8787
['$sort' => ['count' => -1]],
8888
['$limit' => 1]
8989
]);
90-
})->first()['_id'];
90+
})->first();
9191

92-
$maxExceptionsWorkflow = StoredWorkflow::where('_id', $mostExceptionWorkflowId)->first();
92+
if ($maxExceptionsWorkflow) {
93+
$mostExceptionWorkflowId = $maxExceptionsWorkflow['_id'];
9394

94-
$maxExceptionsWorkflow->exceptions_count = StoredWorkflowException::where('stored_workflow_id', $mostExceptionWorkflowId)->count();
95+
$maxExceptionsWorkflow = StoredWorkflow::where('_id', $mostExceptionWorkflowId)->first();
9596

96-
$maxExceptionsWorkflow->id = $maxExceptionsWorkflow->_id;
97+
if ($maxExceptionsWorkflow) {
98+
$maxExceptionsWorkflow->exceptions_count = StoredWorkflowException::where('stored_workflow_id', $mostExceptionWorkflowId)->count();
99+
$maxExceptionsWorkflow->id = $maxExceptionsWorkflow->_id;
100+
}
101+
}
97102
} else {
98103
$maxExceptionsWorkflow = config('workflows.stored_workflow_model', StoredWorkflow::class)::withCount('exceptions')
99104
->has('exceptions')

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
},
1616
"require-dev": {
1717
"fakerphp/faker": "^1.9.1",
18+
"jenssegers/mongodb": "^3.9",
1819
"mockery/mockery": "^1.4.4",
19-
"orchestra/testbench": "8.9.1",
20+
"mongodb/mongodb": "1.11",
21+
"orchestra/testbench": "^7.29",
2022
"phpunit/phpunit": "^9.5.10"
2123
},
2224
"autoload": {
@@ -30,7 +32,8 @@
3032
}
3133
},
3234
"scripts": {
33-
"test": "composer test-mssql && composer test-mysql && composer test-pgsql && composer test-sqlite",
35+
"test": "composer test-mongo && composer test-mssql && composer test-mysql && composer test-pgsql && composer test-sqlite",
36+
"test-mongo": "vendor/bin/phpunit --testdox --configuration=phpunit-mongo.xml",
3437
"test-mssql": "vendor/bin/phpunit --testdox --configuration=phpunit-mssql.xml",
3538
"test-mysql": "vendor/bin/phpunit --testdox --configuration=phpunit-mysql.xml",
3639
"test-pgsql": "vendor/bin/phpunit --testdox --configuration=phpunit-pgsql.xml",

0 commit comments

Comments
 (0)