Skip to content

Commit

Permalink
Release/3.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bhupeshappfoster committed Jan 24, 2024
1 parent 294c216 commit ce1687b
Show file tree
Hide file tree
Showing 19 changed files with 420 additions and 41 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": "Drive global growth with simplified translation workflows.",
"pluginVersion": "3.3.3",
"pluginVersion": "3.3.4",
"pluginAuthorName": "Acclaro",
"pluginVendorName": "Acclaro",
"pluginAuthorUrl": "http://www.acclaro.com/",
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ 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/).

## 3.3.4 - 2024-01-24

### Fixed
- An issue where applied files status reverting back to `ready for review` when a callback is received. ([AcclaroInc#520](https://github.com/AcclaroInc/craft-translations/pull/487))

### Added
- New activity logs table for better log management. ([AcclaroInc#521](https://github.com/AcclaroInc/craft-translations/pull/488))
- Support for CKEditor field. ([AcclaroInc#490](https://github.com/AcclaroInc/craft-translations/pull/491))

## 3.3.3 - 2023-12-14

### Fixed
Expand Down
8 changes: 5 additions & 3 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Constants
self::TRANSLATOR_DEFAULT => 'Export_Import',
self::TRANSLATOR_GOOGLE => 'Google',
];

const TRANSLATOR_LABELS = [
self::TRANSLATOR_ACCLARO => 'Acclaro API Token<p class="fs-12">Don\'t have an Acclaro API key? <a target="_blank" href="https://info.acclaro.com/my-acclaro-registration">Register here</a></p>',
self::TRANSLATOR_GOOGLE => 'Google API Token<p class="fs-12">Don\'t have a Google API key? <a target="_blank" href="https://cloud.google.com/translate/">Register here</a></p>',
Expand Down Expand Up @@ -97,7 +97,7 @@ class Constants
// Acclaro Constants
const PRODUCTION_URL = 'https://my.acclaro.com/api/v2/';
const SANDBOX_URL = 'https://apisandbox.acclaro.com/api/v2/';

const GOOGLE_TRANSLATE_API_URL= 'https://translation.googleapis.com/language/translate/v2';

const DELIVERY = 'craftcms';
Expand Down Expand Up @@ -169,6 +169,7 @@ class Constants
const TABLE_GLOBAL_SET_DRAFT = '{{%translations_globalsetdrafts}}';
const TABLE_ASSET_DRAFT = '{{%translations_assetdrafts}}';
const TABLE_COMMERCE_DRAFT = '{{%translations_commercedrafts}}';
const TABLE_ACTIVITY_LOG = '{{%translations_activitylogs}}';

// Job Descriptions
const JOB_ACCLARO_UPDATING_REVIEW_URL = 'Updating Acclaro review urls';
Expand Down Expand Up @@ -279,7 +280,7 @@ class Constants
'craft\fields\MultiSelect',
'craft\fields\RadioButtons',
'benf\neo\Field',
'verbb\vizy\fields\VizyField',
'verbb\vizy\fields\VizyField',
'typedlinkfield\fields\LinkField',
'craft\redactor\Field',
'fruitstudios\linkit\fields\LinkitField',
Expand All @@ -302,6 +303,7 @@ class Constants
'amici\SuperDynamicFields\fields\SueprDynamicRadioField',
'amici\SuperDynamicFields\fields\SueprDynamicCheckboxesField',
'amici\SuperDynamicFields\fields\SueprDynamicMultiSelectField',
'craft\ckeditor\Field',
];

const UNRELATED_FIELD_TYPES = [
Expand Down
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
11 changes: 7 additions & 4 deletions src/controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,19 +435,20 @@ public function actionSaveOrder()
return $this->asFailure($this->getErrorMessage("Source site is not supported."));
}

$logInfo = "";
if ($orderId && ! $createDraft) {
// This is for draft converting to order.
$order = $this->service->getOrderById($orderId);

$order->logActivity(Translations::$plugin->translator->translate('app', 'Order created'));
$logInfo = "Order Created";
} elseif ($orderId && $createDraft && $this->service->getOrderById($orderId)?->isPending()) {
// This is for user saving changes made in existing draft
$order = $this->service->getOrderById($orderId);
$logInfo = "Order draft Updated";
} else {
$order = $this->service->makeNewOrder($sourceSite);

$logInfo = $createDraft ? 'Order draft created' : 'Order created';
$order->logActivity(Translations::$plugin->translator->translate('app', $logInfo));
}

$job = '';
Expand Down Expand Up @@ -553,6 +554,8 @@ public function actionSaveOrder()
return $this->asFailure($this->getErrorMessage("Error saving Order."));
}

$order->logActivity(Translations::$plugin->translator->translate('app', $logInfo));

if (! $createDraft) {
// Check supported languages for order service
if ($order->getTranslator()->service === Constants::TRANSLATOR_ACCLARO) {
Expand Down Expand Up @@ -640,12 +643,12 @@ public function actionSaveOrder()
);
}
}

$orderAction = sprintf('Order submitted to %s', $order->translator->getName());

if ($order->requestQuote())
$orderAction = sprintf('Order quote requested from %s', $order->translator->getName());

$order->logActivity(Translations::$plugin->translator->translate('app', $orderAction));
}

Expand Down
48 changes: 48 additions & 0 deletions src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use acclaro\translations\Translations;
use acclaro\translations\elements\Order;
use acclaro\translations\services\job\DeleteDrafts;
use craft\web\Response;

/**
* @author Acclaro
Expand Down Expand Up @@ -305,4 +306,51 @@ public function actionSaveConfigurationOptions()
$this->setError($th->getMessage());
}
}

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

if (!Translations::$plugin->userRepository->userHasAccess('translations:settings')) {
return $this->asFailure($this->getErrorMessage("User not allowed to perform this action."));
}

$activityLogs = Translations::$plugin->activityLogRepository->getActivityLogs();

// Check if there are any activity logs
if (empty($activityLogs)) {
// Handle the case when there are no activity logs, show a message
return $this->asFailure($this->getErrorMessage('No activity logs available.'));
}

// Start output buffering
ob_start();

$output = fopen('php://output', 'w');

// Write CSV header
$header = array_keys($activityLogs[0]->attributes);
fputcsv($output, $header);

// Write CSV data
foreach ($activityLogs as $activityLog) {
fputcsv($output, $activityLog->attributes);
}

fclose($output);

// Get the buffer contents and clean the buffer
$content = ob_get_clean();

// Set up the response
$response = Craft::$app->getResponse();
$response->format = Response::FORMAT_RAW;
$response->headers->add('Content-Type', 'text/csv');
$response->headers->add('Content-Disposition', 'attachment; filename="activity-logs'.time().'.csv"');
$response->content = $content;

// Return the response
return $response;
}
}
22 changes: 5 additions & 17 deletions src/elements/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ class Order extends Element

public $comments;

public $activityLog;

public $dateOrdered;

public $serviceOrderId;
Expand Down Expand Up @@ -458,7 +456,7 @@ public function getTargetAlertHtml() {
public function rules(): array
{
$rules = parent::rules();
$rules[] = [['translatorId', 'ownerId', 'sourceSite', 'targetSites', 'activityLog', 'entriesCount', 'wordCount', 'elementIds',],'required'];
$rules[] = [['translatorId', 'ownerId', 'sourceSite', 'targetSites', 'entriesCount', 'wordCount', 'elementIds',],'required'];
$rules[] = [['sourceSite'], SiteIdValidator::class];
$rules[] = [['wordCount', 'entriesCount'], NumberValidator::class];
$rules[] = ['status', 'default', 'value' => 'pending'];
Expand Down Expand Up @@ -610,23 +608,14 @@ public function getTargetSitesArray()
return $this->targetSites ? json_decode($this->targetSites, true) : array();
}

public function getActivityLogArray()
public function logActivity($message)
{
$str = $this->activityLog;

return $str ? json_decode($str, true) : array();
return Translations::$plugin->activityLogRepository->createActivityLog($message, $this);
}

public function logActivity($message)
public function getActivityLogs()
{
$activityLog = $this->getActivityLogArray();

$activityLog[] = array(
'date' => date('n/j/Y'),
'message' => $message,
);

$this->activityLog = json_encode($activityLog);
return Translations::$plugin->activityLogRepository->getActivityLogsByTargetId($this);
}

public function getCpEditUrl(): ?string
Expand Down Expand Up @@ -895,7 +884,6 @@ public function afterSave(bool $isNew): void
$record->requestedDueDate = $this->requestedDueDate;
$record->orderDueDate = $this->orderDueDate;
$record->comments = $this->comments;
$record->activityLog = $this->activityLog;
$record->dateOrdered = $this->dateOrdered;
$record->serviceOrderId = $this->serviceOrderId;
$record->entriesCount = $this->entriesCount;
Expand Down
17 changes: 16 additions & 1 deletion src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ protected function createTables()
'requestedDueDate' => $this->dateTime(),
'orderDueDate' => $this->dateTime(),
'comments' => $this->text(),
'activityLog' => $this->longText(),
'dateOrdered' => $this->dateTime(),
'serviceOrderId' => $this->string()->defaultValue(''),
'entriesCount' => $this->integer()->notNull(),
Expand Down Expand Up @@ -245,6 +244,22 @@ protected function createTables()
);
}

$tableSchema = Craft::$app->db->schema->getTableSchema(Constants::TABLE_ACTIVITY_LOG);
if ($tableSchema === null) {
$tablesCreated = true;
$this->createTable(
Constants::TABLE_ACTIVITY_LOG,
[
'id' => $this->primaryKey(),
'message' => $this->text(),
'targetclass' => $this->string()->notNull(),
'targetId' => $this->integer()->notNull(),
'created' => $this->dateTime()->notNull(),
'actions' => $this->text()
]
);
}

return $tablesCreated;
}

Expand Down
63 changes: 63 additions & 0 deletions src/migrations/m240117_112821_create_activity_logs_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace acclaro\translations\migrations;

use acclaro\translations\Constants;
use craft\db\Migration;

/**
* Combined migration for dropping activityLog column and creating activity_log table.
*/
class m240117_112821_create_activity_logs_table extends Migration
{
/**
* @inheritdoc
*/
public function safeUp(): bool
{
// Create activity_log table
$this->createTable(Constants::TABLE_ACTIVITY_LOG, [
'id' => $this->primaryKey(),
'targetId' => $this->integer()->notNull(),
'targetClass' => $this->string()->notNull(),
'created' => $this->dateTime()->notNull(),
'message' => $this->text(),
'actions' => $this->text()
]);

$this->createIndex(null, Constants::TABLE_ACTIVITY_LOG, ['targetId']);
$this->createIndex(null, Constants::TABLE_ACTIVITY_LOG, ['targetClass']);

// Move data from activityLog column to activity_log table
$data = $this->db->createCommand('SELECT id, activityLog FROM {{%translations_orders}}')->queryAll();

foreach ($data as $row) {
$messages = json_decode($row['activityLog'], true);

foreach ($messages as $message) {
// Insert data into activity_log table
$this->insert(Constants::TABLE_ACTIVITY_LOG, [
'created' => \DateTime::createFromFormat('d/m/Y', $message['date'])->format('Y-m-d H:i:s'),
'targetId' => $row['id'],
'targetClass' => 'acclaro\\translations\\elements\\Order',
'message' => $message['message'],
'actions' => ''
]);
}
}

// Drop activityLog column
$this->dropColumn(Constants::TABLE_ORDERS, 'activityLog');

return true;
}

/**
* @inheritdoc
*/
public function safeDown(): bool
{
echo "m240117_054435_create_activity_log cannot be reverted.\n";
return false;
}
}
Loading

0 comments on commit ce1687b

Please sign in to comment.