Skip to content
Code-Schnipsel Gruppen Projekte
Bestätigt Commit a6068c89 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

fix: uuid migration

Übergeordneter 6d2a3e09
No related branches found
No related tags found
2 Merge Requests!12Next,!11Dev
......@@ -41,5 +41,5 @@
<event on="onQuiqqerOrderSuccessful" fire="\QUI\ERP\Coupons\Events::removeCouponsFromSession"/>
<event on="onQuiqqer::order::orderProcessFinish" fire="\QUI\ERP\Coupons\Events::removeCouponsFromSession"/>
<event on="onQuiqqerMigrationV2" fire="\QUI\ERP\Coupons\Events::onQuiqqerMigrationV2"/>
</events>
......@@ -151,11 +151,11 @@ public function __construct(int $id)
$this->title = $data['title'];
if (!empty($data['usages'])) {
$this->usages = json_decode($data['usages'], true);
$this->usages = json_decode($data['usages'], true) ?? [];
}
if (!empty($data['userIds'])) {
$this->userIds = json_decode($data['userIds'], true);
$this->userIds = json_decode($data['userIds'], true) ?? [];
}
// migrate user ids
......@@ -169,7 +169,7 @@ public function __construct(int $id)
}
if (!empty($data['groupIds'])) {
$this->groupIds = json_decode($data['groupIds'], true);
$this->groupIds = json_decode($data['groupIds'], true) ?? [];
}
// migrate user ids
......@@ -187,7 +187,7 @@ public function __construct(int $id)
}
if (!empty($data['discountIds'])) {
$this->discountIds = json_decode($data['discountIds'], true);
$this->discountIds = json_decode($data['discountIds'], true) ?? [];
}
$this->CreateDate = new DateTime($data['createDate']);
......
......@@ -17,11 +17,15 @@
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 implode;
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 +780,58 @@ public static function onQuiqqerOrderCreated(AbstractOrder $Order): void
{
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]
);
}
}
}
}
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren