mirror of
https://github.com/grocy/grocy.git
synced 2025-08-16 18:54:35 +00:00
Added demo recreation handling
This commit is contained in:
@@ -65,4 +65,12 @@ class GrocyDemoDataGenerator
|
|||||||
GrocyLogicHabits::TrackHabit(2, date('Y-m-d H:i:s', strtotime('-20 days')));
|
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": {
|
"require": {
|
||||||
"slim/slim": "^3.8",
|
"slim/slim": "^3.8",
|
||||||
"slim/php-view": "^2.2",
|
"slim/php-view": "^2.2",
|
||||||
"morris/lessql": "^0.3.4"
|
"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__ . '/GrocyLogicHabits.php';
|
||||||
require_once __DIR__ . '/GrocyPhpHelper.php';
|
require_once __DIR__ . '/GrocyPhpHelper.php';
|
||||||
|
|
||||||
$app = new \Slim\App(new \Slim\Container([
|
$app = new \Slim\App;
|
||||||
'settings' => [
|
|
||||||
'displayErrorDetails' => true,
|
if (PHP_SAPI !== 'cli')
|
||||||
'determineRouteBeforeAppMiddleware' => true
|
{
|
||||||
],
|
$app = new \Slim\App(new \Slim\Container([
|
||||||
]));
|
'settings' => [
|
||||||
$container = $app->getContainer();
|
'displayErrorDetails' => true,
|
||||||
$container['renderer'] = new PhpRenderer('./views');
|
'determineRouteBeforeAppMiddleware' => true
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
$container = $app->getContainer();
|
||||||
|
$container['renderer'] = new PhpRenderer('./views');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PHP_SAPI === 'cli')
|
||||||
|
{
|
||||||
|
$app->add(new \pavlakis\cli\CliRequest());
|
||||||
|
}
|
||||||
|
|
||||||
if (!Grocy::IsDemoInstallation())
|
if (!Grocy::IsDemoInstallation())
|
||||||
{
|
{
|
||||||
@@ -430,4 +440,26 @@ $app->group('/api', function() use($db)
|
|||||||
return $response->withHeader('Content-Type', 'application/json');
|
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();
|
$app->run();
|
||||||
|
Reference in New Issue
Block a user