Skip to content

Commit 5078cd4

Browse files
committed
feat: add reset flag general setting
1 parent c7a0ee9 commit 5078cd4

File tree

10 files changed

+81
-59
lines changed

10 files changed

+81
-59
lines changed

src/Controller/StatusController.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,17 +377,24 @@ public function getResetStatus(Context $context): JsonResponse
377377
}
378378

379379
#[Route(
380-
path: '/api/_action/migration/messenger-stats',
381-
name: 'api.admin.migration.messenger-stats',
380+
path: '/api/_action/migration/is-resetting-checksums',
381+
name: 'api.admin.migration.is-resetting-checksums',
382382
defaults: ['_acl' => ['admin']],
383383
methods: [Request::METHOD_GET]
384384
)]
385-
public function getMigrationMessengerStats(Context $context): JsonResponse
385+
public function isResettingChecksums(Context $context): JsonResponse
386386
{
387-
$messages = $this->runService->getMigrationMessengerStats($context);
387+
$settings = $this->generalSettingRepo
388+
->search(new Criteria(), $context)
389+
->getEntities()
390+
->first();
388391

389-
return new JsonResponse([
390-
'messages' => $messages,
391-
]);
392+
if ($settings === null) {
393+
return new JsonResponse(false);
394+
}
395+
396+
return new JsonResponse(
397+
$settings->isResettingChecksums()
398+
);
392399
}
393400
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* (c) shopware AG <[email protected]>
4+
* For the full copyright and license information, please view the LICENSE
5+
* file that was distributed with this source code.
6+
*/
7+
8+
namespace SwagMigrationAssistant\Core\Migration;
9+
10+
use Doctrine\DBAL\Connection;
11+
use Shopware\Core\Framework\Log\Package;
12+
use Shopware\Core\Framework\Migration\MigrationStep;
13+
14+
#[Package('fundamentals@after-sales')]
15+
class Migration1759000000AddIsResettingChecksumsToSetting extends MigrationStep
16+
{
17+
public function getCreationTimestamp(): int
18+
{
19+
return 1759000000;
20+
}
21+
22+
public function update(Connection $connection): void
23+
{
24+
$connection->executeStatement(<<<SQL
25+
ALTER TABLE `swag_migration_general_setting` ADD `is_resetting_checksums` TINYINT(1) NOT NULL DEFAULT '0';
26+
SQL);
27+
}
28+
}

src/Migration/MessageQueue/Handler/ResetChecksumHandler.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function __invoke(ResetChecksumMessage $message): void
8080
$batchSize = \count($ids);
8181

8282
if ($batchSize === 0) {
83+
$this->clearResettingChecksumsFlag();
8384
$this->dispatchCompletionMessage(
8485
$message,
8586
$progress
@@ -107,6 +108,7 @@ public function __invoke(ResetChecksumMessage $message): void
107108
}
108109

109110
if ($batchSize < self::BATCH_SIZE) {
111+
$this->clearResettingChecksumsFlag();
110112
$this->dispatchCompletionMessage(
111113
$message,
112114
$progress,
@@ -205,4 +207,11 @@ private function updateProgress(ResetChecksumMessage $message, int $processed, i
205207

206208
return $progress;
207209
}
210+
211+
private function clearResettingChecksumsFlag(): void
212+
{
213+
$this->connection->executeStatement(
214+
'UPDATE swag_migration_general_setting SET `is_resetting_checksums` = 0;'
215+
);
216+
}
208217
}

src/Migration/Run/RunService.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ public function startCleanupMappingChecksums(string $connectionId, Context $cont
179179
throw MigrationException::noConnectionFound();
180180
}
181181

182+
$this->dbalConnection->executeStatement(
183+
'UPDATE swag_migration_general_setting SET `is_resetting_checksums` = 1;'
184+
);
185+
182186
$this->bus->dispatch(new ResetChecksumMessage(
183187
$connectionId,
184188
$context,
@@ -255,24 +259,6 @@ public function assignThemeToSalesChannel(string $runUuid, Context $context): vo
255259
$this->loggingService->saveLogging($context);
256260
}
257261

258-
/**
259-
* @return list<mixed>
260-
*/
261-
public function getMigrationMessengerStats(Context $context): array
262-
{
263-
$query = $this->dbalConnection->createQueryBuilder();
264-
$query->select('JSON_EXTRACT(headers, "$.type") as message_type')
265-
->from('messenger_messages')
266-
->where($query->expr()->like('headers', ':namespace'))
267-
->andWhere($query->expr()->isNull('delivered_at'))
268-
->groupBy('message_type')
269-
->orderBy('message_type', 'ASC');
270-
271-
return $query->setParameter('namespace', '%SwagMigrationAssistant%')
272-
->executeQuery()
273-
->fetchFirstColumn();
274-
}
275-
276262
/**
277263
* @param array<int, string> $dataSelectionIds
278264
*/

src/Migration/Run/RunServiceInterface.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ public function startCleanupMappingChecksums(string $connectionUuid, Context $co
3838

3939
public function startCleanupMigrationData(Context $context): void;
4040

41-
/**
42-
* @return list<mixed>
43-
*/
44-
public function getMigrationMessengerStats(Context $context): array;
45-
4641
/**
4742
* @param array<int, string> $dataSelectionIds
4843
*/

src/Migration/Setting/GeneralSettingDefinition.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected function defineFields(): FieldCollection
4646
(new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()),
4747
new FkField('selected_connection_id', 'selectedConnectionId', SwagMigrationConnectionDefinition::class),
4848
new BoolField('is_reset', 'isReset'),
49+
new BoolField('is_resetting_checksums', 'isResettingChecksums'),
4950
new CreatedAtField(),
5051
new UpdatedAtField(),
5152
new ManyToOneAssociationField('selectedConnection', 'selected_connection_id', SwagMigrationConnectionDefinition::class, 'id', true),

src/Migration/Setting/GeneralSettingEntity.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class GeneralSettingEntity extends Entity
2323

2424
protected bool $isReset;
2525

26+
protected bool $isResettingChecksums = false;
27+
2628
public function getSelectedConnectionId(): ?string
2729
{
2830
return $this->selectedConnectionId;
@@ -52,4 +54,14 @@ public function setIsReset(bool $isReset): void
5254
{
5355
$this->isReset = $isReset;
5456
}
57+
58+
public function isResettingChecksums(): bool
59+
{
60+
return $this->isResettingChecksums;
61+
}
62+
63+
public function setIsResettingChecksums(bool $isResettingChecksums): void
64+
{
65+
$this->isResettingChecksums = $isResettingChecksums;
66+
}
5567
}

src/Resources/app/administration/src/core/service/api/swag-migration.api.service.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,18 +399,16 @@ export default class MigrationApiService extends ApiService {
399399
});
400400
}
401401

402-
async getMigrationMessengerStats(): Promise<{ messages: string[] }> {
402+
async isResettingChecksums(): Promise<boolean> {
403403
// @ts-ignore
404404
const headers = this.getBasicHeaders();
405405

406406
// @ts-ignore
407-
return this.httpClient
408-
.get(`_action/${this.getApiBasePath()}/messenger-stats`, {
409-
...this.basicConfig,
410-
headers,
411-
})
412-
.then((response) => {
413-
return ApiService.handleResponse(response);
414-
});
407+
return this.httpClient.get(`_action/${this.getApiBasePath()}/is-resetting-checksums`, {
408+
...this.basicConfig,
409+
headers,
410+
}).then((response: AxiosResponse) => {
411+
return ApiService.handleResponse(response);
412+
});
415413
}
416414
}

src/Resources/app/administration/src/module/swag-migration/component/card/swag-migration-shop-information/index.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ const BADGE_TYPE = {
2222

2323
const MIGRATION_RESET_CHECKSUM_POLLING_INTERVAL = 2500 as const;
2424

25-
const MIGRATION_RESET_CHECKSUM_MESSAGE = 'ResetChecksumMessage' as const;
26-
2725
/**
2826
* @private
2927
*/
@@ -231,7 +229,7 @@ export default Shopware.Component.wrapComponentConfig({
231229

232230
try {
233231
const [isResetting] = await Promise.all([
234-
this.checkIsResettingChecksum(),
232+
this.migrationApiService.isResettingChecksums(),
235233
this.updateLastMigrationDate(),
236234
]);
237235

@@ -267,16 +265,16 @@ export default Shopware.Component.wrapComponentConfig({
267265
this.unregisterPolling();
268266

269267
this.migrationStore.setIsResettingChecksum(true);
270-
this.pollingIntervalId = setInterval(this.resetCheckSumRoller, MIGRATION_RESET_CHECKSUM_POLLING_INTERVAL);
268+
this.pollingIntervalId = setInterval(this.resetCheckSumPoller, MIGRATION_RESET_CHECKSUM_POLLING_INTERVAL);
271269
},
272270

273-
async resetCheckSumRoller() {
271+
async resetCheckSumPoller() {
274272
if (!this.isResettingChecksum) {
275273
return;
276274
}
277275

278276
try {
279-
if ((await this.checkIsResettingChecksum()) === false) {
277+
if ((await this.migrationApiService.isResettingChecksums()) === false) {
280278
this.unregisterPolling();
281279
}
282280
} catch {
@@ -288,18 +286,6 @@ export default Shopware.Component.wrapComponentConfig({
288286
}
289287
},
290288

291-
async checkIsResettingChecksum(): Promise<boolean> {
292-
const response = await this.migrationApiService.getMigrationMessengerStats();
293-
294-
return (
295-
(Array.isArray(response?.messages) &&
296-
response.messages.some((msg: string) => {
297-
return msg.toLowerCase().includes(MIGRATION_RESET_CHECKSUM_MESSAGE.toLowerCase());
298-
})) ||
299-
false
300-
);
301-
},
302-
303289
async updateLastMigrationDate() {
304290
const criteria = new Criteria(1, 1).addSorting(Criteria.sort('createdAt', 'DESC'));
305291

tests/Profile/Shopware/Gateway/Local/SeoUrlReaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ private function setRouterToLowerValue(bool $value): void
110110
)->fetchOne();
111111

112112
if (!\is_string($value)) {
113-
$connection->executeQuery(
113+
$connection->executeStatement(
114114
'INSERT INTO `s_core_config_values` (`element_id`, `shop_id`, `value`) VALUES (:elementId, :shopId, :value)',
115115
['elementId' => $elementId, 'shopId' => 1, 'value' => $serializedValue]
116116
);
117117

118118
return;
119119
}
120120

121-
$connection->executeQuery(
121+
$connection->executeStatement(
122122
'UPDATE `s_core_config_values` SET `value` = :value WHERE `element_id` = :elementId AND `shop_id` = 1;',
123123
['elementId' => $elementId, 'value' => $serializedValue]
124124
);

0 commit comments

Comments
 (0)