[TASK] move database-routes to Controller
This commit is contained in:
parent
2b956e827c
commit
5d927902cb
122
src/routes.php
122
src/routes.php
@ -55,127 +55,9 @@ $app->group('/api', function (RouteCollectorProxy $group): void {
|
|||||||
$group->get('/excel/download', SpreadsheetController::class . ':download');
|
$group->get('/excel/download', SpreadsheetController::class . ':download');
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->get('/migrate', DatabaseController::class . ':migrate')->setName('migrations');
|
$app->get('/migrate', DatabaseController::class . ':migrate')->setName('migrate');
|
||||||
|
|
||||||
$app->get('/seed', function (Request $request, Response $response, $args) {
|
$app->get('/seed', DatabaseController::class . ':seed')->setName('seed');
|
||||||
$db = $this->get('db');
|
|
||||||
|
|
||||||
if ($db::schema()->hasTable('dimensions')) {
|
|
||||||
$entries = [
|
|
||||||
[
|
|
||||||
'name' => 'Liter',
|
|
||||||
'short' => 'l'
|
|
||||||
], [
|
|
||||||
'name' => 'Stück',
|
|
||||||
'short' => 'Stk'
|
|
||||||
], [
|
|
||||||
'name' => 'Flasche',
|
|
||||||
'short' => 'Fl'
|
|
||||||
], [
|
|
||||||
'name' => 'Glas',
|
|
||||||
'short' => 'Gl'
|
|
||||||
], [
|
|
||||||
'name' => 'Tasse',
|
|
||||||
'short' => 'T'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
foreach ($entries as $item) {
|
|
||||||
try {
|
|
||||||
$db->table('dimensions')->insert($item);
|
|
||||||
} catch (\Throwable $th) {
|
|
||||||
$this->get('log')->error($th);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($db::schema()->hasTable('group')) {
|
|
||||||
$entries = [
|
|
||||||
[
|
|
||||||
'name' => 'Bier'
|
|
||||||
], [
|
|
||||||
'name' => 'afG Gastro'
|
|
||||||
], [
|
|
||||||
'name' => 'afG offen'
|
|
||||||
], [
|
|
||||||
'name' => 'Wein und Sekt'
|
|
||||||
], [
|
|
||||||
'name' => 'Fingerfood'
|
|
||||||
], [
|
|
||||||
'name' => 'Heißgetränke'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($entries as $item) {
|
|
||||||
try {
|
|
||||||
$db->table('group')->insert($item);
|
|
||||||
} catch (\Throwable $th) {
|
|
||||||
$this->get('log')->error($th);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($db::schema()->hasTable('sets')) {
|
|
||||||
$entries = [
|
|
||||||
[
|
|
||||||
'name' => 'UG'
|
|
||||||
], [
|
|
||||||
'name' => 'mobile'
|
|
||||||
], [
|
|
||||||
'name' => 'Studio'
|
|
||||||
], [
|
|
||||||
'name' => 'Domstufen'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($entries as $item) {
|
|
||||||
try {
|
|
||||||
$db->table('sets')->insert($item);
|
|
||||||
} catch (\Throwable $th) {
|
|
||||||
$this->get('log')->error($th);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($db::schema()->hasTable('articles')) {
|
|
||||||
$file = file_get_contents(__DIR__ . '/../data/articles.theater.json');
|
|
||||||
$entries = json_decode($file, true);
|
|
||||||
|
|
||||||
foreach ($entries as $entry) {
|
|
||||||
try {
|
|
||||||
$cDim = $db
|
|
||||||
->table('dimensions')
|
|
||||||
->where(
|
|
||||||
'short',
|
|
||||||
'=',
|
|
||||||
str_replace('.', '', $entry['dimension'])
|
|
||||||
)->first();
|
|
||||||
$pDim = $db
|
|
||||||
->table('dimensions')
|
|
||||||
->where(
|
|
||||||
'short',
|
|
||||||
'=',
|
|
||||||
str_replace('.', '', $entry['portion']['type'])
|
|
||||||
)->first();
|
|
||||||
$item = [
|
|
||||||
'name' => $entry['name'],
|
|
||||||
'short' => $entry['short'],
|
|
||||||
'content_size' => $entry['content']['size'],
|
|
||||||
'portion_size' => $entry['portion']['size'],
|
|
||||||
'content_dimension' => $cDim->id,
|
|
||||||
'portion_dimension' => $pDim->id,
|
|
||||||
'portion_price' => $entry['portion']['price'],
|
|
||||||
'group_id' => 1
|
|
||||||
];
|
|
||||||
print_r($item);
|
|
||||||
$db->table('articles')->insert($item);
|
|
||||||
} catch (\Throwable $th) {
|
|
||||||
$this->get('log')->error($th);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->get('view')->render($response, 'frontend.html', []);
|
|
||||||
})->setName('migrations');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move Uploaded File to Target Destination
|
* Move Uploaded File to Target Destination
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user