Skip to content
Code-Schnipsel Gruppen Projekte

Next

Zusammengeführt Henning Leutz schlägt vor, next in master zu mergen.
1 Datei
+ 0
2
Änderungen vergleichen
  • Nebeneinander
  • In der Reihe
@@ -16,12 +16,14 @@ use QUI\ERP\Order\Basket\Basket;
use QUI\ERP\Products\Handler\Fields;
use QUI\ERP\Products\Interfaces\ProductInterface;
use QUI\Smarty\Collector;
use QUI\System\Console\Tools\MigrationV2;
use function array_merge;
use function array_search;
use function array_unique;
use function in_array;
use function is_array;
use function is_numeric;
use function is_string;
use function json_decode;
use function json_encode;
@@ -776,4 +778,58 @@ class Events
{
QUI\ERP\Coupons\Products\Handler::createCouponCodesFromOrder($Order);
}
public static function onQuiqqerMigrationV2(MigrationV2 $Console): void
{
$Console->writeLn('- Migrate coupons');
$table = QUI::getDBTableName('quiqqer_coupons');
$result = QUI::getDataBase()->fetch([
'from' => $table
]);
foreach ($result as $entry) {
$id = $entry['id'];
$userIds = $entry['userIds'];
$groupIds = $entry['groupIds'];
if (!empty($userIds)) {
$userIds = json_decode($userIds, true) ?? [];
foreach ($userIds as $k => $userId) {
if (is_numeric($userId)) {
try {
$userIds[$k] = QUI::getUsers()->get($userId)->getUUID();
} catch (QUI\Exception) {
}
}
}
QUI::getDataBase()->update(
$table,
['userIds' => json_encode($userIds)],
['id' => $id]
);
}
if (!empty($groupIds)) {
$groupIds = json_decode($groupIds, true) ?? [];
foreach ($groupIds as $k => $groupId) {
if (is_numeric($groupId)) {
try {
$groupIds[$k] = QUI::getGroups()->get($groupId)->getUUID();
} catch (QUI\Exception) {
}
}
}
QUI::getDataBase()->update(
$table,
['groupIds' => json_encode($groupIds)],
['id' => $id]
);
}
}
}
}