Skip to content

Commit

Permalink
Merge pull request #22 from AcclaroInc/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sidedwards authored Aug 22, 2019
2 parents 12d44d9 + 45d9407 commit e7cc180
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .craftplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"pluginName": "Translations for Craft",
"pluginDescription": "Easily launch and manage multilingual Craft websites without having to copy/paste content or manually track updates.",
"pluginVersion": "1.2.0",
"pluginVersion": "1.2.1",
"pluginAuthorName": "Acclaro",
"pluginVendorName": "Acclaro",
"pluginAuthorUrl": "http://www.acclaro.com/",
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.2.1 - 2019-08-21

### Added
- Added `RegeneratePreviewUrls` background task
- Added `acclaro/UdpateReviewFileUrls` background task

## 1.2.0 - 2019-08-16

> {warning} Due to a fundamental [change in Crafts internal draft service](https://github.com/craftcms/cms/blob/master/CHANGELOG-v3.md#320---2019-07-09) in 3.2+, we are unable to retain previously created translation drafts. If you are upgrading from Craft 3.1 or below to Craft 3.2+ please refer to our [upgrade guide](https://github.com/AcclaroInc/craft-translations/wiki/Translations-Upgrade-Workflow-(Craft-3.1-to-3.2-)) for important upgrade information.
Expand Down
30 changes: 30 additions & 0 deletions src/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use acclaro\translations\services\job\CreateDrafts;
use acclaro\translations\services\job\UpdateEntries;
use acclaro\translations\services\job\DeleteDrafts;
use acclaro\translations\services\job\RegeneratePreviewUrls;
use acclaro\translations\services\translator\AcclaroTranslationService;

/**
Expand Down Expand Up @@ -1151,6 +1152,35 @@ public function actionEditOrderName()
}
}

public function actionRegeneratePreviewUrls()
{
$this->requireLogin();
$this->requireAdmin();
$this->requirePostRequest();

$orderId = Craft::$app->getRequest()->getParam('orderId');

$order = Translations::$plugin->orderRepository->getOrderById($orderId);

if ($order) {
$job = Craft::$app->queue->push(new RegeneratePreviewUrls([
'description' => 'Regenerating preview urls for '. $order->title,
'order' => $order
]));

if ($job) {
$params = [
'id' => (int) $job,
'notice' => 'Done regenerating preview urls for '. $order->title,
'url' => 'translations/orders/detail/'. $order->id
];
Craft::$app->getView()->registerJs('$(function(){ Craft.Translations.trackJobProgressById(true, false, '. json_encode($params) .'); });');
} else {
$this->redirect('translations/orders', 302, true);
}
}
}

// Global Set CRUD Methods
// =========================================================================

Expand Down
4 changes: 2 additions & 2 deletions src/services/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function generateFileWebUrl(Element $element, FileModel $file)
return $element->url;
}

return $this->generateElementPreviewUrl($element, $file);
return $this->generateElementPreviewUrl($element, $file->targetSite);
}

public function generateCpUrl($path)
Expand All @@ -109,7 +109,7 @@ public function generateElementPreviewUrl(Element $element, $targetSite)

$className = get_class($element);

if ($className === Entry::class && $element->getStatus() === Entry::STATUS_LIVE) {
if ($className === Entry::class && !$element->getIsDraft()) {
$previewUrl = $element->getUrl();
} else {
$route = [
Expand Down
66 changes: 66 additions & 0 deletions src/services/job/RegeneratePreviewUrls.php
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';
}
}
58 changes: 58 additions & 0 deletions src/services/job/acclaro/UdpateReviewFileUrls.php
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';
}
}
14 changes: 14 additions & 0 deletions src/services/translator/AcclaroTranslationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use acclaro\translations\Translations;
use acclaro\translations\services\api\AcclaroApiClient;
use acclaro\translations\services\job\acclaro\SendOrder;
use acclaro\translations\services\job\acclaro\UdpateReviewFileUrls;

class AcclaroTranslationService implements TranslationServiceInterface
{
Expand Down Expand Up @@ -184,6 +185,19 @@ public function sendOrder(Order $order)
// Craft::$app->getView()->registerJs('$(function(){ Craft.Translations.trackJobProgressById(true, false, '. json_encode($params) .'); });');
// }
}

/**
* {@inheritdoc}
*/
public function udpateReviewFileUrls(Order $order)
{
$job = Craft::$app->queue->push(new UdpateReviewFileUrls([
'description' => 'Updating Acclaro review urls',
'order' => $order,
'sandboxMode' => $this->sandboxMode,
'settings' => $this->settings
]));
}

public function getOrderUrl(Order $order)
{
Expand Down
23 changes: 18 additions & 5 deletions src/templates/orders/_detail.twig
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,24 @@
</tbody>
</table>

{# {% if order.status == 'complete' %}
<a href="{{ url('translations/orders/entries/'~order.id) }}" class="btn submit">{{ 'View Entries & Bulk Publish'|t }}</a>
{% else %}
<a href="{{ url('translations/orders/entries/'~order.id) }}" class="btn submit">{{ 'View Entries in this Order'|t }}</a>
{% endif %} #}
{% if order.status != 'published' %}
<form id="regenerate-preview-urls" class="utility" method="post" accept-charset="UTF-8">
{{ csrfInput() }}
{{ forms.hidden({
name: 'action',
value: 'translations/base/regenerate-preview-urls',
}) }}

{{ forms.hidden({
name: 'orderId',
value: order.id
}) }}

<div class="buttons">
<input type="submit" class="btn right" value="{{ "Regenerate Preview Urls"|t('app') }}" />
</div>
</form>
{% endif %}

<div class="translations-order-detail-activity-log">
<h2>{{ 'Order Activity Log'|t }}</h2>
Expand Down

0 comments on commit e7cc180

Please sign in to comment.