-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from AcclaroInc/develop
Develop
- Loading branch information
Showing
8 changed files
with
195 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Translations for Craft plugin for Craft CMS 3.x | ||
* | ||
* Translations for Craft eliminates error prone and costly copy/paste workflows for launching human translated Craft CMS web content. | ||
* | ||
* @link http://www.acclaro.com/ | ||
* @copyright Copyright (c) 2018 Acclaro | ||
*/ | ||
|
||
namespace acclaro\translations\services\job; | ||
|
||
use Craft; | ||
use Exception; | ||
|
||
use craft\queue\BaseJob; | ||
use craft\elements\Entry; | ||
use acclaro\translations\Translations; | ||
use acclaro\translations\services\job\UdpateReviewFileUrls; | ||
|
||
class RegeneratePreviewUrls extends BaseJob | ||
{ | ||
public $order; | ||
|
||
public function execute($queue) | ||
{ | ||
$totalElements = count($this->order->files); | ||
$currentElement = 0; | ||
|
||
foreach ($this->order->files as $file) { | ||
$this->setProgress($queue, $currentElement++ / $totalElements); | ||
$transaction = Craft::$app->getDb()->beginTransaction(); | ||
|
||
try { | ||
$draft = Translations::$plugin->draftRepository->getDraftById($file->draftId, $file->targetSite); | ||
$element = Craft::$app->getElements()->getElementById($file->elementId, null, $file->sourceSite); | ||
$file->previewUrl = Translations::$plugin->urlGenerator->generateElementPreviewUrl($draft, $file->targetSite); | ||
$file->source = Translations::$plugin->elementToXmlConverter->toXml( | ||
$element, | ||
$file->draftId, | ||
$file->sourceSite, | ||
$file->targetSite, | ||
$file->previewUrl | ||
); | ||
Translations::$plugin->fileRepository->saveFile($file); | ||
$transaction->commit(); | ||
} catch (\Throwable $e) { | ||
$transaction->rollBack(); | ||
throw $e; | ||
} | ||
} | ||
|
||
if ($this->order->translator->service !== 'export_import') { | ||
$translator = $this->order->getTranslator(); | ||
|
||
$translationService = Translations::$plugin->translatorFactory->makeTranslationService($translator->service, $translator->getSettings()); | ||
|
||
$translationService->udpateReviewFileUrls($this->order); | ||
} | ||
} | ||
|
||
protected function defaultDescription() | ||
{ | ||
return 'Regenerating preview urls'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Translations for Craft plugin for Craft CMS 3.x | ||
* | ||
* Translations for Craft eliminates error prone and costly copy/paste workflows for launching human translated Craft CMS web content. | ||
* | ||
* @link http://www.acclaro.com/ | ||
* @copyright Copyright (c) 2018 Acclaro | ||
*/ | ||
|
||
namespace acclaro\translations\services\job\acclaro; | ||
|
||
use Craft; | ||
use Exception; | ||
|
||
use craft\queue\BaseJob; | ||
use craft\elements\Entry; | ||
use acclaro\translations\Translations; | ||
use acclaro\translations\services\api\AcclaroApiClient; | ||
|
||
class UdpateReviewFileUrls extends BaseJob | ||
{ | ||
public $order; | ||
public $sandboxMode; | ||
public $settings; | ||
|
||
public function execute($queue) | ||
{ | ||
$acclaroApiClient = new AcclaroApiClient( | ||
$this->settings['apiToken'], | ||
!empty($this->settings['sandboxMode']) | ||
); | ||
|
||
$order = $this->order; | ||
|
||
$totalElements = count($order->files); | ||
$currentElement = 0; | ||
|
||
foreach ($order->files as $file) { | ||
$this->setProgress($queue, $currentElement++ / $totalElements); | ||
|
||
try { | ||
$acclaroApiClient->addReviewUrl( | ||
$order->serviceOrderId, | ||
$file->serviceFileId, | ||
$file->previewUrl | ||
); | ||
} catch (\Throwable $e) { | ||
throw $e; | ||
} | ||
} | ||
} | ||
|
||
protected function defaultDescription() | ||
{ | ||
return 'Updating Acclaro review urls'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters