mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
Add default quantity units and locations to reduce confusion (only for new installations) (references #38)
This commit is contained in:
30
migrations/0031.php
Normal file
30
migrations/0031.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
// This is executed inside DatabaseMigrationService class/context
|
||||
|
||||
use \Grocy\Services\LocalizationService;
|
||||
$localizationService = new LocalizationService(GROCY_CULTURE);
|
||||
|
||||
$db = $this->DatabaseService->GetDbConnection();
|
||||
|
||||
if ($db->quantity_units()->count() === 0)
|
||||
{
|
||||
// Create 2 default quantity units
|
||||
$newRow = $db->quantity_units()->createRow(array(
|
||||
'name' => $localizationService->Localize('Piece')
|
||||
));
|
||||
$newRow->save();
|
||||
$newRow = $db->quantity_units()->createRow(array(
|
||||
'name' => $localizationService->Localize('Pack')
|
||||
));
|
||||
$newRow->save();
|
||||
}
|
||||
|
||||
if ($db->locations()->count() === 0)
|
||||
{
|
||||
// Create a default location
|
||||
$newRow = $db->locations()->createRow(array(
|
||||
'name' => $localizationService->Localize('Fridge')
|
||||
));
|
||||
$newRow->save();
|
||||
}
|
Reference in New Issue
Block a user