Skip to content
Code-Schnipsel Gruppen Projekte

Revisionen vergleichen

Änderungen werden so angezeigt, als ob die Quellrevision mit der Zielrevision zusammengeführt würde. Erfahre mehr über den Vergleich von Revisionen.

Quelle

Zielprojekt auswählen
No results found

Ziel

Zielprojekt auswählen
  • quiqqer/coupons
1 Ergebnis
Änderungen anzeigen
Commits auf Quelle (4)
......@@ -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']);
......
......@@ -16,12 +16,14 @@
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 @@ 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]
);
}
}
}
}