rvr-nextgen/database/migrations/data/20230428_1826_community_main_currency.php
Pőcze Bence e0ea18a6d0
All checks were successful
rvr-nextgen/pipeline/pr-master This commit looks good
RVRNEXT-5 migration for main_currency_id
2023-04-28 21:06:36 +02:00

20 lines
659 B
PHP

<?php
use RVR\PersistentData\Model\Community;
use RVR\PersistentData\Model\Currency;
use SokoWeb\Database\Query\Select;
$select = new Select(Container::$dbConnection);
$communities = Container::$persistentDataManager->selectMultipleFromDb($select, Community::class);
foreach ($communities as $community) {
$mainCurrency = new Currency();
$mainCurrency->setCommunity($community);
$mainCurrency->setCode($community->getCurrency());
$mainCurrency->setRoundDigits(0);
Container::$persistentDataManager->saveToDb($mainCurrency);
$community->setMainCurrency($mainCurrency);
Container::$persistentDataManager->saveToDb($community);
}