Compare commits
2
Commits
4cdf11be3d
..
0.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
907a41e057 | ||
|
|
417ce35fc8 |
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
DOCKER_WEB_PORT=8080
|
DOCKER_APP_PORT=8080
|
||||||
DOCKER_CAPTCHA_PORT=8081
|
DOCKER_CAPTCHA_PORT=8081
|
||||||
DOCKER_CAPTCHA_WEBSOCKET_PORT=8082
|
DOCKER_CAPTCHA_WEBSOCKET_PORT=8082
|
||||||
DOCKER_DB_PORT=3306
|
DOCKER_DB_PORT=3306
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
**/storage/framework/sessions/*
|
**/storage/framework/sessions/*
|
||||||
**/storage/framework/views/*
|
**/storage/framework/views/*
|
||||||
**/storage/framework/testing/*
|
**/storage/framework/testing/*
|
||||||
**/storage/translation_service/*
|
|
||||||
**/storage/logs/*
|
**/storage/logs/*
|
||||||
**/vendor/
|
**/vendor/
|
||||||
**/node_modules/
|
**/node_modules/
|
||||||
|
|||||||
@@ -15,19 +15,6 @@ CAPTCHA_PUBLIC_TOKEN=
|
|||||||
FEEDBACK_MAIL_NOTIFICATIONS=false
|
FEEDBACK_MAIL_NOTIFICATIONS=false
|
||||||
FEEDBACK_MAIL_TO=
|
FEEDBACK_MAIL_TO=
|
||||||
|
|
||||||
TRANSLATION_SERVICE_ENABLE=false
|
|
||||||
# yandex or log
|
|
||||||
TRANSLATE_SERVICE=log
|
|
||||||
TRANSLATE_YANDEX_FOLDER_ID=
|
|
||||||
TRANSLATE_YANDEX_AUTHORIZED_KEY_PATH=/storage/translation_service/authorized_key.json
|
|
||||||
TRANSLATE_YANDEX_LIMIT_MAX_REQUEST=20
|
|
||||||
TRANSLATE_YANDEX_LIMIT_RATE_SECONDS=1
|
|
||||||
TRANSLATE_YANDEX_LIMIT_MAX_SYMBOLS=9000
|
|
||||||
|
|
||||||
TRANSLATE_LOG_LIMIT_MAX_REQUEST=20
|
|
||||||
TRANSLATE_LOG_LIMIT_RATE_SECONDS=1
|
|
||||||
TRANSLATE_LOG_LIMIT_MAX_SYMBOLS=9000
|
|
||||||
|
|
||||||
APP_FORCE_HTTPS=false
|
APP_FORCE_HTTPS=false
|
||||||
|
|
||||||
APP_DEFAULT_LOCALE=ru
|
APP_DEFAULT_LOCALE=ru
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ final readonly class StoreUpdate extends Dto
|
|||||||
private string $title,
|
private string $title,
|
||||||
private string $description,
|
private string $description,
|
||||||
private Storages $storages,
|
private Storages $storages,
|
||||||
private bool $isTranslateAutomatically = false,
|
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public function getTitle(): string
|
public function getTitle(): string
|
||||||
@@ -28,9 +27,4 @@ final readonly class StoreUpdate extends Dto
|
|||||||
{
|
{
|
||||||
return $this->storages;
|
return $this->storages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isTranslateAutomatically(): bool
|
|
||||||
{
|
|
||||||
return $this->isTranslateAutomatically;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ final readonly class Content
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private int $languageId,
|
private int $languageId,
|
||||||
private string $title,
|
private string $title,
|
||||||
private bool $isTranslateAutomatically = false,
|
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public function getLanguageId(): int
|
public function getLanguageId(): int
|
||||||
@@ -19,9 +18,4 @@ final readonly class Content
|
|||||||
{
|
{
|
||||||
return $this->title;
|
return $this->title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isTranslateAutomatically(): bool
|
|
||||||
{
|
|
||||||
return $this->isTranslateAutomatically;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ final readonly class Content
|
|||||||
private string $title,
|
private string $title,
|
||||||
private string $content,
|
private string $content,
|
||||||
private Storages $storages,
|
private Storages $storages,
|
||||||
private bool $isTranslateAutomatically = false,
|
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public function getLanguageId(): int
|
public function getLanguageId(): int
|
||||||
@@ -33,9 +32,4 @@ final readonly class Content
|
|||||||
{
|
{
|
||||||
return $this->storages;
|
return $this->storages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isTranslateAutomatically(): bool
|
|
||||||
{
|
|
||||||
return $this->isTranslateAutomatically;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Dto\Service\Admin\Project\ServiceTranslate;
|
|
||||||
|
|
||||||
use App\Dto\Service\Dto;
|
|
||||||
|
|
||||||
final readonly class Translation extends Dto
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private int $languageId,
|
|
||||||
private ?int $sourceLanguageId,
|
|
||||||
private ?string $code,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function getLanguageId(): int
|
|
||||||
{
|
|
||||||
return $this->languageId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSourceLanguageId(): ?int
|
|
||||||
{
|
|
||||||
return $this->sourceLanguageId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCode(): ?string
|
|
||||||
{
|
|
||||||
return $this->code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Dto\Service\Admin\Project\ServiceTranslate;
|
|
||||||
|
|
||||||
final class Translations
|
|
||||||
{
|
|
||||||
private array $translations;
|
|
||||||
|
|
||||||
public function add(Translation $translation): void
|
|
||||||
{
|
|
||||||
$this->translations[] = $translation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTranslations(): array
|
|
||||||
{
|
|
||||||
return $this->translations;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Dto\Service\Admin\Project\ServiceTranslate;
|
|
||||||
|
|
||||||
use App\Dto\Service\Dto;
|
|
||||||
|
|
||||||
final readonly class Update extends Dto
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private Translations $translations,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function getTranslations(): Translations
|
|
||||||
{
|
|
||||||
return $this->translations;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -44,7 +44,6 @@ final class Translations
|
|||||||
'site.Choose version',
|
'site.Choose version',
|
||||||
'site.alert-status-not-supported',
|
'site.alert-status-not-supported',
|
||||||
'site.alert-status-future',
|
'site.alert-status-future',
|
||||||
'Home',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach (DocumentationVersionStatus::cases() as $status) {
|
foreach (DocumentationVersionStatus::cases() as $status) {
|
||||||
|
|||||||
@@ -8,16 +8,10 @@ final readonly class Update extends Dto
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private Translations $translations,
|
private Translations $translations,
|
||||||
private bool $isTranslateAutomatically = false,
|
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public function getTranslations(): Translations
|
public function getTranslations(): Translations
|
||||||
{
|
{
|
||||||
return $this->translations;
|
return $this->translations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isTranslateAutomatically(): bool
|
|
||||||
{
|
|
||||||
return $this->isTranslateAutomatically;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Dto\Service\ProjectTranslationServiceHash;
|
|
||||||
|
|
||||||
final class Fields
|
|
||||||
{
|
|
||||||
private array $fields = [];
|
|
||||||
|
|
||||||
public function add(string $name, string $value): self
|
|
||||||
{
|
|
||||||
$this->fields[$name] = $value;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFields(): array
|
|
||||||
{
|
|
||||||
return $this->fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNames(): array
|
|
||||||
{
|
|
||||||
return \array_keys($this->fields);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Dto\Service\ProjectTranslationServiceHash;
|
|
||||||
|
|
||||||
final class HashStatusWaiting
|
|
||||||
{
|
|
||||||
private array $hash = [];
|
|
||||||
|
|
||||||
public function add(string $fieldName, bool $isWaiting): void
|
|
||||||
{
|
|
||||||
$this->hash[$fieldName] = $isWaiting;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isStatusWaiting(string $fieldName): bool
|
|
||||||
{
|
|
||||||
return $this->hash[$fieldName] ?? false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Dto\Service\ProjectTranslationServiceHash;
|
|
||||||
|
|
||||||
final class Hashes
|
|
||||||
{
|
|
||||||
private array $hashes = [];
|
|
||||||
private array $ids = [];
|
|
||||||
|
|
||||||
public function add(int $hashId, string $fieldName, string $hash): void
|
|
||||||
{
|
|
||||||
$this->hashes[$hashId] = [
|
|
||||||
'field' => $fieldName,
|
|
||||||
'hash' => $hash,
|
|
||||||
];
|
|
||||||
$this->ids[] = $hashId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHash(int $hashId): ?array
|
|
||||||
{
|
|
||||||
return $this->hashes[$hashId] ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIds(): array
|
|
||||||
{
|
|
||||||
return $this->ids;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Dto\Service\ProjectTranslationServiceHash;
|
|
||||||
|
|
||||||
final class TranslateFields
|
|
||||||
{
|
|
||||||
private array $fields = [];
|
|
||||||
private array $hashes = [];
|
|
||||||
|
|
||||||
public function add(int $languageId, string $fieldName, string $hash, int $hashId): self
|
|
||||||
{
|
|
||||||
if (!isset($this->fields[$languageId])) {
|
|
||||||
$this->fields[$languageId] = [];
|
|
||||||
}
|
|
||||||
$this->fields[$languageId][] = $fieldName;
|
|
||||||
|
|
||||||
if (!isset($this->hashes[$languageId])) {
|
|
||||||
$this->hashes[$languageId] = [];
|
|
||||||
}
|
|
||||||
$this->hashes[$languageId][$fieldName] = [
|
|
||||||
'hash' => $hash,
|
|
||||||
'hashId' => $hashId,
|
|
||||||
];
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFields(): array
|
|
||||||
{
|
|
||||||
return $this->fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHashesByLanguage(int $languageId): array
|
|
||||||
{
|
|
||||||
return $this->hashes[$languageId] ?? [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Dto\Service\ProjectTranslationServiceTextHash;
|
|
||||||
|
|
||||||
final class Codes
|
|
||||||
{
|
|
||||||
private array $codes = [];
|
|
||||||
|
|
||||||
public function add(string $code, string $value): self
|
|
||||||
{
|
|
||||||
$this->codes[$code] = $value;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCodes(): array
|
|
||||||
{
|
|
||||||
return $this->codes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCodeNames(): array
|
|
||||||
{
|
|
||||||
return \array_keys($this->codes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Dto\Service\ProjectTranslationServiceTextHash;
|
|
||||||
|
|
||||||
final class HashStatusWaiting
|
|
||||||
{
|
|
||||||
private array $hash = [];
|
|
||||||
|
|
||||||
public function add(string $code, bool $isWaiting): void
|
|
||||||
{
|
|
||||||
$this->hash[$code] = $isWaiting;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isStatusWaiting(string $code): bool
|
|
||||||
{
|
|
||||||
return $this->hash[$code] ?? false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Dto\Service\ProjectTranslationServiceTextHash;
|
|
||||||
|
|
||||||
final class Hashes
|
|
||||||
{
|
|
||||||
private array $hashes = [];
|
|
||||||
private array $ids = [];
|
|
||||||
|
|
||||||
public function add(int $hashId, string $code, string $hash): void
|
|
||||||
{
|
|
||||||
$this->hashes[$hashId] = [
|
|
||||||
'code' => $code,
|
|
||||||
'hash' => $hash,
|
|
||||||
];
|
|
||||||
$this->ids[] = $hashId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHash(int $hashId): ?array
|
|
||||||
{
|
|
||||||
return $this->hashes[$hashId] ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIds(): array
|
|
||||||
{
|
|
||||||
return $this->ids;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Dto\Service\ProjectTranslationServiceTextHash;
|
|
||||||
|
|
||||||
final class TranslateCodes
|
|
||||||
{
|
|
||||||
private array $codes = [];
|
|
||||||
private array $hashes = [];
|
|
||||||
|
|
||||||
public function add(int $languageId, string $code, string $hash, int $hashId): self
|
|
||||||
{
|
|
||||||
if (!isset($this->codes[$languageId])) {
|
|
||||||
$this->codes[$languageId] = [];
|
|
||||||
}
|
|
||||||
$this->codes[$languageId][] = $code;
|
|
||||||
|
|
||||||
if (!isset($this->hashes[$languageId])) {
|
|
||||||
$this->hashes[$languageId] = [];
|
|
||||||
}
|
|
||||||
$this->hashes[$languageId][$code] = [
|
|
||||||
'hash' => $hash,
|
|
||||||
'hashId' => $hashId,
|
|
||||||
];
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCodes(): array
|
|
||||||
{
|
|
||||||
return $this->codes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHashesByLanguage(int $languageId): array
|
|
||||||
{
|
|
||||||
return $this->hashes[$languageId] ?? [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use Illuminate\Cache\TaggedCache;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
enum CacheTag: string
|
||||||
|
{
|
||||||
|
case Project = 'project';
|
||||||
|
case ProjectTranslation = 'project_translation';
|
||||||
|
case DocumantationVersion = 'documantation_version';
|
||||||
|
|
||||||
|
public function getCache(): TaggedCache
|
||||||
|
{
|
||||||
|
return Cache::tags($this->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Enums;
|
namespace App\Enums;
|
||||||
|
|
||||||
use App\Models\DocumentationCategoryContent;
|
|
||||||
use App\Models\DocumentationContent;
|
use App\Models\DocumentationContent;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\ProjectContent;
|
use App\Models\ProjectContent;
|
||||||
@@ -12,7 +11,6 @@ enum Morph: int
|
|||||||
case Project = 1;
|
case Project = 1;
|
||||||
case DocumentationContent = 2;
|
case DocumentationContent = 2;
|
||||||
case ProjectContent = 3;
|
case ProjectContent = 3;
|
||||||
case DocumentationCategoryContent = 4;
|
|
||||||
|
|
||||||
public function getPathModel(): string
|
public function getPathModel(): string
|
||||||
{
|
{
|
||||||
@@ -20,7 +18,6 @@ enum Morph: int
|
|||||||
self::Project => Project::class,
|
self::Project => Project::class,
|
||||||
self::DocumentationContent => DocumentationContent::class,
|
self::DocumentationContent => DocumentationContent::class,
|
||||||
self::ProjectContent => ProjectContent::class,
|
self::ProjectContent => ProjectContent::class,
|
||||||
self::DocumentationCategoryContent => DocumentationCategoryContent::class,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,6 @@ enum Permission: string
|
|||||||
self::AdminPanel => [
|
self::AdminPanel => [
|
||||||
'view' => __('permissions.Administrative panel allowed'),
|
'view' => __('permissions.Administrative panel allowed'),
|
||||||
],
|
],
|
||||||
self::Project => array_merge($this->getBasePermissions(), [
|
|
||||||
'Setting up automatic translation' => __('permissions.Setting up automatic translation'),
|
|
||||||
]),
|
|
||||||
self::ProjectContent => [
|
self::ProjectContent => [
|
||||||
'view' => __('permissions.Allowed to watch'),
|
'view' => __('permissions.Allowed to watch'),
|
||||||
'create' => __('permissions.Allowed to create'),
|
'create' => __('permissions.Allowed to create'),
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Enums\ProjectTranslationServiceHashes;
|
|
||||||
|
|
||||||
enum Status: int
|
|
||||||
{
|
|
||||||
case Waiting = 0;
|
|
||||||
case Success = 10;
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Exceptions\Services\Translate;
|
|
||||||
|
|
||||||
final class CompletedException extends \Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,12 +3,8 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller as BaseController;
|
use App\Http\Controllers\Controller as BaseController;
|
||||||
use Illuminate\Support\Facades\Config;
|
|
||||||
|
|
||||||
abstract class Controller extends BaseController
|
abstract class Controller extends BaseController
|
||||||
{
|
{
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
Config::set('breadcrumbs.view', 'breadcrumbs.admin');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ final class LanguagesController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly LanguageService $languageService,
|
private readonly LanguageService $languageService,
|
||||||
) {
|
) { }
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function newLanguage(NewLanguageRequest $request): JsonResponse
|
public function newLanguage(NewLanguageRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ final class AboutController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly AboutService $aboutService,
|
private readonly AboutService $aboutService,
|
||||||
) {
|
) { }
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function languages(int $project, Request $request): View
|
public function languages(int $project, Request $request): View
|
||||||
{
|
{
|
||||||
|
|||||||
+6
-14
@@ -4,7 +4,6 @@ namespace App\Http\Controllers\Admin\Projects;
|
|||||||
|
|
||||||
use App\Dto\QuerySettingsDto;
|
use App\Dto\QuerySettingsDto;
|
||||||
use App\Http\Controllers\Admin\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests\Admin\Projects\DocumentationCategories\CreateRequest;
|
|
||||||
use App\Http\Requests\Admin\Projects\DocumentationCategories\IndexRequest;
|
use App\Http\Requests\Admin\Projects\DocumentationCategories\IndexRequest;
|
||||||
use App\Http\Requests\Admin\Projects\DocumentationCategories\StoreUpdateRequest;
|
use App\Http\Requests\Admin\Projects\DocumentationCategories\StoreUpdateRequest;
|
||||||
use App\Services\Admin\Project\DocumentationCategoryService;
|
use App\Services\Admin\Project\DocumentationCategoryService;
|
||||||
@@ -16,9 +15,7 @@ final class DocumentationCategoriesController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly DocumentationCategoryService $documentationCategoryService,
|
private readonly DocumentationCategoryService $documentationCategoryService,
|
||||||
) {
|
) { }
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index(int $projectId, int $versionId, IndexRequest $request): View
|
public function index(int $projectId, int $versionId, IndexRequest $request): View
|
||||||
{
|
{
|
||||||
@@ -35,23 +32,18 @@ final class DocumentationCategoriesController extends Controller
|
|||||||
$this->errors($result);
|
$this->errors($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin/projects/documentation-versions/documentation-categories/index', $result->getData());
|
return view('admin/projects/documentation-categories/index', $result->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(int $projectId, int $versionId, CreateRequest $request): View
|
public function create(int $projectId, int $versionId, Request $request): View
|
||||||
{
|
{
|
||||||
$parentId = null;
|
|
||||||
if ($request->has('category')) {
|
|
||||||
$parentId = (int) $request->input('category');
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$result = $this->documentationCategoryService->create($projectId, $versionId, $user, $parentId);
|
$result = $this->documentationCategoryService->create($projectId, $versionId, $user);
|
||||||
if ($result->isError()) {
|
if ($result->isError()) {
|
||||||
$this->errors($result);
|
$this->errors($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin/projects/documentation-versions/documentation-categories/create', $result->getData());
|
return view('admin/projects/documentation-categories/create', $result->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit(int $projectId, int $versionId, int $id, Request $request): View
|
public function edit(int $projectId, int $versionId, int $id, Request $request): View
|
||||||
@@ -62,7 +54,7 @@ final class DocumentationCategoriesController extends Controller
|
|||||||
$this->errors($result);
|
$this->errors($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin/projects/documentation-versions/documentation-categories/edit', $result->getData());
|
return view('admin/projects/documentation-categories/edit', $result->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(int $projectId, int $versionId, StoreUpdateRequest $request): RedirectResponse
|
public function store(int $projectId, int $versionId, StoreUpdateRequest $request): RedirectResponse
|
||||||
|
|||||||
+3
-5
@@ -15,9 +15,7 @@ final class DocumentationVersionController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly DocumentationVersionService $documentationVersionService,
|
private readonly DocumentationVersionService $documentationVersionService,
|
||||||
) {
|
) { }
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index(int $projectId, IndexRequest $request): View
|
public function index(int $projectId, IndexRequest $request): View
|
||||||
{
|
{
|
||||||
@@ -37,10 +35,10 @@ final class DocumentationVersionController extends Controller
|
|||||||
return view('admin/projects/documentation-versions/index', $result->getData());
|
return view('admin/projects/documentation-versions/index', $result->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show(int $projectId, int $id, Request $request, ?int $category = null): View
|
public function show(int $projectId, int $id, Request $request): View
|
||||||
{
|
{
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$result = $this->documentationVersionService->show($projectId, $id, $category, $user);
|
$result = $this->documentationVersionService->show($projectId, $id, $user);
|
||||||
if ($result->isError()) {
|
if ($result->isError()) {
|
||||||
$this->errors($result);
|
$this->errors($result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ namespace App\Http\Controllers\Admin\Projects;
|
|||||||
|
|
||||||
use App\Dto\QuerySettingsDto;
|
use App\Dto\QuerySettingsDto;
|
||||||
use App\Http\Controllers\Admin\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
use App\Http\Requests\Admin\Projects\Documentations\CreateRequest;
|
|
||||||
use App\Http\Requests\Admin\Projects\Documentations\IndexRequest;
|
use App\Http\Requests\Admin\Projects\Documentations\IndexRequest;
|
||||||
use App\Http\Requests\Admin\Projects\Documentations\StoreUpdateRequest;
|
use App\Http\Requests\Admin\Projects\Documentations\StoreUpdateRequest;
|
||||||
use App\Services\Admin\Project\DocumentationService;
|
use App\Services\Admin\Project\DocumentationService;
|
||||||
@@ -16,9 +15,7 @@ final class DocumentationsController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly DocumentationService $documentationService,
|
private readonly DocumentationService $documentationService,
|
||||||
) {
|
) { }
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index(int $projectId, int $versionId, IndexRequest $request): View
|
public function index(int $projectId, int $versionId, IndexRequest $request): View
|
||||||
{
|
{
|
||||||
@@ -35,23 +32,18 @@ final class DocumentationsController extends Controller
|
|||||||
$this->errors($result);
|
$this->errors($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin/projects/documentation-versions/documentations/index', $result->getData());
|
return view('admin/projects/documentations/index', $result->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(int $projectId, int $versionId, CreateRequest $request): View
|
public function create(int $projectId, int $versionId, Request $request): View
|
||||||
{
|
{
|
||||||
$categoryId = null;
|
|
||||||
if ($request->has('category')) {
|
|
||||||
$categoryId = (int) $request->input('category');
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$result = $this->documentationService->create($projectId, $versionId, $user, $categoryId);
|
$result = $this->documentationService->create($projectId, $versionId, $user);
|
||||||
if ($result->isError()) {
|
if ($result->isError()) {
|
||||||
$this->errors($result);
|
$this->errors($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin/projects/documentation-versions/documentations/create', $result->getData());
|
return view('admin/projects/documentations/create', $result->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit(int $projectId, int $versionId, int $id, Request $request): View
|
public function edit(int $projectId, int $versionId, int $id, Request $request): View
|
||||||
@@ -62,7 +54,7 @@ final class DocumentationsController extends Controller
|
|||||||
$this->errors($result);
|
$this->errors($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin/projects/documentation-versions/documentations/edit', $result->getData());
|
return view('admin/projects/documentations/edit', $result->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(int $projectId, int $versionId, StoreUpdateRequest $request): RedirectResponse
|
public function store(int $projectId, int $versionId, StoreUpdateRequest $request): RedirectResponse
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ final class FeedbacksController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly FeedbackService $feedbackService,
|
private readonly FeedbackService $feedbackService,
|
||||||
) {
|
) { }
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index(IndexRequest $request): View
|
public function index(IndexRequest $request): View
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ final class LinksController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly LinkService $linkService
|
private readonly LinkService $linkService
|
||||||
) {
|
) { }
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index(int $projectId, IndexRequest $request): View
|
public function index(int $projectId, IndexRequest $request): View
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin\Projects;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Admin\Controller;
|
|
||||||
use App\Http\Requests\Admin\Projects\ServiceTranslate\UpdateRequest;
|
|
||||||
use App\Services\Admin\Project\ServiceTranslateService;
|
|
||||||
use Illuminate\Http\RedirectResponse;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\View\View;
|
|
||||||
|
|
||||||
final class ServiceTranslateController extends Controller
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly ServiceTranslateService $serviceTranslateService,
|
|
||||||
) {
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function view(int $projectId, Request $request): View
|
|
||||||
{
|
|
||||||
$user = $request->user();
|
|
||||||
$result = $this->serviceTranslateService->view($projectId, $user);
|
|
||||||
if ($result->isError()) {
|
|
||||||
$this->errors($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('admin.projects.service-translate.view', $result->getData());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(int $projectId, UpdateRequest $request): RedirectResponse
|
|
||||||
{
|
|
||||||
$data = $request->getDto();
|
|
||||||
$user = $request->user();
|
|
||||||
$result = $this->serviceTranslateService->update($projectId, $data, $user);
|
|
||||||
|
|
||||||
if ($result->isError()) {
|
|
||||||
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect()->route('admin.projects.service-translate.view', ['project' => $projectId])->withSuccess($result->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Admin\Projects;
|
namespace App\Http\Controllers\Admin\Projects;
|
||||||
|
|
||||||
use App\Http\Controllers\Admin\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Admin\Projects\Translations\UpdateRequest;
|
use App\Http\Requests\Admin\Projects\Translations\UpdateRequest;
|
||||||
use App\Services\Admin\Project\TranslationService;
|
use App\Services\Admin\Project\TranslationService;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
@@ -13,9 +13,7 @@ final class TranslationsController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly TranslationService $translationService,
|
private readonly TranslationService $translationService,
|
||||||
) {
|
) { }
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function languages(int $projectId, Request $request): View
|
public function languages(int $projectId, Request $request): View
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ final class ProjectsController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly ProjectService $projectService
|
private readonly ProjectService $projectService
|
||||||
) {
|
) { }
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index(IndexRequest $request): View
|
public function index(IndexRequest $request): View
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ final class RolesController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly RoleService $roleService
|
private readonly RoleService $roleService
|
||||||
) {
|
) { }
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
public function index(IndexRequest $request): View
|
public function index(IndexRequest $request): View
|
||||||
{
|
{
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ final class UsersController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly UserService $userService
|
private readonly UserService $userService
|
||||||
) {
|
) { }
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index(IndexRequest $request): View
|
public function index(IndexRequest $request): View
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ final class DocumentationController extends Controller
|
|||||||
|
|
||||||
public function defaultVersion(Request $request): RedirectResponse | View
|
public function defaultVersion(Request $request): RedirectResponse | View
|
||||||
{
|
{
|
||||||
$project = $request->attributes->get('project');
|
$project = $request->get('project');
|
||||||
$websiteTranslations = $request->attributes->get('websiteTranslations');
|
$websiteTranslations = $request->get('websiteTranslations');
|
||||||
|
|
||||||
$result = $this->documentationService->defaultVersion($project, $request->user());
|
$result = $this->documentationService->defaultVersion($project, $request->user());
|
||||||
if ($result->isError()) {
|
if ($result->isError()) {
|
||||||
@@ -40,9 +40,9 @@ final class DocumentationController extends Controller
|
|||||||
public function index(Request $request): View
|
public function index(Request $request): View
|
||||||
{
|
{
|
||||||
$documentation = new Documentation(
|
$documentation = new Documentation(
|
||||||
project: $request->attributes->get('project'),
|
project: $request->get('project'),
|
||||||
version: $request->attributes->get('version'),
|
version: $request->get('version'),
|
||||||
websiteTranslations: $request->attributes->get('websiteTranslations'),
|
websiteTranslations: $request->get('websiteTranslations'),
|
||||||
user: $request->user(),
|
user: $request->user(),
|
||||||
);
|
);
|
||||||
$result = $this->documentationService->index($documentation);
|
$result = $this->documentationService->index($documentation);
|
||||||
@@ -57,9 +57,9 @@ final class DocumentationController extends Controller
|
|||||||
public function category(string $slug, Request $request): View
|
public function category(string $slug, Request $request): View
|
||||||
{
|
{
|
||||||
$documentation = new Documentation(
|
$documentation = new Documentation(
|
||||||
project: $request->attributes->get('project'),
|
project: $request->get('project'),
|
||||||
version: $request->attributes->get('version'),
|
version: $request->get('version'),
|
||||||
websiteTranslations: $request->attributes->get('websiteTranslations'),
|
websiteTranslations: $request->get('websiteTranslations'),
|
||||||
user: $request->user(),
|
user: $request->user(),
|
||||||
);
|
);
|
||||||
$result = $this->documentationService->category($slug, $documentation);
|
$result = $this->documentationService->category($slug, $documentation);
|
||||||
@@ -77,9 +77,9 @@ final class DocumentationController extends Controller
|
|||||||
public function view(string $slug, Request $request): View
|
public function view(string $slug, Request $request): View
|
||||||
{
|
{
|
||||||
$documentation = new Documentation(
|
$documentation = new Documentation(
|
||||||
project: $request->attributes->get('project'),
|
project: $request->get('project'),
|
||||||
version: $request->attributes->get('version'),
|
version: $request->get('version'),
|
||||||
websiteTranslations: $request->attributes->get('websiteTranslations'),
|
websiteTranslations: $request->get('websiteTranslations'),
|
||||||
user: $request->user(),
|
user: $request->user(),
|
||||||
);
|
);
|
||||||
$result = $this->documentationService->view($slug, $documentation);
|
$result = $this->documentationService->view($slug, $documentation);
|
||||||
|
|||||||
@@ -17,16 +17,16 @@ final class FeedbackController extends Controller
|
|||||||
public function index(Request $request): View
|
public function index(Request $request): View
|
||||||
{
|
{
|
||||||
return view('site.feedback.index', [
|
return view('site.feedback.index', [
|
||||||
'project' => $request->attributes->get('project'),
|
'project' => $request->get('project'),
|
||||||
'websiteTranslations' => $request->attributes->get('websiteTranslations'),
|
'websiteTranslations' => $request->get('websiteTranslations'),
|
||||||
'captcha' => config('app.captcha', false),
|
'captcha' => config('app.captcha', false),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function send(SendRequest $request): RedirectResponse
|
public function send(SendRequest $request): RedirectResponse
|
||||||
{
|
{
|
||||||
$project = $request->attributes->get('project');
|
$project = $request->get('project');
|
||||||
$websiteTranslations = $request->attributes->get('websiteTranslations');
|
$websiteTranslations = $request->get('websiteTranslations');
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$data = $request->getDto();
|
$data = $request->getDto();
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ final class ProjectsController extends Controller
|
|||||||
public function index(Request $request): View
|
public function index(Request $request): View
|
||||||
{
|
{
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$project = $request->attributes->get('project');
|
$project = $request->get('project');
|
||||||
|
|
||||||
if (\is_null($project)) {
|
if (\is_null($project)) {
|
||||||
$with = ['storage'];
|
$with = ['storage'];
|
||||||
@@ -27,7 +27,7 @@ final class ProjectsController extends Controller
|
|||||||
return \view('site.projects.index', $result->getData());
|
return \view('site.projects.index', $result->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
$websiteTranslations = $request->attributes->get('websiteTranslations');
|
$websiteTranslations = $request->get('websiteTranslations');
|
||||||
$result = $this->projectService->getAboutByProject($project, $websiteTranslations, $user);
|
$result = $this->projectService->getAboutByProject($project, $websiteTranslations, $user);
|
||||||
if ($result->isError()) {
|
if ($result->isError()) {
|
||||||
$this->errors($result);
|
$this->errors($result);
|
||||||
|
|||||||
@@ -2,22 +2,22 @@
|
|||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Enums\CacheTag;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
final readonly class DocumentationVersion
|
final readonly class DocumentationVersion
|
||||||
{
|
{
|
||||||
public function handle(Request $request, \Closure $next): Response
|
public function handle(Request $request, \Closure $next): Response
|
||||||
{
|
{
|
||||||
$project = $request->attributes->get('project');
|
$project = $request->get('project');
|
||||||
$versionSlug = $request->route()?->parameter('version');
|
$versionSlug = $request->route()?->parameter('version');
|
||||||
if ($versionSlug === null || $project === null) {
|
if ($versionSlug === null || $project === null) {
|
||||||
\abort(Response::HTTP_NOT_FOUND);
|
\abort(Response::HTTP_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
$seconds = 3600;
|
$seconds = 3600;
|
||||||
$version = Cache::remember(self::class . $project->id . '-' . $versionSlug, $seconds, function () use ($project, $versionSlug) {
|
$version = CacheTag::DocumantationVersion->getCache()->remember(self::class . $project->id . '-' . $versionSlug, $seconds, function () use ($project, $versionSlug) {
|
||||||
return $project->documentationVersions()->where('slug', $versionSlug)->first() ?? false;
|
return $project->documentationVersions()->where('slug', $versionSlug)->first() ?? false;
|
||||||
});
|
});
|
||||||
if ($version === false) {
|
if ($version === false) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ final class IsProject
|
|||||||
{
|
{
|
||||||
public function handle(Request $request, \Closure $next): Response
|
public function handle(Request $request, \Closure $next): Response
|
||||||
{
|
{
|
||||||
$project = $request->attributes->get('project');
|
$project = $request->get('project');
|
||||||
if (\is_null($project)) {
|
if (\is_null($project)) {
|
||||||
\abort(Response::HTTP_NOT_FOUND);
|
\abort(Response::HTTP_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ final class IsWebsiteTranslations
|
|||||||
{
|
{
|
||||||
public function handle(Request $request, \Closure $next): Response
|
public function handle(Request $request, \Closure $next): Response
|
||||||
{
|
{
|
||||||
$websiteTranslations = $request->attributes->get('websiteTranslations');
|
$websiteTranslations = $request->get('websiteTranslations');
|
||||||
if (\is_null($websiteTranslations)) {
|
if (\is_null($websiteTranslations)) {
|
||||||
\abort(Response::HTTP_NOT_FOUND);
|
\abort(Response::HTTP_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Enums\CacheTag;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ final class ProjectAndLanguage extends ProjectLanguage
|
|||||||
}
|
}
|
||||||
|
|
||||||
$seconds = 3600;
|
$seconds = 3600;
|
||||||
$project = Cache::remember(self::class . $projectCode, $seconds, function () use ($projectCode) {
|
$project = CacheTag::Project->getCache()->remember(self::class . $projectCode, $seconds, function () use ($projectCode) {
|
||||||
return $this->projectRepository->getProjectByCode($projectCode) ?? false;
|
return $this->projectRepository->getProjectByCode($projectCode) ?? false;
|
||||||
});
|
});
|
||||||
if ($project === false) {
|
if ($project === false) {
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Enums\CacheTag;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ final class ProjectDomainAndLanguage extends ProjectLanguage
|
|||||||
}
|
}
|
||||||
|
|
||||||
$seconds = 3600;
|
$seconds = 3600;
|
||||||
$project = Cache::remember(self::class . $httpHost, $seconds, function () use ($httpHost) {
|
$project = CacheTag::Project->getCache()->remember(self::class . $httpHost, $seconds, function () use ($httpHost) {
|
||||||
return $this->projectRepository->getProjectByHttpHost($httpHost) ?? false;
|
return $this->projectRepository->getProjectByHttpHost($httpHost) ?? false;
|
||||||
});
|
});
|
||||||
if ($project === false) {
|
if ($project === false) {
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Enums\CacheTag;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Repositories\ProjectLanguageRepository;
|
use App\Repositories\ProjectLanguageRepository;
|
||||||
use App\Repositories\ProjectRepository;
|
use App\Repositories\ProjectRepository;
|
||||||
use App\Repositories\ProjectTranslationRepository;
|
use App\Repositories\ProjectTranslationRepository;
|
||||||
use App\Services\WebsiteTranslations;
|
use App\Services\WebsiteTranslations;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
|
|
||||||
abstract class ProjectLanguage
|
abstract class ProjectLanguage
|
||||||
{
|
{
|
||||||
@@ -21,7 +21,7 @@ abstract class ProjectLanguage
|
|||||||
protected function getWebsiteTranslations(Project $project, ?string $languageCode): ?WebsiteTranslations
|
protected function getWebsiteTranslations(Project $project, ?string $languageCode): ?WebsiteTranslations
|
||||||
{
|
{
|
||||||
$seconds = 3600 * 3;
|
$seconds = 3600 * 3;
|
||||||
$language = Cache::remember(self::class . $project->id . '-' . $languageCode, $seconds, function () use ($project, $languageCode) {
|
$language = CacheTag::Project->getCache()->remember(self::class . $project->id . '-' . $languageCode, $seconds, function () use ($project, $languageCode) {
|
||||||
return $this->projectLanguageRepository->getProjectLanguageByCodeOrDefault($project, $languageCode) ?? false;
|
return $this->projectLanguageRepository->getProjectLanguageByCodeOrDefault($project, $languageCode) ?? false;
|
||||||
});
|
});
|
||||||
if ($language === false) {
|
if ($language === false) {
|
||||||
@@ -34,7 +34,7 @@ abstract class ProjectLanguage
|
|||||||
}
|
}
|
||||||
|
|
||||||
$seconds = 3600 * 24;
|
$seconds = 3600 * 24;
|
||||||
$translations = Cache::remember(self::class . '-translations-' . $project->id . '-' . $language->id, $seconds, function () use ($project, $language) {
|
$translations = CacheTag::ProjectTranslation->getCache()->remember(self::class . '-translations-' . $project->id . '-' . $language->id, $seconds, function () use ($project, $language) {
|
||||||
return $this->projectTranslationRepository->getProjectTranslations($project->id, $language->id)->all()->pluck('text', 'code')->toArray();
|
return $this->projectTranslationRepository->getProjectTranslations($project->id, $language->id)->all()->pluck('text', 'code')->toArray();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ final class StoreUpdateRequest extends FormRequest implements FormRequestDto
|
|||||||
'title' => ['required', 'string', 'max:255',],
|
'title' => ['required', 'string', 'max:255',],
|
||||||
'description' => ['nullable', 'string',],
|
'description' => ['nullable', 'string',],
|
||||||
'storage.content_images.*.file' => ['numeric', 'min:1'],
|
'storage.content_images.*.file' => ['numeric', 'min:1'],
|
||||||
'translate-automatically' => ['nullable', 'boolean'],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,9 +33,8 @@ final class StoreUpdateRequest extends FormRequest implements FormRequestDto
|
|||||||
{
|
{
|
||||||
return new StoreUpdate(
|
return new StoreUpdate(
|
||||||
title: $this->input('title'),
|
title: $this->input('title'),
|
||||||
description: (string) $this->input('description', ''),
|
description: $this->input('description'),
|
||||||
storages: $this->storages(),
|
storages: $this->storages(),
|
||||||
isTranslateAutomatically: (bool) $this->input('translate-automatically', false),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Http\Requests\Admin\Projects\DocumentationCategories;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
final class CreateRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*/
|
|
||||||
public function rules(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'category' => ['nullable', 'integer', 'min:1'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-2
@@ -21,7 +21,6 @@ final class StoreUpdateRequest extends FormRequest implements FormRequestDto
|
|||||||
'sort' => ['required', 'integer', 'min:-1000', 'max:1000'],
|
'sort' => ['required', 'integer', 'min:-1000', 'max:1000'],
|
||||||
'parent_id' => ['nullable', 'integer', 'exists:documentation_categories,id'],
|
'parent_id' => ['nullable', 'integer', 'exists:documentation_categories,id'],
|
||||||
'content.*.title' => ['required', 'string', 'max:255'],
|
'content.*.title' => ['required', 'string', 'max:255'],
|
||||||
'translate-automatically.*' => ['nullable', 'boolean'],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +47,6 @@ final class StoreUpdateRequest extends FormRequest implements FormRequestDto
|
|||||||
$contents->addContent(new Content(
|
$contents->addContent(new Content(
|
||||||
languageId: (int) $languageId,
|
languageId: (int) $languageId,
|
||||||
title: $content['title'],
|
title: $content['title'],
|
||||||
isTranslateAutomatically: (bool) $this->input('translate-automatically.' . $languageId, false),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return $contents;
|
return $contents;
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Http\Requests\Admin\Projects\Documentations;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
final class CreateRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*/
|
|
||||||
public function rules(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'category' => ['nullable', 'integer', 'min:1'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -32,7 +32,6 @@ final class StoreUpdateRequest extends FormRequest implements FormRequestDto
|
|||||||
'content.*.title' => ['required', 'string', 'max:255'],
|
'content.*.title' => ['required', 'string', 'max:255'],
|
||||||
'content.*.content' => ['nullable', 'string'],
|
'content.*.content' => ['nullable', 'string'],
|
||||||
'content.*.content_images.*.file' => ['numeric', 'min:1'],
|
'content.*.content_images.*.file' => ['numeric', 'min:1'],
|
||||||
'translate-automatically.*' => ['nullable', 'boolean'],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +60,6 @@ final class StoreUpdateRequest extends FormRequest implements FormRequestDto
|
|||||||
title: $content['title'],
|
title: $content['title'],
|
||||||
content: $content['content'] ?? '',
|
content: $content['content'] ?? '',
|
||||||
storages: $this->contentStorages($content),
|
storages: $this->contentStorages($content),
|
||||||
isTranslateAutomatically: (bool) $this->input('translate-automatically.' . $languageId, false),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return $contents;
|
return $contents;
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Http\Requests\Admin\Projects\ServiceTranslate;
|
|
||||||
|
|
||||||
use App\Contracts\FormRequestDto;
|
|
||||||
use App\Dto\Service\Admin\Project\ServiceTranslate\Translation;
|
|
||||||
use App\Dto\Service\Admin\Project\ServiceTranslate\Translations;
|
|
||||||
use App\Dto\Service\Admin\Project\ServiceTranslate\Update;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
final class UpdateRequest extends FormRequest implements FormRequestDto
|
|
||||||
{
|
|
||||||
public function attributes(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'language.*.id' => __('validation.attributes.language_id'),
|
|
||||||
'language.*.code' => __('validation.attributes.code'),
|
|
||||||
'language.*.source_language_id' => __('validation.attributes.source_language_id'),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*/
|
|
||||||
public function rules(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'language.*.id' => ['required', 'numeric', 'min:1'],
|
|
||||||
'language.*.code' => ['nullable', 'string', 'min:2', 'max:50', 'required_with:language.*.source_language_id'],
|
|
||||||
'language.*.source_language_id' => ['nullable', 'numeric', 'min:1', 'different:language.*.id'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getDto(): Update
|
|
||||||
{
|
|
||||||
$translations = new Translations();
|
|
||||||
foreach ($this->input('language', []) as $language) {
|
|
||||||
$sourceLanguageId = $language['source_language_id'] ?? null;
|
|
||||||
if ($sourceLanguageId) {
|
|
||||||
$sourceLanguageId = (int) $sourceLanguageId;
|
|
||||||
}
|
|
||||||
|
|
||||||
$translation = new Translation(
|
|
||||||
languageId: (int) $language['id'],
|
|
||||||
sourceLanguageId: $sourceLanguageId,
|
|
||||||
code: $language['code'] ?? null,
|
|
||||||
);
|
|
||||||
$translations->add($translation);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Update(
|
|
||||||
translations: $translations,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,6 @@ final class UpdateRequest extends FormRequest implements FormRequestDto
|
|||||||
'translations' => ['nullable', 'array'],
|
'translations' => ['nullable', 'array'],
|
||||||
'translations.*.code' => ['required', 'string', new In(Translations::getTranslationCodes())],
|
'translations.*.code' => ['required', 'string', new In(Translations::getTranslationCodes())],
|
||||||
'translations.*.text' => ['nullable', 'string', 'max:1000'],
|
'translations.*.text' => ['nullable', 'string', 'max:1000'],
|
||||||
'translate-automatically' => ['nullable', 'boolean'],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,9 +33,6 @@ final class UpdateRequest extends FormRequest implements FormRequestDto
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Update(
|
return new Update($translations);
|
||||||
translations: $translations,
|
|
||||||
isTranslateAutomatically: (bool) $this->input('translate-automatically', false),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Jobs\Translate;
|
|
||||||
|
|
||||||
use App\Services\Translate\Project\ProjectContentService;
|
|
||||||
use Exception;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Foundation\Queue\Queueable;
|
|
||||||
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
||||||
|
|
||||||
final class ProcessProjectContent implements ShouldQueue, ShouldBeEncrypted
|
|
||||||
{
|
|
||||||
use Dispatchable, Queueable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the middleware the job should pass through.
|
|
||||||
*
|
|
||||||
* @return array<int, object>
|
|
||||||
*/
|
|
||||||
public function middleware(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
(new WithoutOverlapping($this->uniqueId()))->expireAfter(180),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
private readonly int $projectId,
|
|
||||||
private readonly array $contentIds = [],
|
|
||||||
private readonly array $exceptLanguages = [],
|
|
||||||
) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the unique ID for the job.
|
|
||||||
*/
|
|
||||||
public function uniqueId(): string
|
|
||||||
{
|
|
||||||
return 'project-' . $this->projectId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function handle(ProjectContentService $projectContentService): void
|
|
||||||
{
|
|
||||||
$result = $projectContentService->translate($this->projectId, $this->contentIds, $this->exceptLanguages);
|
|
||||||
if ($result->isError() && $result->getCode() !== 404) {
|
|
||||||
cache()->lock($this->uniqueId())->forceRelease();
|
|
||||||
throw new Exception($result->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Jobs\Translate;
|
|
||||||
|
|
||||||
use App\Services\Translate\Project\DocumentationCategoryContentService;
|
|
||||||
use Exception;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Foundation\Queue\Queueable;
|
|
||||||
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
||||||
|
|
||||||
final class ProcessProjectDocumentationCategoryContent implements ShouldQueue, ShouldBeEncrypted
|
|
||||||
{
|
|
||||||
use Dispatchable, Queueable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the middleware the job should pass through.
|
|
||||||
*
|
|
||||||
* @return array<int, object>
|
|
||||||
*/
|
|
||||||
public function middleware(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
(new WithoutOverlapping($this->uniqueId()))->expireAfter(180),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
private readonly int $projectDocumentCategoryId,
|
|
||||||
private readonly array $contentIds = [],
|
|
||||||
private readonly array $exceptLanguages = [],
|
|
||||||
) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the unique ID for the job.
|
|
||||||
*/
|
|
||||||
public function uniqueId(): string
|
|
||||||
{
|
|
||||||
return 'documentation-category-' . $this->projectDocumentCategoryId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function handle(DocumentationCategoryContentService $categoryContentService): void
|
|
||||||
{
|
|
||||||
$result = $categoryContentService->translate($this->projectDocumentCategoryId, $this->contentIds, $this->exceptLanguages);
|
|
||||||
if ($result->isError() && $result->getCode() !== 404) {
|
|
||||||
cache()->lock($this->uniqueId())->forceRelease();
|
|
||||||
throw new Exception($result->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Jobs\Translate;
|
|
||||||
|
|
||||||
use App\Services\Translate\Project\DocumentationContentService;
|
|
||||||
use Exception;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Foundation\Queue\Queueable;
|
|
||||||
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
||||||
|
|
||||||
final class ProcessProjectDocumentationContent implements ShouldQueue, ShouldBeEncrypted
|
|
||||||
{
|
|
||||||
use Dispatchable, Queueable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the middleware the job should pass through.
|
|
||||||
*
|
|
||||||
* @return array<int, object>
|
|
||||||
*/
|
|
||||||
public function middleware(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
(new WithoutOverlapping($this->uniqueId()))->expireAfter(180),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
private readonly int $projectDocumentId,
|
|
||||||
private readonly array $contentIds = [],
|
|
||||||
private readonly array $exceptLanguages = [],
|
|
||||||
) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the unique ID for the job.
|
|
||||||
*/
|
|
||||||
public function uniqueId(): string
|
|
||||||
{
|
|
||||||
return 'documentation-' . $this->projectDocumentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function handle(DocumentationContentService $documentationContentService): void
|
|
||||||
{
|
|
||||||
$result = $documentationContentService->translate($this->projectDocumentId, $this->contentIds, $this->exceptLanguages);
|
|
||||||
if ($result->isError() && $result->getCode() !== 404) {
|
|
||||||
cache()->lock($this->uniqueId())->forceRelease();
|
|
||||||
throw new Exception($result->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Jobs\Translate;
|
|
||||||
|
|
||||||
use App\Services\Translate\Project\TranslationTextService;
|
|
||||||
use Exception;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Foundation\Queue\Queueable;
|
|
||||||
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
||||||
|
|
||||||
final class ProcessTranslationText implements ShouldQueue, ShouldBeEncrypted
|
|
||||||
{
|
|
||||||
use Dispatchable, Queueable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the middleware the job should pass through.
|
|
||||||
*
|
|
||||||
* @return array<int, object>
|
|
||||||
*/
|
|
||||||
public function middleware(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
(new WithoutOverlapping($this->uniqueId()))->expireAfter(180),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
private readonly int $projectId,
|
|
||||||
private readonly int $languageId,
|
|
||||||
private readonly array $translateTextCode = [],
|
|
||||||
private readonly array $exceptLanguages = [],
|
|
||||||
) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the unique ID for the job.
|
|
||||||
*/
|
|
||||||
public function uniqueId(): string
|
|
||||||
{
|
|
||||||
return 'ProcessTranslationText-' . $this->projectId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function handle(TranslationTextService $translationTextService): void
|
|
||||||
{
|
|
||||||
$result = $translationTextService->translate($this->projectId, $this->languageId, $this->translateTextCode, $this->exceptLanguages);
|
|
||||||
if ($result->isError() && $result->getCode() !== 404) {
|
|
||||||
cache()->lock($this->uniqueId())->forceRelease();
|
|
||||||
throw new Exception($result->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -37,7 +37,6 @@ final class Documentation extends Model
|
|||||||
'slug',
|
'slug',
|
||||||
'is_public',
|
'is_public',
|
||||||
'category_id',
|
'category_id',
|
||||||
'sort',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,6 +17,5 @@ final class ProjectContent extends Model implements StorageContract
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'title',
|
'title',
|
||||||
'description',
|
'description',
|
||||||
'language_id',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use App\Models\Scopes\SortScope;
|
|||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Database\Eloquent\Attributes\ScopedBy;
|
use Illuminate\Database\Eloquent\Attributes\ScopedBy;
|
||||||
|
|
||||||
@@ -71,9 +70,4 @@ final class ProjectLanguage extends Model
|
|||||||
},
|
},
|
||||||
)->shouldCache();
|
)->shouldCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serviceTranslate(): HasOne
|
|
||||||
{
|
|
||||||
return $this->hasOne(ProjectTranslationService::class, 'language_id', 'id');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
final class ProjectTranslationService extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
|
|
||||||
protected $table = 'project_translation_service';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'code',
|
|
||||||
'language_id',
|
|
||||||
'source_language_id',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Enums\Morph;
|
|
||||||
use App\Enums\ProjectTranslationServiceHashes\Status;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
final class ProjectTranslationServiceHash extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
|
|
||||||
protected $table = 'project_translation_service_hashes';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The model's default values for attributes.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $attributes = [
|
|
||||||
'status' => Status::Waiting,
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'language_id',
|
|
||||||
'field',
|
|
||||||
'status',
|
|
||||||
'hash',
|
|
||||||
'morph_type',
|
|
||||||
'morph_id',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the attributes that should be cast.
|
|
||||||
*
|
|
||||||
* @return array<string, string>
|
|
||||||
*/
|
|
||||||
protected function casts(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'status' => Status::class,
|
|
||||||
'morph_type' => Morph::class,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use App\Enums\ProjectTranslationServiceHashes\Status;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
final class ProjectTranslationServiceTextHash extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
|
|
||||||
protected $table = 'project_translation_service_text_hashes';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The model's default values for attributes.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $attributes = [
|
|
||||||
'status' => Status::Waiting,
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'language_id',
|
|
||||||
'code',
|
|
||||||
'status',
|
|
||||||
'hash',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the attributes that should be cast.
|
|
||||||
*
|
|
||||||
* @return array<string, string>
|
|
||||||
*/
|
|
||||||
protected function casts(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'status' => Status::class,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -32,11 +32,6 @@ final readonly class ProjectPolicy extends Policy
|
|||||||
return $user->hasPermission('project.delete');
|
return $user->hasPermission('project.delete');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function settingUpAutomaticTranslation(User $user, Project $project): bool
|
|
||||||
{
|
|
||||||
return $user->hasPermission('project.setting-up-automatic-translation');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function upload(User $user): bool
|
public function upload(User $user): bool
|
||||||
{
|
{
|
||||||
if ($user->hasPermission('project.create') || $user->hasPermission('project.update')) {
|
if ($user->hasPermission('project.create') || $user->hasPermission('project.update')) {
|
||||||
|
|||||||
@@ -11,9 +11,6 @@ use App\Services\Search\CreateSearchInstanceCommand;
|
|||||||
use App\Dto\Builder\DocumentationCategory as DocumentationCategoryBuilderDto;
|
use App\Dto\Builder\DocumentationCategory as DocumentationCategoryBuilderDto;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
final readonly class DocumentationCategoryRepository
|
final readonly class DocumentationCategoryRepository
|
||||||
@@ -96,52 +93,4 @@ final readonly class DocumentationCategoryRepository
|
|||||||
->pluck('title', 'id')
|
->pluck('title', 'id')
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPathFromRoot(int $categoryId, ?ProjectLanguage $projectLanguage): Collection
|
|
||||||
{
|
|
||||||
$seconds = 3600;
|
|
||||||
return Cache::remember(self::class . $categoryId . '_' . $projectLanguage->id ?? 0, $seconds, function () use ($categoryId, $projectLanguage) {
|
|
||||||
$rows = DB::select(
|
|
||||||
<<<SQL
|
|
||||||
WITH RECURSIVE chain AS (
|
|
||||||
SELECT id, parent_id, 0 AS depth
|
|
||||||
FROM documentation_categories
|
|
||||||
WHERE id = ?
|
|
||||||
|
|
||||||
UNION ALL
|
|
||||||
|
|
||||||
SELECT dc.id, dc.parent_id, chain.depth + 1 AS depth
|
|
||||||
FROM documentation_categories dc
|
|
||||||
INNER JOIN chain ON chain.parent_id = dc.id
|
|
||||||
)
|
|
||||||
SELECT id, depth
|
|
||||||
FROM chain
|
|
||||||
ORDER BY depth DESC
|
|
||||||
SQL,
|
|
||||||
[$categoryId]
|
|
||||||
);
|
|
||||||
|
|
||||||
$idsInOrder = collect($rows)->pluck('id')->all();
|
|
||||||
|
|
||||||
$with = [
|
|
||||||
'content' => function (HasOne $hasOne) use ($projectLanguage) {
|
|
||||||
/** @var ?ProjectLanguage $projectLanguage */
|
|
||||||
$hasOne->when($projectLanguage, function (Builder $query, ProjectLanguage $projectLanguage) {
|
|
||||||
$query->where('language_id', $projectLanguage->id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
$categories = DocumentationCategory::query()
|
|
||||||
->whereIn('id', $idsInOrder)
|
|
||||||
->with($with)
|
|
||||||
->get()
|
|
||||||
->keyBy('id');
|
|
||||||
|
|
||||||
return collect($idsInOrder)
|
|
||||||
->map(fn (int $id) => $categories->get($id))
|
|
||||||
->filter()
|
|
||||||
->values();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,4 @@ final readonly class ProjectTranslationRepository
|
|||||||
$query = ProjectTranslation::query()->withTrashed()->where('project_id', $projectId)->where('language_id', $languageId);
|
$query = ProjectTranslation::query()->withTrashed()->where('project_id', $projectId)->where('language_id', $languageId);
|
||||||
return $this->createSearchInstanceCommand->execute($query);
|
return $this->createSearchInstanceCommand->execute($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProjectTranslationByCodes(int $projectId, int $languageId, array $codes): Search
|
|
||||||
{
|
|
||||||
$query = ProjectTranslation::query()
|
|
||||||
->where('project_id', $projectId)
|
|
||||||
->where('language_id', $languageId)
|
|
||||||
->whereIn('code', $codes);
|
|
||||||
return $this->createSearchInstanceCommand->execute($query);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Repositories;
|
|
||||||
|
|
||||||
use App\Contracts\Search;
|
|
||||||
use App\Enums\Morph;
|
|
||||||
use App\Models\ProjectTranslationServiceHash;
|
|
||||||
use App\Services\Search\CreateSearchInstanceCommand;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
|
|
||||||
final readonly class ProjectTranslationServiceHashRepository
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private CreateSearchInstanceCommand $createSearchInstanceCommand,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function getHashes(Morph $morph, int $morphId, ?array $languages = null, ?array $fields = null): Search
|
|
||||||
{
|
|
||||||
$query = ProjectTranslationServiceHash::query()
|
|
||||||
->where('morph_type', $morph)
|
|
||||||
->where('morph_id', $morphId)
|
|
||||||
->when($languages, function (Builder $query) use ($languages) {
|
|
||||||
$query->whereIn('language_id', $languages);
|
|
||||||
})
|
|
||||||
->when($fields, function (Builder $query) use ($fields) {
|
|
||||||
$query->whereIn('field', $fields);
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this->createSearchInstanceCommand->execute($query);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHashesByIds(array $ids): Search
|
|
||||||
{
|
|
||||||
$query = ProjectTranslationServiceHash::query()->whereIn('id', $ids);
|
|
||||||
return $this->createSearchInstanceCommand->execute($query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Repositories;
|
|
||||||
|
|
||||||
use App\Models\ProjectTranslationService;
|
|
||||||
use App\Services\Search\CreateSearchInstanceCommand;
|
|
||||||
use App\Services\Search\Search;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
|
|
||||||
final readonly class ProjectTranslationServiceRepository
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private CreateSearchInstanceCommand $createSearchInstanceCommand,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function getLanguagesBySourceLanguage(int $sourceLanguage, ?array $excludeLanguages = null): Search
|
|
||||||
{
|
|
||||||
$query = ProjectTranslationService::query()
|
|
||||||
->select('language_id', 'code')
|
|
||||||
->where('source_language_id', $sourceLanguage)
|
|
||||||
->when($excludeLanguages, function (Builder $query) use ($excludeLanguages) {
|
|
||||||
$query->whereNotIn('language_id', $excludeLanguages);
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this->createSearchInstanceCommand->execute($query);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLanguageCodeByLanguageId(int $languageId): ?string
|
|
||||||
{
|
|
||||||
return ProjectTranslationService::query()
|
|
||||||
->select('code')
|
|
||||||
->where('language_id', $languageId)
|
|
||||||
->first()?->code ?? null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Repositories;
|
|
||||||
|
|
||||||
use App\Contracts\Search;
|
|
||||||
use App\Models\ProjectTranslationServiceTextHash;
|
|
||||||
use App\Services\Search\CreateSearchInstanceCommand;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
|
|
||||||
final readonly class ProjectTranslationServiceTextHashRepository
|
|
||||||
{
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
private CreateSearchInstanceCommand $createSearchInstanceCommand,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function getHashes(array $codes, ?array $languages = null): Search
|
|
||||||
{
|
|
||||||
$query = ProjectTranslationServiceTextHash::query()
|
|
||||||
->whereIn('code', $codes)
|
|
||||||
->when($languages, function (Builder $query) use ($languages) {
|
|
||||||
$query->whereIn('language_id', $languages);
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this->createSearchInstanceCommand->execute($query);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHashesByIds(array $ids): Search
|
|
||||||
{
|
|
||||||
$query = ProjectTranslationServiceTextHash::query()->whereIn('id', $ids);
|
|
||||||
return $this->createSearchInstanceCommand->execute($query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ namespace App\Services\Admin\Project;
|
|||||||
use App\Contracts\ServiceResultError;
|
use App\Contracts\ServiceResultError;
|
||||||
use App\Dto\Service\Admin\Project\About\StoreUpdate;
|
use App\Dto\Service\Admin\Project\About\StoreUpdate;
|
||||||
use App\Enums\Morph;
|
use App\Enums\Morph;
|
||||||
use App\Jobs\Translate\ProcessProjectContent;
|
|
||||||
use App\Models\ProjectContent;
|
use App\Models\ProjectContent;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Repositories\ProjectContentRepository;
|
use App\Repositories\ProjectContentRepository;
|
||||||
@@ -70,7 +69,6 @@ final class AboutService extends Service
|
|||||||
'project' => $project,
|
'project' => $project,
|
||||||
'language' => $language,
|
'language' => $language,
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
'serviceTranslationEnable' => config('translation_service.enable', false),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,9 +105,6 @@ final class AboutService extends Service
|
|||||||
$this->storageService->saveAndDelete($aboutProject, $storages);
|
$this->storageService->saveAndDelete($aboutProject, $storages);
|
||||||
return $aboutProject;
|
return $aboutProject;
|
||||||
});
|
});
|
||||||
if (\config('translation_service.enable', false)) {
|
|
||||||
$this->translateContent($aboutProject, $data);
|
|
||||||
}
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return $this->errService(__('Server Error'));
|
return $this->errService(__('Server Error'));
|
||||||
@@ -138,9 +133,6 @@ final class AboutService extends Service
|
|||||||
|
|
||||||
return $aboutProject;
|
return $aboutProject;
|
||||||
});
|
});
|
||||||
if (\config('translation_service.enable', false)) {
|
|
||||||
$this->translateContent($aboutProject, $data);
|
|
||||||
}
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return $this->errService(__('Server Error'));
|
return $this->errService(__('Server Error'));
|
||||||
@@ -156,15 +148,4 @@ final class AboutService extends Service
|
|||||||
'description' => $data->getDescription(),
|
'description' => $data->getDescription(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function translateContent(ProjectContent $projectContent, StoreUpdate $data): void
|
|
||||||
{
|
|
||||||
if (! $data->isTranslateAutomatically()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$translateExceptLanguages = [$projectContent->language_id];
|
|
||||||
$translateContentIds = [$projectContent->id];
|
|
||||||
|
|
||||||
ProcessProjectContent::dispatch($projectContent->project_id, $translateContentIds, $translateExceptLanguages);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,8 @@ namespace App\Services\Admin\Project;
|
|||||||
use App\Dto\QuerySettingsDto;
|
use App\Dto\QuerySettingsDto;
|
||||||
use App\Dto\Builder\DocumentationCategory as DocumentationCategoryBuilderDto;
|
use App\Dto\Builder\DocumentationCategory as DocumentationCategoryBuilderDto;
|
||||||
use App\Dto\Service\Admin\Project\DocumentationCategory\StoreUpdate;
|
use App\Dto\Service\Admin\Project\DocumentationCategory\StoreUpdate;
|
||||||
use App\Dto\Service\Admin\Project\DocumentationCategoryContent\Content;
|
|
||||||
use App\Dto\Service\Admin\Project\DocumentationCategoryContent\Contents;
|
|
||||||
use App\Exceptions\Services\DocumentationCategory\ParentException;
|
use App\Exceptions\Services\DocumentationCategory\ParentException;
|
||||||
use App\Exceptions\Services\ServiceException;
|
use App\Exceptions\Services\ServiceException;
|
||||||
use App\Jobs\Translate\ProcessProjectDocumentationCategoryContent;
|
|
||||||
use App\Models\DocumentationCategory;
|
use App\Models\DocumentationCategory;
|
||||||
use App\Models\DocumentationCategoryContent;
|
use App\Models\DocumentationCategoryContent;
|
||||||
use App\Models\ProjectLanguage;
|
use App\Models\ProjectLanguage;
|
||||||
@@ -20,7 +17,6 @@ use App\ServiceResults\ServiceResultArray;
|
|||||||
use App\ServiceResults\ServiceResultError;
|
use App\ServiceResults\ServiceResultError;
|
||||||
use App\ServiceResults\ServiceResultSuccess;
|
use App\ServiceResults\ServiceResultSuccess;
|
||||||
use App\ServiceResults\StoreUpdateResult;
|
use App\ServiceResults\StoreUpdateResult;
|
||||||
use App\Services\ClearCacheCommandHandler;
|
|
||||||
use App\Services\DocumentationCategory\DocumentationCategoryCommandHandler;
|
use App\Services\DocumentationCategory\DocumentationCategoryCommandHandler;
|
||||||
use App\Services\DocumentationCategoryContent\ModelSyncCommand;
|
use App\Services\DocumentationCategoryContent\ModelSyncCommand;
|
||||||
use App\Services\Service;
|
use App\Services\Service;
|
||||||
@@ -35,7 +31,6 @@ final class DocumentationCategoryService extends Service
|
|||||||
private readonly DocumentationCategoryRepository $documentationCategoryRepository,
|
private readonly DocumentationCategoryRepository $documentationCategoryRepository,
|
||||||
private readonly DocumentationCategoryCommandHandler $categoryCommandHandler,
|
private readonly DocumentationCategoryCommandHandler $categoryCommandHandler,
|
||||||
private readonly ModelSyncCommand $contentSaveCommand,
|
private readonly ModelSyncCommand $contentSaveCommand,
|
||||||
private readonly ClearCacheCommandHandler $clearCacheCommandHandler,
|
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public function index(int $projectId, int $versionId, DocumentationCategoryBuilderDto $documentationCategoryBuilderDto, QuerySettingsDto $querySettingsDto, User $user): ServiceResultError | ServiceResultArray
|
public function index(int $projectId, int $versionId, DocumentationCategoryBuilderDto $documentationCategoryBuilderDto, QuerySettingsDto $querySettingsDto, User $user): ServiceResultError | ServiceResultArray
|
||||||
@@ -77,7 +72,7 @@ final class DocumentationCategoryService extends Service
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(int $projectId, int $versionId, User $user, ?int $parentId = null): ServiceResultError | ServiceResultArray
|
public function create(int $projectId, int $versionId, User $user): ServiceResultError | ServiceResultArray
|
||||||
{
|
{
|
||||||
$version = $this->documentationVersionRepository->getVersionById($versionId);
|
$version = $this->documentationVersionRepository->getVersionById($versionId);
|
||||||
$project = $version?->project;
|
$project = $version?->project;
|
||||||
@@ -90,20 +85,11 @@ final class DocumentationCategoryService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
$defaultLanguage = $project->languages->where('is_default', 1)->first();
|
$defaultLanguage = $project->languages->where('is_default', 1)->first();
|
||||||
$category = new DocumentationCategory();
|
|
||||||
$categoryPath = null;
|
|
||||||
if ($parentId !== null) {
|
|
||||||
$category->parent_id = $parentId;
|
|
||||||
$categoryPath = $this->documentationCategoryRepository->getPathFromRoot($parentId, $defaultLanguage);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->result([
|
return $this->result([
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'project' => $project,
|
'project' => $project,
|
||||||
'category' => $category,
|
'category' => new DocumentationCategory(),
|
||||||
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage),
|
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage),
|
||||||
'serviceTranslationEnable' => config('translation_service.enable', false),
|
|
||||||
'categoryPath' => $categoryPath,
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,20 +110,16 @@ final class DocumentationCategoryService extends Service
|
|||||||
return $this->errFobidden(__('Access is denied'));
|
return $this->errFobidden(__('Access is denied'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$defaultLanguage = $project->languages->where('is_default', 1)->first();
|
|
||||||
$withCategories = [];
|
$withCategories = [];
|
||||||
$categoryPath = null;
|
|
||||||
if ($category->parent_id) {
|
if ($category->parent_id) {
|
||||||
$withCategories[] = $category->parent_id;
|
$withCategories[] = $category->parent_id;
|
||||||
$categoryPath = $this->documentationCategoryRepository->getPathFromRoot($category->parent_id, $defaultLanguage);
|
|
||||||
}
|
}
|
||||||
|
$defaultLanguage = $project->languages->where('is_default', 1)->first();
|
||||||
return $this->result([
|
return $this->result([
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'project' => $project,
|
'project' => $project,
|
||||||
'category' => $category,
|
'category' => $category,
|
||||||
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage, $category, $withCategories),
|
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage, $category, $withCategories),
|
||||||
'serviceTranslationEnable' => config('translation_service.enable', false),
|
|
||||||
'categoryPath' => $categoryPath,
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,12 +151,6 @@ final class DocumentationCategoryService extends Service
|
|||||||
|
|
||||||
return $category;
|
return $category;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (\config('translation_service.enable', false)) {
|
|
||||||
$this->translateContent($category, $data->getContents());
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->clearCacheCommandHandler->all();
|
|
||||||
} catch (ServiceException $e) {
|
} catch (ServiceException $e) {
|
||||||
return $e->getServiceResultError();
|
return $e->getServiceResultError();
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
@@ -225,12 +201,6 @@ final class DocumentationCategoryService extends Service
|
|||||||
|
|
||||||
return $category;
|
return $category;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (\config('translation_service.enable', false)) {
|
|
||||||
$this->translateContent($category, $data->getContents());
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->clearCacheCommandHandler->all();
|
|
||||||
} catch (ServiceException $e) {
|
} catch (ServiceException $e) {
|
||||||
return $e->getServiceResultError();
|
return $e->getServiceResultError();
|
||||||
} catch (ParentException $e) {
|
} catch (ParentException $e) {
|
||||||
@@ -267,8 +237,6 @@ final class DocumentationCategoryService extends Service
|
|||||||
DB::transaction(function () use ($category) {
|
DB::transaction(function () use ($category) {
|
||||||
$this->categoryCommandHandler->handleDestroy($category);
|
$this->categoryCommandHandler->handleDestroy($category);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->clearCacheCommandHandler->all();
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return $this->errService(__('Server Error'));
|
return $this->errService(__('Server Error'));
|
||||||
@@ -286,27 +254,4 @@ final class DocumentationCategoryService extends Service
|
|||||||
'parent_id' => $data->getParentId(),
|
'parent_id' => $data->getParentId(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function translateContent(DocumentationCategory $category, Contents $contents): void
|
|
||||||
{
|
|
||||||
$translateExceptLanguages = [];
|
|
||||||
|
|
||||||
$translateLanguages = [];
|
|
||||||
foreach ($contents->getContents() as $content) {
|
|
||||||
/** @var Content $content */
|
|
||||||
$translateExceptLanguages[] = $content->getLanguageId();
|
|
||||||
if ($content->isTranslateAutomatically()) {
|
|
||||||
$translateLanguages[] = $content->getLanguageId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($translateLanguages)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$translateContentIds = $category->contents()->select('id')
|
|
||||||
->whereIn('language_id', $translateLanguages)
|
|
||||||
->get()->pluck('id')->toArray();
|
|
||||||
ProcessProjectDocumentationCategoryContent::dispatch($category->id, $translateContentIds, $translateExceptLanguages);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ namespace App\Services\Admin\Project;
|
|||||||
use App\Dto\Builder\Documentation as DocumentationBuilderDto;
|
use App\Dto\Builder\Documentation as DocumentationBuilderDto;
|
||||||
use App\Dto\QuerySettingsDto;
|
use App\Dto\QuerySettingsDto;
|
||||||
use App\Dto\Service\Admin\Project\Documentation\StoreUpdate;
|
use App\Dto\Service\Admin\Project\Documentation\StoreUpdate;
|
||||||
use App\Dto\Service\Admin\Project\DocumentationContent\Content;
|
|
||||||
use App\Dto\Service\Admin\Project\DocumentationContent\Contents;
|
|
||||||
use App\Exceptions\Services\DocumentationContent\StorageCommandException;
|
use App\Exceptions\Services\DocumentationContent\StorageCommandException;
|
||||||
use App\Jobs\Translate\ProcessProjectDocumentationContent;
|
|
||||||
use App\Models\Documentation;
|
use App\Models\Documentation;
|
||||||
use App\Models\ProjectLanguage;
|
use App\Models\ProjectLanguage;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -75,7 +72,7 @@ final class DocumentationService extends Service
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(int $projectId, int $versionId, User $user, ?int $categoryId = null): ServiceResultError | ServiceResultArray
|
public function create(int $projectId, int $versionId, User $user): ServiceResultError | ServiceResultArray
|
||||||
{
|
{
|
||||||
$version = $this->documentationVersionRepository->getVersionById($versionId);
|
$version = $this->documentationVersionRepository->getVersionById($versionId);
|
||||||
$project = $version?->project;
|
$project = $version?->project;
|
||||||
@@ -88,20 +85,11 @@ final class DocumentationService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
$defaultLanguage = $project->languages->where('is_default', 1)->first();
|
$defaultLanguage = $project->languages->where('is_default', 1)->first();
|
||||||
$documentation = new Documentation();
|
|
||||||
$categoryPath = null;
|
|
||||||
if ($categoryId !== null) {
|
|
||||||
$documentation->category_id = $categoryId;
|
|
||||||
$categoryPath = $this->documentationCategoryRepository->getPathFromRoot($categoryId, $defaultLanguage);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->result([
|
return $this->result([
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'project' => $project,
|
'project' => $project,
|
||||||
'documentation' => $documentation,
|
'documentation' => new Documentation(),
|
||||||
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage),
|
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage),
|
||||||
'serviceTranslationEnable' => config('translation_service.enable', false),
|
|
||||||
'categoryPath' => $categoryPath,
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,20 +110,16 @@ final class DocumentationService extends Service
|
|||||||
return $this->errFobidden(__('Access is denied'));
|
return $this->errFobidden(__('Access is denied'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$defaultLanguage = $project->languages->where('is_default', 1)->first();
|
|
||||||
$withCategories = [];
|
$withCategories = [];
|
||||||
$categoryPath = null;
|
|
||||||
if ($documentation->category_id) {
|
if ($documentation->category_id) {
|
||||||
$withCategories[] = $documentation->category_id;
|
$withCategories[] = $documentation->category_id;
|
||||||
$categoryPath = $this->documentationCategoryRepository->getPathFromRoot($documentation->category_id, $defaultLanguage);
|
|
||||||
}
|
}
|
||||||
|
$defaultLanguage = $project->languages->where('is_default', 1)->first();
|
||||||
return $this->result([
|
return $this->result([
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'project' => $project,
|
'project' => $project,
|
||||||
'documentation' => $documentation,
|
'documentation' => $documentation,
|
||||||
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage, null, $withCategories),
|
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage, null, $withCategories),
|
||||||
'serviceTranslationEnable' => config('translation_service.enable', false),
|
|
||||||
'categoryPath' => $categoryPath,
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,10 +150,6 @@ final class DocumentationService extends Service
|
|||||||
|
|
||||||
return $documentation;
|
return $documentation;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (\config('translation_service.enable', false)) {
|
|
||||||
$this->translateContent($documentation, $data->getContents());
|
|
||||||
}
|
|
||||||
} catch (StorageCommandException $e) {
|
} catch (StorageCommandException $e) {
|
||||||
return $e->getResultError();
|
return $e->getResultError();
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
@@ -212,10 +192,6 @@ final class DocumentationService extends Service
|
|||||||
|
|
||||||
return $documentation;
|
return $documentation;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (\config('translation_service.enable', false)) {
|
|
||||||
$this->translateContent($documentation, $data->getContents());
|
|
||||||
}
|
|
||||||
} catch (StorageCommandException $e) {
|
} catch (StorageCommandException $e) {
|
||||||
return $e->getResultError();
|
return $e->getResultError();
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
@@ -264,27 +240,4 @@ final class DocumentationService extends Service
|
|||||||
'category_id' => $data->getCategoryId(),
|
'category_id' => $data->getCategoryId(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function translateContent(Documentation $documentation, Contents $contents): void
|
|
||||||
{
|
|
||||||
$translateExceptLanguages = [];
|
|
||||||
|
|
||||||
$translateLanguages = [];
|
|
||||||
foreach ($contents->getContents() as $content) {
|
|
||||||
/** @var Content $content */
|
|
||||||
$translateExceptLanguages[] = $content->getLanguageId();
|
|
||||||
if ($content->isTranslateAutomatically()) {
|
|
||||||
$translateLanguages[] = $content->getLanguageId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($translateLanguages)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$translateContentIds = $documentation->contents()->select('id')
|
|
||||||
->whereIn('language_id', $translateLanguages)
|
|
||||||
->get()->pluck('id')->toArray();
|
|
||||||
ProcessProjectDocumentationContent::dispatch($documentation->id, $translateContentIds, $translateExceptLanguages);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Services\Admin\Project;
|
namespace App\Services\Admin\Project;
|
||||||
|
|
||||||
use App\Dto\Builder\Documentation as DocumentationBuilderDto;
|
|
||||||
use App\Dto\Builder\DocumentationCategory as DocumentationCategoryBuilderDto;
|
|
||||||
use App\Dto\QuerySettingsDto;
|
use App\Dto\QuerySettingsDto;
|
||||||
use App\Dto\Builder\DocumentationVersion as DocumentationVersionBuilderDto;
|
use App\Dto\Builder\DocumentationVersion as DocumentationVersionBuilderDto;
|
||||||
use App\Dto\Service\Admin\Project\DocumentationVersion\StoreUpdate;
|
use App\Dto\Service\Admin\Project\DocumentationVersion\StoreUpdate;
|
||||||
|
use App\Enums\CacheTag;
|
||||||
use App\Enums\DocumentationVersionStatus;
|
use App\Enums\DocumentationVersionStatus;
|
||||||
use App\Models\DocumentationVersion;
|
use App\Models\DocumentationVersion;
|
||||||
use App\Models\ProjectLanguage;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Repositories\DocumentationCategoryRepository;
|
|
||||||
use App\Repositories\DocumentationRepository;
|
|
||||||
use App\Repositories\DocumentationVersionRepository;
|
use App\Repositories\DocumentationVersionRepository;
|
||||||
use App\Repositories\ProjectRepository;
|
use App\Repositories\ProjectRepository;
|
||||||
use App\ServiceResults\ServiceResultArray;
|
use App\ServiceResults\ServiceResultArray;
|
||||||
@@ -22,8 +18,6 @@ use App\ServiceResults\StoreUpdateResult;
|
|||||||
use App\Services\ClearCacheCommandHandler;
|
use App\Services\ClearCacheCommandHandler;
|
||||||
use App\Services\DocumentationVersion\DocumentationVersionCommandHandler;
|
use App\Services\DocumentationVersion\DocumentationVersionCommandHandler;
|
||||||
use App\Services\Service;
|
use App\Services\Service;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
final class DocumentationVersionService extends Service
|
final class DocumentationVersionService extends Service
|
||||||
@@ -33,9 +27,6 @@ final class DocumentationVersionService extends Service
|
|||||||
private readonly DocumentationVersionRepository $documentationVersionRepository,
|
private readonly DocumentationVersionRepository $documentationVersionRepository,
|
||||||
private readonly DocumentationVersionCommandHandler $documentationVersionCommandHandler,
|
private readonly DocumentationVersionCommandHandler $documentationVersionCommandHandler,
|
||||||
private readonly ClearCacheCommandHandler $clearCacheCommandHandler,
|
private readonly ClearCacheCommandHandler $clearCacheCommandHandler,
|
||||||
|
|
||||||
private readonly DocumentationCategoryRepository $documentationCategoryRepository,
|
|
||||||
private readonly DocumentationRepository $documentationRepository
|
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public function index(int $projectId, DocumentationVersionBuilderDto $documentationVersionBuilderDto, QuerySettingsDto $querySettingsDto, User $user): ServiceResultError | ServiceResultArray
|
public function index(int $projectId, DocumentationVersionBuilderDto $documentationVersionBuilderDto, QuerySettingsDto $querySettingsDto, User $user): ServiceResultError | ServiceResultArray
|
||||||
@@ -64,7 +55,7 @@ final class DocumentationVersionService extends Service
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show(int $projectId, int $versionId, ?int $categoryId, User $user): ServiceResultError | ServiceResultArray
|
public function show(int $projectId, int $versionId, User $user): ServiceResultError | ServiceResultArray
|
||||||
{
|
{
|
||||||
$project = $this->projectRepository->getProjectById($projectId);
|
$project = $this->projectRepository->getProjectById($projectId);
|
||||||
if (\is_null($project)) {
|
if (\is_null($project)) {
|
||||||
@@ -80,52 +71,9 @@ final class DocumentationVersionService extends Service
|
|||||||
return $this->errFobidden(__('Access is denied'));
|
return $this->errFobidden(__('Access is denied'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$defaultLanguage = $project->languages()->where('is_default', 1)->first();
|
|
||||||
|
|
||||||
$category = null;
|
|
||||||
$categoryPath = null;
|
|
||||||
if (!\is_null($categoryId)) {
|
|
||||||
$category = $this->documentationCategoryRepository->getCategoryById($categoryId);
|
|
||||||
if (\is_null($category) || $category->version_id !== $version->id) {
|
|
||||||
return $this->errNotFound(__('Not Found'));
|
|
||||||
}
|
|
||||||
if ($user->cannot('view', $category)) {
|
|
||||||
return $this->errFobidden(__('Access is denied'));
|
|
||||||
}
|
|
||||||
$categoryPath = $this->documentationCategoryRepository->getPathFromRoot($category->id, $defaultLanguage);
|
|
||||||
}
|
|
||||||
|
|
||||||
$with = [
|
|
||||||
'content' => function (HasOne $hasOne) use ($defaultLanguage) {
|
|
||||||
/** @var ?ProjectLanguage $defaultLanguage */
|
|
||||||
$hasOne->when($defaultLanguage, function (Builder $query, ProjectLanguage $defaultLanguage) {
|
|
||||||
$query->where('language_id', $defaultLanguage->id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
$categoryDto = new DocumentationCategoryBuilderDto\Category($category->id ?? null);
|
|
||||||
$categories = $this->documentationCategoryRepository
|
|
||||||
->getCategories(
|
|
||||||
$version->id,
|
|
||||||
new DocumentationCategoryBuilderDto(parentId: $categoryDto),
|
|
||||||
$with
|
|
||||||
)->all();
|
|
||||||
$documents = $this->documentationRepository
|
|
||||||
->getDocumentations(
|
|
||||||
$version->id,
|
|
||||||
new DocumentationBuilderDto(categoryId: $categoryDto),
|
|
||||||
$with
|
|
||||||
)->all();
|
|
||||||
|
|
||||||
return $this->result([
|
return $this->result([
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'project' => $project,
|
'project' => $project,
|
||||||
|
|
||||||
'category' => $category,
|
|
||||||
'categoryPath' => $categoryPath,
|
|
||||||
'categories' => $categories,
|
|
||||||
'documentations' => $documents,
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +141,7 @@ final class DocumentationVersionService extends Service
|
|||||||
$dataVersion = $this->getDataVersion($data);
|
$dataVersion = $this->getDataVersion($data);
|
||||||
return $this->documentationVersionCommandHandler->handleStore($project, $dataVersion);
|
return $this->documentationVersionCommandHandler->handleStore($project, $dataVersion);
|
||||||
});
|
});
|
||||||
$this->clearCacheCommandHandler->all();
|
$this->clearCacheCommandHandler->byTag(CacheTag::DocumantationVersion);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return $this->errService(__('Server Error'));
|
return $this->errService(__('Server Error'));
|
||||||
@@ -230,7 +178,7 @@ final class DocumentationVersionService extends Service
|
|||||||
$dataVersion = $this->getDataVersion($data);
|
$dataVersion = $this->getDataVersion($data);
|
||||||
return $this->documentationVersionCommandHandler->handleUpdate($version, $dataVersion);
|
return $this->documentationVersionCommandHandler->handleUpdate($version, $dataVersion);
|
||||||
});
|
});
|
||||||
$this->clearCacheCommandHandler->all();
|
$this->clearCacheCommandHandler->byTag(CacheTag::DocumantationVersion);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return $this->errService(__('Server Error'));
|
return $this->errService(__('Server Error'));
|
||||||
@@ -259,7 +207,7 @@ final class DocumentationVersionService extends Service
|
|||||||
DB::transaction(function () use ($version) {
|
DB::transaction(function () use ($version) {
|
||||||
$this->documentationVersionCommandHandler->handleDestroy($version);
|
$this->documentationVersionCommandHandler->handleDestroy($version);
|
||||||
});
|
});
|
||||||
$this->clearCacheCommandHandler->all();
|
$this->clearCacheCommandHandler->byTag(CacheTag::DocumantationVersion);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return $this->errService(__('Server Error'));
|
return $this->errService(__('Server Error'));
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\Admin\Project;
|
|
||||||
|
|
||||||
use App\Dto\Service\Admin\Project\ServiceTranslate\Update;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Repositories\ProjectRepository;
|
|
||||||
use App\ServiceResults\ServiceResultArray;
|
|
||||||
use App\ServiceResults\ServiceResultError;
|
|
||||||
use App\ServiceResults\ServiceResultSuccess;
|
|
||||||
use App\Services\ProjectTranslationService\ModelSyncCommand as TranslationServiceModelSyncCommand;
|
|
||||||
use App\Services\Service;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
|
|
||||||
final class ServiceTranslateService extends Service
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly ProjectRepository $projectRepository,
|
|
||||||
private readonly TranslationServiceModelSyncCommand $translationServiceModelSyncCommand,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function view(int $projectId, User $user): ServiceResultError | ServiceResultArray
|
|
||||||
{
|
|
||||||
$project = $this->projectRepository->getProjectById($projectId);
|
|
||||||
if (\is_null($project)) {
|
|
||||||
return $this->errNotFound(__('Not Found'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
config('translation_service.enable', false) === false
|
|
||||||
|| $user->cannot('settingUpAutomaticTranslation', $project)
|
|
||||||
) {
|
|
||||||
return $this->errFobidden(__('Access is denied'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->result([
|
|
||||||
'project' => $project,
|
|
||||||
'languages' => $project->languages()->with(['serviceTranslate'])->get(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(int $projectId, Update $data, User $user): ServiceResultError | ServiceResultSuccess
|
|
||||||
{
|
|
||||||
$project = $this->projectRepository->getProjectById($projectId);
|
|
||||||
if (\is_null($project)) {
|
|
||||||
return $this->errNotFound(__('Not Found'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
config('translation_service.enable', false) === false
|
|
||||||
|| $user->cannot('settingUpAutomaticTranslation', $project)
|
|
||||||
) {
|
|
||||||
return $this->errFobidden(__('Access is denied'));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
DB::transaction(function () use ($data, $project) {
|
|
||||||
$this->translationServiceModelSyncCommand->execute($project, $data->getTranslations());
|
|
||||||
});
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
report($e);
|
|
||||||
return $this->errService(__('Server Error'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->ok(__('The settings were saved successfully'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,9 +3,8 @@
|
|||||||
namespace App\Services\Admin\Project;
|
namespace App\Services\Admin\Project;
|
||||||
|
|
||||||
use App\Dto\Service\Admin\Project\Translation\Translations;
|
use App\Dto\Service\Admin\Project\Translation\Translations;
|
||||||
use App\Dto\Service\Admin\Project\Translation\Translation;
|
|
||||||
use App\Dto\Service\Admin\Project\Translation\Update;
|
use App\Dto\Service\Admin\Project\Translation\Update;
|
||||||
use App\Jobs\Translate\ProcessTranslationText;
|
use App\Enums\CacheTag;
|
||||||
use App\Models\ProjectTranslation;
|
use App\Models\ProjectTranslation;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Repositories\ProjectRepository;
|
use App\Repositories\ProjectRepository;
|
||||||
@@ -61,7 +60,6 @@ final class TranslationService extends Service
|
|||||||
'language' => $language,
|
'language' => $language,
|
||||||
'projectTranslations' => $this->projectTranslationRepository->getProjectTranslations($projectId, $languageId)->all()->pluck('text', 'code')->toArray(),
|
'projectTranslations' => $this->projectTranslationRepository->getProjectTranslations($projectId, $languageId)->all()->pluck('text', 'code')->toArray(),
|
||||||
'translations' => Translations::getTranslationCodes(),
|
'translations' => Translations::getTranslationCodes(),
|
||||||
'serviceTranslationEnable' => config('translation_service.enable', false),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,10 +80,7 @@ final class TranslationService extends Service
|
|||||||
DB::transaction(function () use ($data, $project, $language) {
|
DB::transaction(function () use ($data, $project, $language) {
|
||||||
$this->translationModelSyncCommand->execute($project, $language, $data->getTranslations());
|
$this->translationModelSyncCommand->execute($project, $language, $data->getTranslations());
|
||||||
});
|
});
|
||||||
$this->clearCacheCommandHandler->all();
|
$this->clearCacheCommandHandler->byTag(CacheTag::ProjectTranslation);
|
||||||
if (\config('translation_service.enable', false)) {
|
|
||||||
$this->translateContent($projectId, $languageId, $data);
|
|
||||||
}
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return $this->errService(__('Server Error'));
|
return $this->errService(__('Server Error'));
|
||||||
@@ -93,19 +88,4 @@ final class TranslationService extends Service
|
|||||||
|
|
||||||
return $this->ok(__('Translations successfully updated'));
|
return $this->ok(__('Translations successfully updated'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function translateContent(int $projectId, int $languageId, Update $data): void
|
|
||||||
{
|
|
||||||
if (! $data->isTranslateAutomatically()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$translateExceptLanguages = [$languageId];
|
|
||||||
$translateTextCode = [];
|
|
||||||
foreach ($data->getTranslations()->getTranslations() as $translation) {
|
|
||||||
/** @var Translation $translation */
|
|
||||||
$translateTextCode[] = $translation->getCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessTranslationText::dispatch($projectId, $languageId, $translateTextCode, $translateExceptLanguages);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Services\Admin;
|
|||||||
use App\Dto\Builder\Project as ProjectBuilderDto;
|
use App\Dto\Builder\Project as ProjectBuilderDto;
|
||||||
use App\Dto\QuerySettingsDto;
|
use App\Dto\QuerySettingsDto;
|
||||||
use App\Dto\Service\Admin\Project\StoreUpdate;
|
use App\Dto\Service\Admin\Project\StoreUpdate;
|
||||||
|
use App\Enums\CacheTag;
|
||||||
use App\Enums\Morph;
|
use App\Enums\Morph;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\ProjectLanguage;
|
use App\Models\ProjectLanguage;
|
||||||
@@ -49,7 +50,6 @@ final class ProjectService extends Service
|
|||||||
|
|
||||||
return $this->result([
|
return $this->result([
|
||||||
'projects' => $projects,
|
'projects' => $projects,
|
||||||
'serviceTranslationEnable' => config('translation_service.enable', false),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ final class ProjectService extends Service
|
|||||||
|
|
||||||
return $project;
|
return $project;
|
||||||
});
|
});
|
||||||
$this->clearCacheCommandHandler->all();
|
$this->clearCacheCommandHandler->byTag(CacheTag::Project);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return $this->errService(__('Server Error'));
|
return $this->errService(__('Server Error'));
|
||||||
@@ -176,7 +176,7 @@ final class ProjectService extends Service
|
|||||||
|
|
||||||
return $project;
|
return $project;
|
||||||
});
|
});
|
||||||
$this->clearCacheCommandHandler->all();
|
$this->clearCacheCommandHandler->byTag(CacheTag::Project);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return $this->errService(__('Server Error'));
|
return $this->errService(__('Server Error'));
|
||||||
@@ -201,7 +201,7 @@ final class ProjectService extends Service
|
|||||||
DB::transaction(function () use ($project) {
|
DB::transaction(function () use ($project) {
|
||||||
$this->projectCommandHandler->handleDestroy($project);
|
$this->projectCommandHandler->handleDestroy($project);
|
||||||
});
|
});
|
||||||
$this->clearCacheCommandHandler->all();
|
$this->clearCacheCommandHandler->byTag(CacheTag::Project);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return $this->errService(__('Server Error'));
|
return $this->errService(__('Server Error'));
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
use App\Enums\CacheTag;
|
||||||
|
|
||||||
final readonly class ClearCacheCommandHandler
|
final readonly class ClearCacheCommandHandler
|
||||||
{
|
{
|
||||||
public function all(): void
|
public function byTag(CacheTag $tag)
|
||||||
{
|
{
|
||||||
Cache::flush();
|
$tag->getCache()->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\ProjectTranslation;
|
|
||||||
|
|
||||||
use App\Models\ProjectLanguage;
|
|
||||||
|
|
||||||
final readonly class TranslationText
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private ProjectLanguage $language,
|
|
||||||
private array $translations,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public static function init(ProjectLanguage $language, array $translations): self
|
|
||||||
{
|
|
||||||
return new self($language, $translations);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function translate(string $code): string
|
|
||||||
{
|
|
||||||
return $this->translations[$code] ?? __($code, [], $this->language->system_lang?->getLocale());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\ProjectTranslation;
|
|
||||||
|
|
||||||
use App\Models\Project;
|
|
||||||
use App\Models\ProjectLanguage;
|
|
||||||
use App\Repositories\ProjectTranslationRepository;
|
|
||||||
|
|
||||||
final readonly class TranslationTextCommand
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private ProjectTranslationRepository $translationRepository,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function execute(Project $project, ProjectLanguage $language, array $codes): TranslationText
|
|
||||||
{
|
|
||||||
$translations = $this->translationRepository
|
|
||||||
->getProjectTranslationByCodes($project->id, $language->id, $codes)
|
|
||||||
->all()->pluck('text', 'code');
|
|
||||||
|
|
||||||
return TranslationText::init($language, $translations->toArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\ProjectTranslationService;
|
|
||||||
|
|
||||||
use App\Models\Project;
|
|
||||||
use App\Dto\Service\Admin\Project\ServiceTranslate\Translations;
|
|
||||||
use App\Models\ProjectTranslationService;
|
|
||||||
|
|
||||||
final readonly class ModelSyncCommand
|
|
||||||
{
|
|
||||||
public function execute(Project $project, Translations $translations): void
|
|
||||||
{
|
|
||||||
$insert = [];
|
|
||||||
$delete = [];
|
|
||||||
|
|
||||||
$languages = $project->languages()->with(['serviceTranslate'])->get();
|
|
||||||
foreach ($translations->getTranslations() as $translation) {
|
|
||||||
/* @var \App\Dto\Service\Admin\Project\ServiceTranslate\Translation $translation */
|
|
||||||
$language = $languages->firstWhere('id', '=', $translation->getLanguageId());
|
|
||||||
if ($language === null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$serviceTranslate = $language->serviceTranslate;
|
|
||||||
if ($serviceTranslate === null) {
|
|
||||||
if ($translation->getCode() !== null) {
|
|
||||||
$insert[] = [
|
|
||||||
'language_id' => $translation->getLanguageId(),
|
|
||||||
'code' => $translation->getCode(),
|
|
||||||
'source_language_id' => $translation->getSourceLanguageId(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($translation->getCode() === null) {
|
|
||||||
$delete[] = [$serviceTranslate->id];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$serviceTranslate->update([
|
|
||||||
'code' => $translation->getCode(),
|
|
||||||
'source_language_id' => $translation->getSourceLanguageId(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($insert)) {
|
|
||||||
ProjectTranslationService::query()->insert($insert);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($delete)) {
|
|
||||||
ProjectTranslationService::query()->whereIn('id', $delete)->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\ProjectTranslationService;
|
|
||||||
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
final readonly class NoTranslateAttributeHandler
|
|
||||||
{
|
|
||||||
public function handleAddAttribute(string $text): string
|
|
||||||
{
|
|
||||||
return Str::replace('<code', '<code translate="no"', $text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleRemoveAttribute(string $text): string
|
|
||||||
{
|
|
||||||
return Str::replace('<code translate="no"', '<code', $text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\ProjectTranslationServiceHash;
|
|
||||||
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\Hashes;
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\HashStatusWaiting;
|
|
||||||
use App\Enums\ProjectTranslationServiceHashes\Status;
|
|
||||||
use App\Repositories\ProjectTranslationServiceHashRepository;
|
|
||||||
|
|
||||||
final readonly class CompletionChecker
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private ProjectTranslationServiceHashRepository $hashRepository,
|
|
||||||
private ProjectTranslationServiceHashCommandHandler $commandHandler,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function execute(Hashes $hashesDto): HashStatusWaiting
|
|
||||||
{
|
|
||||||
$hashes = $this->hashRepository->getHashesByIds($hashesDto->getIds())->all();
|
|
||||||
$hashStatusWaiting = new HashStatusWaiting();
|
|
||||||
$hashSuccessIds = [];
|
|
||||||
foreach ($hashes as $hash) {
|
|
||||||
$dataHash = $hashesDto->getHash($hash->id);
|
|
||||||
if ($dataHash === null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$isWaiting = false;
|
|
||||||
if ($hash->status === Status::Waiting && $hash->hash === $dataHash['hash'] && $hash->field === $dataHash['field']) {
|
|
||||||
$isWaiting = true;
|
|
||||||
$hashSuccessIds[] = $hash->id;
|
|
||||||
}
|
|
||||||
$hashStatusWaiting->add($hash->field, $isWaiting);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->commandHandler->handleSetStatusById($hashSuccessIds, Status::Success);
|
|
||||||
|
|
||||||
return $hashStatusWaiting;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\ProjectTranslationServiceHash;
|
|
||||||
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\Fields;
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\TranslateFields;
|
|
||||||
use App\Enums\Morph;
|
|
||||||
use App\Enums\ProjectTranslationServiceHashes\Status;
|
|
||||||
use App\Models\ProjectTranslationServiceHash;
|
|
||||||
use App\Repositories\ProjectTranslationServiceHashRepository;
|
|
||||||
|
|
||||||
final readonly class HashTrackerCommand
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private ProjectTranslationServiceHashRepository $hashRepository,
|
|
||||||
private ProjectTranslationServiceHashCommandHandler $commandHandler,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function execute(Morph $morph, int $morphId, array $languages, Fields $fields): TranslateFields
|
|
||||||
{
|
|
||||||
$hashes = $this->hashRepository->getHashes($morph, $morphId, $languages, $fields->getNames())->all();
|
|
||||||
|
|
||||||
$translateFields = new TranslateFields();
|
|
||||||
foreach ($fields->getFields() as $fieldName => $fieldValue) {
|
|
||||||
$textHash = $this->generateHashFromText((string) $fieldValue);
|
|
||||||
foreach ($languages as $language) {
|
|
||||||
$modelHash = $hashes->where('language_id', $language)->firstWhere('field', $fieldName);
|
|
||||||
if ($modelHash === null) {
|
|
||||||
$modelHash = $this->commandHandler->handleStore([
|
|
||||||
'language_id' => $language,
|
|
||||||
'morph_type' => $morph,
|
|
||||||
'morph_id' => $morphId,
|
|
||||||
'field' => $fieldName,
|
|
||||||
'hash' => $textHash,
|
|
||||||
'status' => Status::Waiting,
|
|
||||||
]);
|
|
||||||
$translateFields->add($language, $fieldName, $textHash, $modelHash->id);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($modelHash->hash === $textHash && $this->isSuccess($modelHash)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$translateFields->add($language, $fieldName, $textHash, $modelHash->id);
|
|
||||||
$this->commandHandler->handleUpdate($modelHash, [
|
|
||||||
'hash' => $textHash,
|
|
||||||
'status' => Status::Waiting,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $translateFields;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function generateHashFromText(string $text): string
|
|
||||||
{
|
|
||||||
return \hash('sha256', $text);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function isSuccess(ProjectTranslationServiceHash $modelHash): bool
|
|
||||||
{
|
|
||||||
if ($modelHash->status === Status::Success) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ($modelHash->updated_at >= now()->subMinutes(10));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-26
@@ -1,26 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\ProjectTranslationServiceHash;
|
|
||||||
|
|
||||||
use App\Enums\ProjectTranslationServiceHashes\Status;
|
|
||||||
use App\Models\ProjectTranslationServiceHash;
|
|
||||||
|
|
||||||
final readonly class ProjectTranslationServiceHashCommandHandler
|
|
||||||
{
|
|
||||||
public function handleStore(array $data): ProjectTranslationServiceHash
|
|
||||||
{
|
|
||||||
return ProjectTranslationServiceHash::create($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleUpdate(ProjectTranslationServiceHash $hash, array $data): ProjectTranslationServiceHash
|
|
||||||
{
|
|
||||||
$hash->update($data);
|
|
||||||
$hash->touch();
|
|
||||||
return $hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleSetStatusById(array $ids, Status $status): void
|
|
||||||
{
|
|
||||||
ProjectTranslationServiceHash::query()->whereIn('id', $ids)->update(['status' => $status->value]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\ProjectTranslationServiceTextHash;
|
|
||||||
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceTextHash\Hashes;
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceTextHash\HashStatusWaiting;
|
|
||||||
use App\Enums\ProjectTranslationServiceHashes\Status;
|
|
||||||
use App\Repositories\ProjectTranslationServiceTextHashRepository;
|
|
||||||
|
|
||||||
final readonly class CompletionChecker
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private ProjectTranslationServiceTextHashRepository $hashRepository,
|
|
||||||
private ProjectTranslationServiceTextHashCommandHandler $commandHandler,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function execute(Hashes $hashesDto): HashStatusWaiting
|
|
||||||
{
|
|
||||||
$hashes = $this->hashRepository->getHashesByIds($hashesDto->getIds())->all();
|
|
||||||
$hashStatusWaiting = new HashStatusWaiting();
|
|
||||||
$hashSuccessIds = [];
|
|
||||||
foreach ($hashes as $hash) {
|
|
||||||
$dataHash = $hashesDto->getHash($hash->id);
|
|
||||||
if ($dataHash === null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$isWaiting = false;
|
|
||||||
if ($hash->status === Status::Waiting && $hash->hash === $dataHash['hash'] && $hash->code === $dataHash['code']) {
|
|
||||||
$isWaiting = true;
|
|
||||||
$hashSuccessIds[] = $hash->id;
|
|
||||||
}
|
|
||||||
$hashStatusWaiting->add($hash->code, $isWaiting);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->commandHandler->handleSetStatusById($hashSuccessIds, Status::Success);
|
|
||||||
|
|
||||||
return $hashStatusWaiting;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\ProjectTranslationServiceTextHash;
|
|
||||||
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceTextHash\Codes;
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceTextHash\TranslateCodes;
|
|
||||||
use App\Enums\ProjectTranslationServiceHashes\Status;
|
|
||||||
use App\Models\ProjectTranslationServiceTextHash;
|
|
||||||
use App\Repositories\ProjectTranslationServiceTextHashRepository;
|
|
||||||
|
|
||||||
final readonly class HashTrackerCommand
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private ProjectTranslationServiceTextHashRepository $hashRepository,
|
|
||||||
private ProjectTranslationServiceTextHashCommandHandler $commandHandler,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function execute(array $languages, Codes $codes): TranslateCodes
|
|
||||||
{
|
|
||||||
$hashes = $this->hashRepository->getHashes($codes->getCodeNames(), $languages)->all();
|
|
||||||
|
|
||||||
$translateCodes = new TranslateCodes();
|
|
||||||
foreach ($codes->getCodes() as $code => $value) {
|
|
||||||
$textHash = $this->generateHashFromText((string) $value);
|
|
||||||
foreach ($languages as $language) {
|
|
||||||
$modelHash = $hashes->where('language_id', $language)->firstWhere('code', $code);
|
|
||||||
if ($modelHash === null) {
|
|
||||||
$modelHash = $this->commandHandler->handleStore([
|
|
||||||
'language_id' => $language,
|
|
||||||
'code' => $code,
|
|
||||||
'hash' => $textHash,
|
|
||||||
'status' => Status::Waiting,
|
|
||||||
]);
|
|
||||||
$translateCodes->add($language, $code, $textHash, $modelHash->id);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($modelHash->hash === $textHash && $this->isSuccess($modelHash)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$translateCodes->add($language, $code, $textHash, $modelHash->id);
|
|
||||||
$this->commandHandler->handleUpdate($modelHash, [
|
|
||||||
'hash' => $textHash,
|
|
||||||
'status' => Status::Waiting,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $translateCodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function generateHashFromText(string $text): string
|
|
||||||
{
|
|
||||||
return \hash('sha256', $text);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function isSuccess(ProjectTranslationServiceTextHash $modelHash): bool
|
|
||||||
{
|
|
||||||
if ($modelHash->status === Status::Success) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ($modelHash->updated_at >= now()->subMinutes(10));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-26
@@ -1,26 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\ProjectTranslationServiceTextHash;
|
|
||||||
|
|
||||||
use App\Enums\ProjectTranslationServiceHashes\Status;
|
|
||||||
use App\Models\ProjectTranslationServiceTextHash;
|
|
||||||
|
|
||||||
final readonly class ProjectTranslationServiceTextHashCommandHandler
|
|
||||||
{
|
|
||||||
public function handleStore(array $data): ProjectTranslationServiceTextHash
|
|
||||||
{
|
|
||||||
return ProjectTranslationServiceTextHash::create($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleUpdate(ProjectTranslationServiceTextHash $hash, array $data): ProjectTranslationServiceTextHash
|
|
||||||
{
|
|
||||||
$hash->update($data);
|
|
||||||
$hash->touch();
|
|
||||||
return $hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleSetStatusById(array $ids, Status $status): void
|
|
||||||
{
|
|
||||||
ProjectTranslationServiceTextHash::query()->whereIn('id', $ids)->update(['status' => $status->value]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Services\Site;
|
namespace App\Services\Site;
|
||||||
|
|
||||||
use App\Dto\Service\Site\Documentation;
|
use App\Dto\Service\Site\Documentation;
|
||||||
|
use App\Enums\CacheTag;
|
||||||
use App\Enums\DocumentationVersionStatus;
|
use App\Enums\DocumentationVersionStatus;
|
||||||
use App\Models\DocumentationCategory;
|
use App\Models\DocumentationCategory;
|
||||||
use App\Models\Documentation as ModelDocumentation;
|
use App\Models\Documentation as ModelDocumentation;
|
||||||
@@ -21,7 +22,6 @@ use App\Dto\Builder\Documentation as DocumentationBuilderDto;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
|
|
||||||
final class DocumentationService extends Service
|
final class DocumentationService extends Service
|
||||||
{
|
{
|
||||||
@@ -37,7 +37,8 @@ final class DocumentationService extends Service
|
|||||||
if ($user?->cannot('viewAny', DocumentationVersion::class)) {
|
if ($user?->cannot('viewAny', DocumentationVersion::class)) {
|
||||||
$isPublic = 1;
|
$isPublic = 1;
|
||||||
}
|
}
|
||||||
$version = Cache::remember(self::class . $project->id . '_' . $isPublic ?? 0, $seconds, function () use ($project, $isPublic) {
|
$version = CacheTag::DocumantationVersion->getCache()
|
||||||
|
->remember(self::class . $project->id . '_' . $isPublic ?? 0, $seconds, function () use ($project, $isPublic) {
|
||||||
$versions = $project->documentationVersions()
|
$versions = $project->documentationVersions()
|
||||||
->when($isPublic, function (Builder $query) {
|
->when($isPublic, function (Builder $query) {
|
||||||
$query->where('is_public', 1);
|
$query->where('is_public', 1);
|
||||||
@@ -77,16 +78,10 @@ final class DocumentationService extends Service
|
|||||||
return $this->errFobidden(__('Access is denied'));
|
return $this->errFobidden(__('Access is denied'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$categoryPath = null;
|
|
||||||
if ($category->parent_id) {
|
|
||||||
$categoryPath = $this->documentationCategoryRepository->getPathFromRoot($category->parent_id, $documentation->getWebsiteTranslations()->getLanguage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array_merge($documentation->toArray(), [
|
$data = array_merge($documentation->toArray(), [
|
||||||
'category' => $category,
|
'category' => $category,
|
||||||
'categories' => $this->getCategories($documentation, $category->id),
|
'categories' => $this->getCategories($documentation, $category->id),
|
||||||
'documentations' => $this->getDocumentations($documentation, $category->id),
|
'documentations' => $this->getDocumentations($documentation, $category->id),
|
||||||
'categoryPath' => $categoryPath,
|
|
||||||
]);
|
]);
|
||||||
return $this->resultSitePage($documentation->getProject(), $documentation->getWebsiteTranslations(), $data, \is_null($category->content?->title));
|
return $this->resultSitePage($documentation->getProject(), $documentation->getWebsiteTranslations(), $data, \is_null($category->content?->title));
|
||||||
}
|
}
|
||||||
@@ -104,14 +99,8 @@ final class DocumentationService extends Service
|
|||||||
return $this->errFobidden(__('Access is denied'));
|
return $this->errFobidden(__('Access is denied'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$categoryPath = null;
|
|
||||||
if ($document->category_id) {
|
|
||||||
$categoryPath = $this->documentationCategoryRepository->getPathFromRoot($document->category_id, $documentation->getWebsiteTranslations()->getLanguage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array_merge($documentation->toArray(), [
|
$data = array_merge($documentation->toArray(), [
|
||||||
'documentation' => $document,
|
'documentation' => $document,
|
||||||
'categoryPath' => $categoryPath,
|
|
||||||
]);
|
]);
|
||||||
return $this->resultSitePage($documentation->getProject(), $documentation->getWebsiteTranslations(), $data, \is_null($document->content?->title));
|
return $this->resultSitePage($documentation->getProject(), $documentation->getWebsiteTranslations(), $data, \is_null($document->content?->title));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ final readonly class ResizeCommandHandler
|
|||||||
{
|
{
|
||||||
public function resize(Storage $storage, int $width, int $height): Storage
|
public function resize(Storage $storage, int $width, int $height): Storage
|
||||||
{
|
{
|
||||||
$image = InterventionImage::decodePath($storage->path);
|
$image = InterventionImage::read($storage->path);
|
||||||
if ($image->width() < $width && $image->height() < $height) {
|
if ($image->width() < $width && $image->height() < $height) {
|
||||||
return $storage;
|
return $storage;
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ final readonly class ResizeCommandHandler
|
|||||||
|
|
||||||
public function width(Storage $storage, int $width): Storage
|
public function width(Storage $storage, int $width): Storage
|
||||||
{
|
{
|
||||||
$image = InterventionImage::decodePath($storage->path);
|
$image = InterventionImage::read($storage->path);
|
||||||
if ($image->width() < $width) {
|
if ($image->width() < $width) {
|
||||||
return $storage;
|
return $storage;
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ final readonly class ResizeCommandHandler
|
|||||||
|
|
||||||
public function height(Storage $storage, int $height): Storage
|
public function height(Storage $storage, int $height): Storage
|
||||||
{
|
{
|
||||||
$image = InterventionImage::decodePath($storage->path);
|
$image = InterventionImage::read($storage->path);
|
||||||
if ($image->height() < $height) {
|
if ($image->height() < $height) {
|
||||||
return $storage;
|
return $storage;
|
||||||
}
|
}
|
||||||
|
|||||||
-89
@@ -1,89 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\Translate\Completed\Project;
|
|
||||||
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\Hashes;
|
|
||||||
use App\Exceptions\Services\Translate\CompletedException;
|
|
||||||
use App\Jobs\Translate\ProcessProjectDocumentationCategoryContent;
|
|
||||||
use App\Models\DocumentationCategory;
|
|
||||||
use App\Models\DocumentationCategoryContent;
|
|
||||||
use App\Repositories\DocumentationCategoryRepository;
|
|
||||||
use App\Services\ProjectTranslationService\NoTranslateAttributeHandler;
|
|
||||||
use App\Services\ProjectTranslationServiceHash\CompletionChecker;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use KorElf\TranslateLaravel\Contracts\TranslationCompletedListener;
|
|
||||||
|
|
||||||
final readonly class DocumentationCategoryContentService implements TranslationCompletedListener
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private DocumentationCategoryRepository $categoryRepository,
|
|
||||||
private NoTranslateAttributeHandler $noTranslateAttributeHandler,
|
|
||||||
private CompletionChecker $completionChecker,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws CompletedException
|
|
||||||
*/
|
|
||||||
public function onTranslationCompleted(array $translatedText, array $data = []): void
|
|
||||||
{
|
|
||||||
if (
|
|
||||||
!isset($data['categoryId'])
|
|
||||||
|| !isset($data['languageId'])
|
|
||||||
|| !isset($data['hashes'])
|
|
||||||
) {
|
|
||||||
throw new CompletedException('Required data is missing: categoryId, languageId, or hashes.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$category = $this->categoryRepository->getCategoryById((int) $data['categoryId']);
|
|
||||||
if ($category === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$categoryContent = DB::transaction(function () use ($data, $category, $translatedText) {
|
|
||||||
$values = [];
|
|
||||||
$hashes = $this->completionChecker->execute(
|
|
||||||
$this->getHashes($data['hashes']),
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($translatedText as $translatedTextKey => $translatedTextValue) {
|
|
||||||
if ($hashes->isStatusWaiting($translatedTextKey) !== true) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$translatedTextValue = $this->noTranslateAttributeHandler->handleRemoveAttribute($translatedTextValue);
|
|
||||||
$values[$translatedTextKey] = $translatedTextValue;
|
|
||||||
}
|
|
||||||
if (\count($values) === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$categoryContent = $category->contents()->where('language_id', $data['languageId'])->first();
|
|
||||||
if ($categoryContent !== null) {
|
|
||||||
$categoryContent->update($values);
|
|
||||||
return $categoryContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
$values['language_id'] = $data['languageId'];
|
|
||||||
return $category->contents()->create($values);
|
|
||||||
});
|
|
||||||
if (\config('translation_service.enable', false) && $categoryContent !== null) {
|
|
||||||
$this->translateContent($category, $categoryContent, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function translateContent(DocumentationCategory $category, DocumentationCategoryContent $categoryContent, array $data): void
|
|
||||||
{
|
|
||||||
$translateExceptLanguages = $data['exceptLanguages'] ?? [];
|
|
||||||
$translateExceptLanguages[] = $data['languageId'];
|
|
||||||
ProcessProjectDocumentationCategoryContent::dispatch($category->id, [$categoryContent->id], $translateExceptLanguages);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getHashes(array $hashes): Hashes
|
|
||||||
{
|
|
||||||
$hashesDto = new Hashes();
|
|
||||||
foreach ($hashes as $field => $hash) {
|
|
||||||
$hashesDto->add((int) $hash['hashId'], $field, $hash['hash']);
|
|
||||||
}
|
|
||||||
return $hashesDto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-90
@@ -1,90 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\Translate\Completed\Project;
|
|
||||||
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\Hashes;
|
|
||||||
use App\Exceptions\Services\Translate\CompletedException;
|
|
||||||
use App\Jobs\Translate\ProcessProjectDocumentationContent;
|
|
||||||
use App\Models\Documentation;
|
|
||||||
use App\Models\DocumentationContent;
|
|
||||||
use App\Repositories\DocumentationRepository;
|
|
||||||
use App\Services\ProjectTranslationService\NoTranslateAttributeHandler;
|
|
||||||
use App\Services\ProjectTranslationServiceHash\CompletionChecker;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use KorElf\TranslateLaravel\Contracts\TranslationCompletedListener;
|
|
||||||
|
|
||||||
final readonly class DocumentationContentService implements TranslationCompletedListener
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private DocumentationRepository $documentationRepository,
|
|
||||||
private NoTranslateAttributeHandler $noTranslateAttributeHandler,
|
|
||||||
private CompletionChecker $completionChecker,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws CompletedException
|
|
||||||
*/
|
|
||||||
public function onTranslationCompleted(array $translatedText, array $data = []): void
|
|
||||||
{
|
|
||||||
if (
|
|
||||||
!isset($data['projectDocumentId'])
|
|
||||||
|| !isset($data['languageId'])
|
|
||||||
|| !isset($data['hashes'])
|
|
||||||
) {
|
|
||||||
throw new CompletedException('Required data is missing: projectDocumentId, languageId, or hashes.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$documentation = $this->documentationRepository->getDocumentationById((int) $data['projectDocumentId']);
|
|
||||||
if ($documentation === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$documentationContent = DB::transaction(function () use ($data, $documentation, $translatedText) {
|
|
||||||
$values = [];
|
|
||||||
$hashes = $this->completionChecker->execute(
|
|
||||||
$this->getHashes($data['hashes']),
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($translatedText as $translatedTextKey => $translatedTextValue) {
|
|
||||||
if ($hashes->isStatusWaiting($translatedTextKey) !== true) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$translatedTextValue = $this->noTranslateAttributeHandler->handleRemoveAttribute($translatedTextValue);
|
|
||||||
$values[$translatedTextKey] = $translatedTextValue;
|
|
||||||
}
|
|
||||||
if (\count($values) === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$documentationContent = $documentation->contents()->where('language_id', $data['languageId'])->first();
|
|
||||||
if ($documentationContent !== null) {
|
|
||||||
$documentationContent->update($values);
|
|
||||||
return $documentationContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
$values['language_id'] = $data['languageId'];
|
|
||||||
return $documentation->contents()->create($values);
|
|
||||||
});
|
|
||||||
if (\config('translation_service.enable', false) && $documentationContent !== null) {
|
|
||||||
$this->translateContent($documentation, $documentationContent, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function translateContent(Documentation $documentation, DocumentationContent $documentationContent, array $data): void
|
|
||||||
{
|
|
||||||
$translateExceptLanguages = $data['exceptLanguages'] ?? [];
|
|
||||||
$translateExceptLanguages[] = $data['languageId'];
|
|
||||||
ProcessProjectDocumentationContent::dispatch($documentation->id, [$documentationContent->id], $translateExceptLanguages);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getHashes(array $hashes): Hashes
|
|
||||||
{
|
|
||||||
$hashesDto = new Hashes();
|
|
||||||
foreach ($hashes as $field => $hash) {
|
|
||||||
$hashesDto->add((int) $hash['hashId'], $field, $hash['hash']);
|
|
||||||
}
|
|
||||||
return $hashesDto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\Translate\Completed\Project;
|
|
||||||
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\Hashes;
|
|
||||||
use App\Exceptions\Services\Translate\CompletedException;
|
|
||||||
use App\Jobs\Translate\ProcessProjectContent;
|
|
||||||
use App\Models\Project;
|
|
||||||
use App\Models\ProjectContent;
|
|
||||||
use App\Repositories\ProjectRepository;
|
|
||||||
use App\Services\ProjectTranslationService\NoTranslateAttributeHandler;
|
|
||||||
use App\Services\ProjectTranslationServiceHash\CompletionChecker;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use KorElf\TranslateLaravel\Contracts\TranslationCompletedListener;
|
|
||||||
|
|
||||||
final readonly class ProjectContentService implements TranslationCompletedListener
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private ProjectRepository $projectRepository,
|
|
||||||
private NoTranslateAttributeHandler $noTranslateAttributeHandler,
|
|
||||||
private CompletionChecker $completionChecker,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws CompletedException
|
|
||||||
*/
|
|
||||||
public function onTranslationCompleted(array $translatedText, array $data = []): void
|
|
||||||
{
|
|
||||||
if (
|
|
||||||
!isset($data['projectId'])
|
|
||||||
|| !isset($data['languageId'])
|
|
||||||
|| !isset($data['hashes'])
|
|
||||||
) {
|
|
||||||
throw new CompletedException('Required data is missing: projectId, languageId, or hashes.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$project = $this->projectRepository->getProjectById((int) $data['projectId']);
|
|
||||||
if ($project === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$projectContent = DB::transaction(function () use ($data, $project, $translatedText) {
|
|
||||||
$values = [];
|
|
||||||
$hashes = $this->completionChecker->execute(
|
|
||||||
$this->getHashes($data['hashes']),
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($translatedText as $translatedTextKey => $translatedTextValue) {
|
|
||||||
if ($hashes->isStatusWaiting($translatedTextKey) !== true) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$translatedTextValue = $this->noTranslateAttributeHandler->handleRemoveAttribute($translatedTextValue);
|
|
||||||
$values[$translatedTextKey] = $translatedTextValue;
|
|
||||||
}
|
|
||||||
if (\count($values) === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$projectContent = $project->contents()->where('language_id', $data['languageId'])->first();
|
|
||||||
if ($projectContent !== null) {
|
|
||||||
$projectContent->update($values);
|
|
||||||
return $projectContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
$values['language_id'] = $data['languageId'];
|
|
||||||
return $project->contents()->create($values);
|
|
||||||
});
|
|
||||||
if (\config('translation_service.enable', false) && $projectContent !== null) {
|
|
||||||
$this->translateContent($project, $projectContent, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function translateContent(Project $project, ProjectContent $projectContent, array $data): void
|
|
||||||
{
|
|
||||||
$translateExceptLanguages = $data['exceptLanguages'] ?? [];
|
|
||||||
$translateExceptLanguages[] = $data['languageId'];
|
|
||||||
ProcessProjectContent::dispatch($project->id, [$projectContent->id], $translateExceptLanguages);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getHashes(array $hashes): Hashes
|
|
||||||
{
|
|
||||||
$hashesDto = new Hashes();
|
|
||||||
foreach ($hashes as $field => $hash) {
|
|
||||||
$hashesDto->add((int) $hash['hashId'], $field, $hash['hash']);
|
|
||||||
}
|
|
||||||
return $hashesDto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\Translate\Completed\Project;
|
|
||||||
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceTextHash\Hashes;
|
|
||||||
use App\Exceptions\Services\Translate\CompletedException;
|
|
||||||
use App\Jobs\Translate\ProcessTranslationText;
|
|
||||||
use App\Models\Project;
|
|
||||||
use App\Models\ProjectTranslation;
|
|
||||||
use App\Repositories\ProjectRepository;
|
|
||||||
use App\Repositories\ProjectTranslationRepository;
|
|
||||||
use App\Services\ProjectTranslationServiceTextHash\CompletionChecker;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use KorElf\TranslateLaravel\Contracts\TranslationCompletedListener;
|
|
||||||
|
|
||||||
final readonly class TranslationTextService implements TranslationCompletedListener
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private ProjectRepository $projectRepository,
|
|
||||||
private CompletionChecker $completionChecker,
|
|
||||||
private ProjectTranslationRepository $projectTranslationRepository,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws CompletedException
|
|
||||||
*/
|
|
||||||
public function onTranslationCompleted(array $translatedText, array $data = []): void
|
|
||||||
{
|
|
||||||
if (
|
|
||||||
!isset($data['projectId'])
|
|
||||||
|| !isset($data['languageId'])
|
|
||||||
|| !isset($data['hashes'])
|
|
||||||
) {
|
|
||||||
throw new CompletedException('Required data is missing: projectId, languageId, or hashes.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$project = $this->projectRepository->getProjectById((int) $data['projectId']);
|
|
||||||
if ($project === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$translations = $this->projectTranslationRepository->getProjectTranslationByCodes($project->id, $data['languageId'], \array_keys($translatedText))->all();
|
|
||||||
|
|
||||||
$translateTextCode = DB::transaction(function () use ($data, $translatedText, $translations) {
|
|
||||||
$translateTextCode = [];
|
|
||||||
$hashes = $this->completionChecker->execute(
|
|
||||||
$this->getHashes($data['hashes']),
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($translatedText as $translatedTextKey => $translatedTextValue) {
|
|
||||||
if ($hashes->isStatusWaiting($translatedTextKey) !== true) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$translateTextCode[] = $translatedTextKey;
|
|
||||||
$translation = $translations->firstWhere('code', $translatedTextKey);
|
|
||||||
if ($translation !== null) {
|
|
||||||
$translation->update([
|
|
||||||
'text' => $translatedTextValue,
|
|
||||||
]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProjectTranslation::create([
|
|
||||||
'project_id' => (int) $data['projectId'],
|
|
||||||
'language_id' => (int) $data['languageId'],
|
|
||||||
'code' => $translatedTextKey,
|
|
||||||
'text' => $translatedTextValue,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $translateTextCode;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (\config('translation_service.enable', false) && !empty($translateTextCode)) {
|
|
||||||
$this->translateContent($project, $translateTextCode, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function translateContent(Project $project, array $translateTextCode, array $data): void
|
|
||||||
{
|
|
||||||
$translateExceptLanguages = $data['exceptLanguages'] ?? [];
|
|
||||||
$translateExceptLanguages[] = $data['languageId'];
|
|
||||||
ProcessTranslationText::dispatch($project->id, $data['languageId'], $translateTextCode, $translateExceptLanguages);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getHashes(array $hashes): Hashes
|
|
||||||
{
|
|
||||||
$hashesDto = new Hashes();
|
|
||||||
foreach ($hashes as $code => $hash) {
|
|
||||||
$hashesDto->add((int) $hash['hashId'], $code, $hash['hash']);
|
|
||||||
}
|
|
||||||
return $hashesDto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-94
@@ -1,94 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\Translate\Project;
|
|
||||||
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\Fields;
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\TranslateFields;
|
|
||||||
use App\Enums\Morph;
|
|
||||||
use App\Repositories\DocumentationCategoryRepository;
|
|
||||||
use App\Repositories\ProjectTranslationServiceRepository;
|
|
||||||
use App\ServiceResults\ServiceResultError;
|
|
||||||
use App\ServiceResults\ServiceResultSuccess;
|
|
||||||
use App\Services\ProjectTranslationService\NoTranslateAttributeHandler;
|
|
||||||
use App\Services\ProjectTranslationServiceHash\HashTrackerCommand;
|
|
||||||
use App\Services\Translate\Completed\Project\DocumentationCategoryContentService as DocumentationCategoryContentServiceCompleted;
|
|
||||||
use App\Services\Service;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use KorElf\TranslateLaravel\DTO\AfterTranslateDto;
|
|
||||||
use KorElf\TranslateLaravel\Facades\Translate;
|
|
||||||
|
|
||||||
final class DocumentationCategoryContentService extends Service
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly DocumentationCategoryRepository $documentationCategoryRepository,
|
|
||||||
private readonly ProjectTranslationServiceRepository $projectTranslationServiceRepository,
|
|
||||||
private readonly HashTrackerCommand $hashTrackerCommand,
|
|
||||||
private readonly NoTranslateAttributeHandler $noTranslateAttributeHandler,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function translate(int $categoryId, array $contentIds, array $exceptLanguages): ServiceResultSuccess | ServiceResultError
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$category = $this->documentationCategoryRepository->getCategoryById($categoryId);
|
|
||||||
if ($category === null) {
|
|
||||||
return $this->errNotFound(__('Category not found'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$contents = $category->contents()
|
|
||||||
->whereIn('id', $contentIds)
|
|
||||||
->cursor();
|
|
||||||
|
|
||||||
$sourceLanguagesCode = [];
|
|
||||||
foreach ($contents as $content) {
|
|
||||||
if (!isset($sourceLanguagesCode[$content->language_id])) {
|
|
||||||
$sourceLanguagesCode[$content->language_id] = $this->projectTranslationServiceRepository->getLanguageCodeByLanguageId($content->language_id) ?? 'null';
|
|
||||||
}
|
|
||||||
$translateIntoLanguage = $this->projectTranslationServiceRepository
|
|
||||||
->getLanguagesBySourceLanguage($content->language_id, $exceptLanguages)
|
|
||||||
->all()->pluck('code', 'language_id')->toArray();
|
|
||||||
|
|
||||||
if (empty($translateIntoLanguage)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fields = (new Fields())
|
|
||||||
->add('title', $content->title ?? '');
|
|
||||||
$translations = DB::transaction(function () use ($content, $translateIntoLanguage, $fields) {
|
|
||||||
return $this->hashTrackerCommand->execute(Morph::DocumentationCategoryContent, $content->id, \array_keys($translateIntoLanguage), $fields);
|
|
||||||
});
|
|
||||||
/** @var TranslateFields $translations */
|
|
||||||
unset($fields);
|
|
||||||
|
|
||||||
foreach ($translations->getFields() as $languageId => $fields) {
|
|
||||||
$params = new \KorElf\TranslateLaravel\DTO\RunTranslateDto();
|
|
||||||
$sourceLanguageCode = null;
|
|
||||||
if (isset($sourceLanguagesCode[$content->language_id]) && $sourceLanguagesCode[$content->language_id] !== 'null') {
|
|
||||||
$sourceLanguageCode = $sourceLanguagesCode[$content->language_id];
|
|
||||||
}
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
$text = $this->noTranslateAttributeHandler->handleAddAttribute((string) $content->{$field} ?? '');
|
|
||||||
$params->addParamHtml($field, $text, $translateIntoLanguage[$languageId], $sourceLanguageCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
$afterTranslateDto = new AfterTranslateDto(DocumentationCategoryContentServiceCompleted::class, [
|
|
||||||
'categoryId' => $categoryId,
|
|
||||||
'languageId' => $languageId,
|
|
||||||
'hashes' => $translations->getHashesByLanguage($languageId),
|
|
||||||
'exceptLanguages' => $exceptLanguages,
|
|
||||||
]);
|
|
||||||
Translate::runJob($params, $afterTranslateDto);
|
|
||||||
unset($params, $afterTranslateDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($translations, $translateIntoLanguage);
|
|
||||||
}
|
|
||||||
unset($contents, $documentation);
|
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
\report($e);
|
|
||||||
return $this->errService($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\Translate\Project;
|
|
||||||
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\Fields;
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\TranslateFields;
|
|
||||||
use App\Enums\Morph;
|
|
||||||
use App\Repositories\DocumentationRepository;
|
|
||||||
use App\Repositories\ProjectTranslationServiceRepository;
|
|
||||||
use App\ServiceResults\ServiceResultError;
|
|
||||||
use App\ServiceResults\ServiceResultSuccess;
|
|
||||||
use App\Services\ProjectTranslationService\NoTranslateAttributeHandler;
|
|
||||||
use App\Services\ProjectTranslationServiceHash\HashTrackerCommand;
|
|
||||||
use App\Services\Service;
|
|
||||||
use App\Services\Translate\Completed\Project\DocumentationContentService as DocumentationContentServiceCompleted;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use KorElf\TranslateLaravel\DTO\AfterTranslateDto;
|
|
||||||
use KorElf\TranslateLaravel\Facades\Translate;
|
|
||||||
|
|
||||||
final class DocumentationContentService extends Service
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly DocumentationRepository $documentationRepository,
|
|
||||||
private readonly ProjectTranslationServiceRepository $projectTranslationServiceRepository,
|
|
||||||
private readonly HashTrackerCommand $hashTrackerCommand,
|
|
||||||
private readonly NoTranslateAttributeHandler $noTranslateAttributeHandler,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function translate(int $projectDocumentId, array $contentIds, array $exceptLanguages): ServiceResultSuccess | ServiceResultError
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$documentation = $this->documentationRepository->getDocumentationById($projectDocumentId);
|
|
||||||
if ($documentation === null) {
|
|
||||||
return $this->errNotFound(__('Documentation not found'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$contents = $documentation->contents()
|
|
||||||
->whereIn('id', $contentIds)
|
|
||||||
->cursor();
|
|
||||||
|
|
||||||
$sourceLanguagesCode = [];
|
|
||||||
foreach ($contents as $content) {
|
|
||||||
if (!isset($sourceLanguagesCode[$content->language_id])) {
|
|
||||||
$sourceLanguagesCode[$content->language_id] = $this->projectTranslationServiceRepository->getLanguageCodeByLanguageId($content->language_id) ?? 'null';
|
|
||||||
}
|
|
||||||
$translateIntoLanguage = $this->projectTranslationServiceRepository
|
|
||||||
->getLanguagesBySourceLanguage($content->language_id, $exceptLanguages)
|
|
||||||
->all()->pluck('code', 'language_id')->toArray();
|
|
||||||
|
|
||||||
if (empty($translateIntoLanguage)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fields = (new Fields())
|
|
||||||
->add('title', $content->title ?? '')
|
|
||||||
->add('content', $content->content ?? '');
|
|
||||||
$translations = DB::transaction(function () use ($content, $translateIntoLanguage, $fields) {
|
|
||||||
return $this->hashTrackerCommand->execute(Morph::DocumentationContent, $content->id, \array_keys($translateIntoLanguage), $fields);
|
|
||||||
});
|
|
||||||
/** @var TranslateFields $translations */
|
|
||||||
unset($fields);
|
|
||||||
|
|
||||||
foreach ($translations->getFields() as $languageId => $fields) {
|
|
||||||
$params = new \KorElf\TranslateLaravel\DTO\RunTranslateDto();
|
|
||||||
$sourceLanguageCode = null;
|
|
||||||
if (isset($sourceLanguagesCode[$content->language_id]) && $sourceLanguagesCode[$content->language_id] !== 'null') {
|
|
||||||
$sourceLanguageCode = $sourceLanguagesCode[$content->language_id];
|
|
||||||
}
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
$text = $this->noTranslateAttributeHandler->handleAddAttribute((string) $content->{$field} ?? '');
|
|
||||||
$params->addParamHtml($field, $text, $translateIntoLanguage[$languageId], $sourceLanguageCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
$afterTranslateDto = new AfterTranslateDto(DocumentationContentServiceCompleted::class, [
|
|
||||||
'projectDocumentId' => $projectDocumentId,
|
|
||||||
'languageId' => $languageId,
|
|
||||||
'hashes' => $translations->getHashesByLanguage($languageId),
|
|
||||||
'exceptLanguages' => $exceptLanguages,
|
|
||||||
]);
|
|
||||||
Translate::runJob($params, $afterTranslateDto);
|
|
||||||
unset($params, $afterTranslateDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($translations, $translateIntoLanguage);
|
|
||||||
}
|
|
||||||
unset($contents, $documentation);
|
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
\report($e);
|
|
||||||
return $this->errService($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\Translate\Project;
|
|
||||||
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\Fields;
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceHash\TranslateFields;
|
|
||||||
use App\Enums\Morph;
|
|
||||||
use App\Repositories\ProjectRepository;
|
|
||||||
use App\Repositories\ProjectTranslationServiceRepository;
|
|
||||||
use App\ServiceResults\ServiceResultError;
|
|
||||||
use App\ServiceResults\ServiceResultSuccess;
|
|
||||||
use App\Services\ProjectTranslationService\NoTranslateAttributeHandler;
|
|
||||||
use App\Services\ProjectTranslationServiceHash\HashTrackerCommand;
|
|
||||||
use App\Services\Service;
|
|
||||||
use App\Services\Translate\Completed\Project\ProjectContentService as ProjectContentServiceCompleted;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use KorElf\TranslateLaravel\DTO\AfterTranslateDto;
|
|
||||||
use KorElf\TranslateLaravel\Facades\Translate;
|
|
||||||
|
|
||||||
final class ProjectContentService extends Service
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly ProjectRepository $projectRepository,
|
|
||||||
private readonly ProjectTranslationServiceRepository $projectTranslationServiceRepository,
|
|
||||||
private readonly HashTrackerCommand $hashTrackerCommand,
|
|
||||||
private readonly NoTranslateAttributeHandler $noTranslateAttributeHandler,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function translate(int $projectId, array $contentIds, array $exceptLanguages): ServiceResultSuccess | ServiceResultError
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$project = $this->projectRepository->getProjectById($projectId);
|
|
||||||
if ($project === null) {
|
|
||||||
return $this->errNotFound(__('Project not found'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$contents = $project->contents()
|
|
||||||
->whereIn('id', $contentIds)
|
|
||||||
->cursor();
|
|
||||||
|
|
||||||
$sourceLanguagesCode = [];
|
|
||||||
foreach ($contents as $content) {
|
|
||||||
if (!isset($sourceLanguagesCode[$content->language_id])) {
|
|
||||||
$sourceLanguagesCode[$content->language_id] = $this->projectTranslationServiceRepository->getLanguageCodeByLanguageId($content->language_id) ?? 'null';
|
|
||||||
}
|
|
||||||
$translateIntoLanguage = $this->projectTranslationServiceRepository
|
|
||||||
->getLanguagesBySourceLanguage($content->language_id, $exceptLanguages)
|
|
||||||
->all()->pluck('code', 'language_id')->toArray();
|
|
||||||
|
|
||||||
if (empty($translateIntoLanguage)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fields = (new Fields())
|
|
||||||
->add('title', $content->title ?? '')
|
|
||||||
->add('description', $content->description ?? '');
|
|
||||||
$translations = DB::transaction(function () use ($content, $translateIntoLanguage, $fields) {
|
|
||||||
return $this->hashTrackerCommand->execute(Morph::ProjectContent, $content->id, \array_keys($translateIntoLanguage), $fields);
|
|
||||||
});
|
|
||||||
/** @var TranslateFields $translations */
|
|
||||||
unset($fields);
|
|
||||||
|
|
||||||
foreach ($translations->getFields() as $languageId => $fields) {
|
|
||||||
$params = new \KorElf\TranslateLaravel\DTO\RunTranslateDto();
|
|
||||||
$sourceLanguageCode = null;
|
|
||||||
if (isset($sourceLanguagesCode[$content->language_id]) && $sourceLanguagesCode[$content->language_id] !== 'null') {
|
|
||||||
$sourceLanguageCode = $sourceLanguagesCode[$content->language_id];
|
|
||||||
}
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
$text = $this->noTranslateAttributeHandler->handleAddAttribute((string) $content->{$field} ?? '');
|
|
||||||
$params->addParamHtml($field, $text, $translateIntoLanguage[$languageId], $sourceLanguageCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
$afterTranslateDto = new AfterTranslateDto(ProjectContentServiceCompleted::class, [
|
|
||||||
'projectId' => $projectId,
|
|
||||||
'languageId' => $languageId,
|
|
||||||
'hashes' => $translations->getHashesByLanguage($languageId),
|
|
||||||
'exceptLanguages' => $exceptLanguages,
|
|
||||||
]);
|
|
||||||
Translate::runJob($params, $afterTranslateDto);
|
|
||||||
unset($params, $afterTranslateDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($translations, $translateIntoLanguage);
|
|
||||||
}
|
|
||||||
unset($contents, $documentation);
|
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
\report($e);
|
|
||||||
return $this->errService($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Services\Translate\Project;
|
|
||||||
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceTextHash\Codes;
|
|
||||||
use App\Dto\Service\ProjectTranslationServiceTextHash\TranslateCodes;
|
|
||||||
use App\Repositories\ProjectRepository;
|
|
||||||
use App\Repositories\ProjectTranslationServiceRepository;
|
|
||||||
use App\ServiceResults\ServiceResultError;
|
|
||||||
use App\ServiceResults\ServiceResultSuccess;
|
|
||||||
use App\Services\ProjectTranslation\TranslationText;
|
|
||||||
use App\Services\ProjectTranslation\TranslationTextCommand;
|
|
||||||
use App\Services\ProjectTranslationServiceTextHash\HashTrackerCommand;
|
|
||||||
use App\Services\Translate\Completed\Project\TranslationTextService as TranslationTextServiceCompleted;
|
|
||||||
use App\Services\Service;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use KorElf\TranslateLaravel\DTO\AfterTranslateDto;
|
|
||||||
use KorElf\TranslateLaravel\Facades\Translate;
|
|
||||||
|
|
||||||
final class TranslationTextService extends Service
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly ProjectRepository $projectRepository,
|
|
||||||
private readonly TranslationTextCommand $translationTextCommand,
|
|
||||||
private readonly ProjectTranslationServiceRepository $projectTranslationServiceRepository,
|
|
||||||
private readonly HashTrackerCommand $hashTrackerCommand,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public function translate(int $projectId, int $languageId, array $translateTextCode, array $exceptLanguages): ServiceResultSuccess | ServiceResultError
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$project = $this->projectRepository->getProjectById($projectId);
|
|
||||||
if ($project === null) {
|
|
||||||
return $this->errNotFound(__('Project not found'));
|
|
||||||
}
|
|
||||||
$language = $project->languages()->firstWhere('id', $languageId);
|
|
||||||
if ($language === null) {
|
|
||||||
return $this->errNotFound(__('Language not found'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$translateIntoLanguage = $this->projectTranslationServiceRepository
|
|
||||||
->getLanguagesBySourceLanguage($languageId, $exceptLanguages)
|
|
||||||
->all()->pluck('code', 'language_id')->toArray();
|
|
||||||
|
|
||||||
if (empty($translateIntoLanguage)) {
|
|
||||||
return $this->ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
$translationText = $this->translationTextCommand->execute($project, $language, $translateTextCode);
|
|
||||||
$codes = $this->getCodes($translationText, $translateTextCode);
|
|
||||||
$translations = DB::transaction(function () use ($translateIntoLanguage, $codes) {
|
|
||||||
return $this->hashTrackerCommand->execute(\array_keys($translateIntoLanguage), $codes);
|
|
||||||
});
|
|
||||||
/** @var TranslateCodes $translations */
|
|
||||||
unset($codes);
|
|
||||||
|
|
||||||
$sourceLanguageCode = $this->projectTranslationServiceRepository->getLanguageCodeByLanguageId($language->id);
|
|
||||||
foreach ($translations->getCodes() as $currentLanguageId => $codes) {
|
|
||||||
$params = new \KorElf\TranslateLaravel\DTO\RunTranslateDto();
|
|
||||||
foreach ($codes as $code) {
|
|
||||||
$text = $translationText->translate($code);
|
|
||||||
$params->addParamHtml($code, $text, $translateIntoLanguage[$currentLanguageId], $sourceLanguageCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
$afterTranslateDto = new AfterTranslateDto(TranslationTextServiceCompleted::class, [
|
|
||||||
'projectId' => $projectId,
|
|
||||||
'languageId' => $currentLanguageId,
|
|
||||||
'hashes' => $translations->getHashesByLanguage($currentLanguageId),
|
|
||||||
'exceptLanguages' => $exceptLanguages,
|
|
||||||
]);
|
|
||||||
Translate::runJob($params, $afterTranslateDto);
|
|
||||||
unset($params, $afterTranslateDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($translations, $translateIntoLanguage, $project, $language, $translationText, $sourceLanguageCode);
|
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
\report($e);
|
|
||||||
return $this->errService($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getCodes(TranslationText $translationText, array $translateTextCode): Codes
|
|
||||||
{
|
|
||||||
$codes = new Codes();
|
|
||||||
foreach ($translateTextCode as $code) {
|
|
||||||
$codes->add($code, $translationText->translate($code));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $codes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace app\View\Components\Site;
|
namespace app\View\Components\Site;
|
||||||
|
|
||||||
|
use App\Enums\CacheTag;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Services\WebsiteTranslations;
|
use App\Services\WebsiteTranslations;
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\View\Component;
|
use Illuminate\View\Component;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
@@ -24,7 +24,7 @@ final class ChooseLanguage extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
$seconds = 3600 * 12;
|
$seconds = 3600 * 12;
|
||||||
$languages = Cache::remember(self::class . $this->project->id, $seconds, function () {
|
$languages = CacheTag::Project->getCache()->remember(self::class . $this->project->id, $seconds, function () {
|
||||||
return $this->project->languages;
|
return $this->project->languages;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
namespace App\View\Components\Site;
|
namespace App\View\Components\Site;
|
||||||
|
|
||||||
|
use App\Enums\CacheTag;
|
||||||
use App\Models\DocumentationVersion;
|
use App\Models\DocumentationVersion;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Services\WebsiteTranslations;
|
use App\Services\WebsiteTranslations;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\View\Component;
|
use Illuminate\View\Component;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
|
|
||||||
@@ -28,7 +29,8 @@ final class ChooseVersion extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
$seconds = 3600 * 12;
|
$seconds = 3600 * 12;
|
||||||
$versions = Cache::remember(self::class . $this->project->id . '-' . $isPublic ?? 0, $seconds, function () use ($isPublic) {
|
$versions = CacheTag::DocumantationVersion->getCache()
|
||||||
|
->remember(self::class . $this->project->id . '-' . $isPublic ?? 0, $seconds, function () use ($isPublic) {
|
||||||
return $this->project->documentationVersions()
|
return $this->project->documentationVersions()
|
||||||
->when($isPublic, function (Builder $query) {
|
->when($isPublic, function (Builder $query) {
|
||||||
$query->where('is_public', 1);
|
$query->where('is_public', 1);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use Illuminate\Foundation\Application;
|
|||||||
use Illuminate\Foundation\Configuration\Exceptions;
|
use Illuminate\Foundation\Configuration\Exceptions;
|
||||||
use Illuminate\Foundation\Configuration\Middleware;
|
use Illuminate\Foundation\Configuration\Middleware;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
|
|
||||||
return Application::configure(basePath: dirname(__DIR__))
|
return Application::configure(basePath: dirname(__DIR__))
|
||||||
->withRouting(
|
->withRouting(
|
||||||
@@ -20,15 +19,8 @@ return Application::configure(basePath: dirname(__DIR__))
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
->withMiddleware(function (Middleware $middleware) {
|
->withMiddleware(function (Middleware $middleware) {
|
||||||
|
//
|
||||||
})
|
})
|
||||||
->withExceptions(function (Exceptions $exceptions) {
|
->withExceptions(function (Exceptions $exceptions) {
|
||||||
$exceptions->respond(function (Response $response) {
|
//
|
||||||
if ($response->getStatusCode() === 419) {
|
|
||||||
return back()
|
|
||||||
->withInput()
|
|
||||||
->withErrors(['csrf' => __('http-statuses.csrfError')]);
|
|
||||||
}
|
|
||||||
return $response;
|
|
||||||
});
|
|
||||||
})->create();
|
})->create();
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user