Fixed purchase/consume page handling when FEATURE_FLAG_STOCK_LOCATION_TRACKING is disabled (fixes #1829)

This commit is contained in:
Bernd Bestel
2022-03-23 17:34:51 +01:00
parent dce14b8999
commit bda230537a
4 changed files with 37 additions and 5 deletions

23
migrations/8888.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
// This migration is always executed (on every migration run, not only once)
// This is executed inside DatabaseMigrationService class/context
// When FEATURE_FLAG_STOCK_LOCATION_TRACKING is disabled,
// some places assume that there exists a location with id 1,
// so make sure that this location is available in that case
if (!GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
{
$db = $this->getDatabaseService()->GetDbConnection();
if ($db->locations()->where('id', 1)->count() === 0)
{
// Create 2 default quantity units
$defaultLocation = $db->locations()->createRow([
'id' => 1,
'name' => 'Default'
]);
$defaultLocation->save();
}
}