mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Added demo recreation handling
This commit is contained in:
parent
9c2ee58433
commit
6d4b86a730
@ -65,4 +65,12 @@ class GrocyDemoDataGenerator
|
||||
GrocyLogicHabits::TrackHabit(2, date('Y-m-d H:i:s', strtotime('-20 days')));
|
||||
}
|
||||
}
|
||||
|
||||
public static function RecreateDemo()
|
||||
{
|
||||
unlink(__DIR__ . '/data/grocy.db');
|
||||
|
||||
$db = Grocy::GetDbConnectionRaw(true);
|
||||
self::PopulateDemoData($db);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
{
|
||||
"require": {
|
||||
"slim/slim": "^3.8",
|
||||
"slim/php-view": "^2.2",
|
||||
"morris/lessql": "^0.3.4"
|
||||
}
|
||||
"require": {
|
||||
"slim/slim": "^3.8",
|
||||
"slim/php-view": "^2.2",
|
||||
"morris/lessql": "^0.3.4",
|
||||
"pavlakis/slim-cli": "^1.0"
|
||||
}
|
||||
}
|
||||
|
48
index.php
48
index.php
@ -13,14 +13,24 @@ require_once __DIR__ . '/GrocyLogicStock.php';
|
||||
require_once __DIR__ . '/GrocyLogicHabits.php';
|
||||
require_once __DIR__ . '/GrocyPhpHelper.php';
|
||||
|
||||
$app = new \Slim\App(new \Slim\Container([
|
||||
'settings' => [
|
||||
'displayErrorDetails' => true,
|
||||
'determineRouteBeforeAppMiddleware' => true
|
||||
],
|
||||
]));
|
||||
$container = $app->getContainer();
|
||||
$container['renderer'] = new PhpRenderer('./views');
|
||||
$app = new \Slim\App;
|
||||
|
||||
if (PHP_SAPI !== 'cli')
|
||||
{
|
||||
$app = new \Slim\App(new \Slim\Container([
|
||||
'settings' => [
|
||||
'displayErrorDetails' => true,
|
||||
'determineRouteBeforeAppMiddleware' => true
|
||||
],
|
||||
]));
|
||||
$container = $app->getContainer();
|
||||
$container['renderer'] = new PhpRenderer('./views');
|
||||
}
|
||||
|
||||
if (PHP_SAPI === 'cli')
|
||||
{
|
||||
$app->add(new \pavlakis\cli\CliRequest());
|
||||
}
|
||||
|
||||
if (!Grocy::IsDemoInstallation())
|
||||
{
|
||||
@ -430,4 +440,26 @@ $app->group('/api', function() use($db)
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
});
|
||||
|
||||
$app->group('/cli', function()
|
||||
{
|
||||
$this->get('/recreatedemo', function(Request $request, Response $response)
|
||||
{
|
||||
if (Grocy::IsDemoInstallation())
|
||||
{
|
||||
GrocyDemoDataGenerator::RecreateDemo();
|
||||
}
|
||||
});
|
||||
})->add(function($request, $response, $next)
|
||||
{
|
||||
$response = $next($request, $response);
|
||||
|
||||
if (PHP_SAPI !== 'cli')
|
||||
{
|
||||
echo 'Please call this only from CLI';
|
||||
return $response->withHeader('Content-Type', 'text/plain')->withStatus(400);
|
||||
}
|
||||
|
||||
return $response->withHeader('Content-Type', 'text/plain');
|
||||
});
|
||||
|
||||
$app->run();
|
||||
|
Loading…
x
Reference in New Issue
Block a user