Skip to content

Commit

Permalink
Check for already merged file from reverting back by callback
Browse files Browse the repository at this point in the history
  • Loading branch information
bhupeshappfoster authored Jan 20, 2024
1 parent f211a86 commit 87b0a6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions src/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ public function actionOrderCallback()
echo 'Starting file sync' . PHP_EOL;

foreach($order->getFiles() as $file) {
$translationService->updateFile($order, $file);
Translations::$plugin->fileRepository->saveFile($file);
// Only process the file is not already done
if ($file->isNew() || $file->isInProgress()) {
$translationService->updateFile($order, $file);
Translations::$plugin->fileRepository->saveFile($file);
}
}

echo 'File sync successful' . PHP_EOL;
Expand Down Expand Up @@ -178,16 +181,20 @@ public function actionFileCallback()
echo 'Translation service found'.PHP_EOL;
}

$translationService->updateFile($order, $file);

echo 'Updating file'.PHP_EOL;
// Skip if file already has target content
if ($file->isNew() || $file->isInProgress()) {
$translationService->updateFile($order, $file);

$success = Translations::$plugin->fileRepository->saveFile($file);
$success = Translations::$plugin->fileRepository->saveFile($file);

if (!$success) {
Craft::$app->end('Couldn’t save the file');
if (!$success) {
Craft::$app->end('Couldn’t save the file');
} else {
echo 'File saved'.PHP_EOL;
}
} else {
echo 'Saving file'.PHP_EOL;
echo 'File skipped'.PHP_EOL;
}

Craft::$app->end('OK');
Expand Down
2 changes: 1 addition & 1 deletion src/models/GlobalSetDraftModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function rules(): array
return $rules;
}

public function getFieldLayout(): ?\craft\models\FieldLayout
public function getFieldLayout(): \craft\models\FieldLayout
{
$globalSet = $this->getGlobalSet();

Expand Down

0 comments on commit 87b0a6c

Please sign in to comment.