Skip to content

Commit

Permalink
Merge branch 'master' into PHRAS-3945-mv-config-pusher
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaillat authored Nov 17, 2023
2 parents 89c447f + a29aa33 commit 9a8beea
Show file tree
Hide file tree
Showing 18 changed files with 1,571 additions and 1,275 deletions.
8 changes: 4 additions & 4 deletions lib/Alchemy/Phrasea/Command/Maintenance/CleanUsersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output)
return 1;
}

$clauses[] = sprintf("`last_connection` < DATE_SUB(NOW(), INTERVAL %d day)", $inactivityPeriod);
$clauses[] = sprintf("((`last_connection` IS NULL AND `Users`.`created` < DATE_SUB(NOW(), INTERVAL %d day)) OR (`last_connection` < DATE_SUB(NOW(), INTERVAL %d day)))", $inactivityPeriod, $inactivityPeriod);

$sql_where_u = 1;
$sql_where_ub = 1;
Expand Down Expand Up @@ -249,7 +249,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output)
$usersList[] = [
$user->getId(),
$user->getLogin(),
$user->getLastConnection()->format('Y-m-d h:m:s'),
($user->getLastConnection() == null) ? 'never connected' : $user->getLastConnection()->format('Y-m-d h:m:s'),
$action
];
}
Expand Down Expand Up @@ -280,7 +280,7 @@ private function relanceUser(User $user, $graceDuration)

$mail->setLogin($user->getLogin());
$mail->setLocale($user->getLocale());
$mail->setLastConnection($user->getLastConnection()->format('Y-m-d'));
$mail->setLastConnection(($user->getLastConnection() == null) ? 'never connected': $user->getLastConnection()->format('Y-m-d'));
$mail->setDeleteDate((new \DateTime("+{$graceDuration} day"))->format('Y-m-d'));

// return 0 on failure
Expand All @@ -296,7 +296,7 @@ private function doDelete(User $user, UserManipulator $userManipulator, $validMa
if ($validMail && !empty($maxRelances)) {
$receiver = Receiver::fromUser($user);
$mail = MailSuccessAccountInactifDelete::create($this->container, $receiver);
$mail->setLastConnection($user->getLastConnection()->format('Y-m-d'));
$mail->setLastConnection(($user->getLastConnection() == null) ? 'never connected' : $user->getLastConnection()->format('Y-m-d'));

// if --max_relances=0 there is no inactivity email
if ($user->getLastInactivityEmail() !== null) {
Expand Down
8 changes: 6 additions & 2 deletions lib/Alchemy/Phrasea/Controller/Api/V1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1665,10 +1665,12 @@ private function listRecord(Request $request, record_adapter $record)
$technicalInformation[] = ['name' => $name, 'value' => $value];
}

$resourceId = $this->getResourceIdResolver()($record);

$data = [
'databox_id' => $record->getDataboxId(),
'record_id' => $record->getRecordId(),
'resource_id' => ($this->getResourceIdResolver())($record),
'resource_id' => $resourceId,
'mime_type' => $record->getMimeType(),
'title' => $record->get_title(['encode'=> record_adapter::ENCODE_NONE]),
'original_name' => $record->get_original_name(),
Expand Down Expand Up @@ -1722,11 +1724,13 @@ private function listStory(Request $request, record_adapter $story)
return $field->get_serialized_values();
};

$resourceId = $this->getResourceIdResolver()($story);

return [
'@entity@' => self::OBJECT_TYPE_STORY,
'databox_id' => $story->getDataboxId(),
'story_id' => $story->getRecordId(),
'resource_id' => ($this->getResourceIdResolver())($story),
'resource_id' => $resourceId,
'cover_record_id' => $story->getCoverRecordId(),
'updated_on' => $story->getUpdated()->format(DATE_ATOM),
'created_on' => $story->getCreated()->format(DATE_ATOM),
Expand Down
4 changes: 3 additions & 1 deletion lib/Alchemy/Phrasea/Controller/Api/V3/V3ResultHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ public function listRecord(Request $request, record_adapter $record, ACL $aclfor
$technicalInformation[] = ['name' => $name, 'value' => $value];
}

$resourceId = $this->getResourceIdResolver()($record);

$data = [
'databox_id' => $record->getDataboxId(),
'record_id' => $record->getRecordId(),
'resource_id' => ($this->getResourceIdResolver())($record),
'resource_id' => $resourceId,
'mime_type' => $record->getMimeType(),
'title' => $record->get_title(['encode'=> record_adapter::ENCODE_NONE]),
'original_name' => $record->get_original_name(),
Expand Down
55 changes: 41 additions & 14 deletions lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,25 +552,13 @@ public function autoSubtitleAction(Request $request)
(int)$request->request->get("record_id")
);

$permalinkUrl = '';
$conf = $this->getConf();

// if subdef_source not set, by default use the preview permalink
$subdefSource = $conf->get(['externalservice', 'ginger', 'AutoSubtitling', 'subdef_source']) ?: 'preview';

if ($this->isPhysicallyPresent($record, $subdefSource) && ($previewLink = $record->get_subdef($subdefSource)->get_permalink()) != null) {
$permalinkUrl = $previewLink->get_url()->__toString();
}

$this->dispatch(
PhraseaEvents::RECORD_AUTO_SUBTITLE,
new RecordAutoSubtitleEvent(
$record,
$permalinkUrl,
$request->request->get("subtitle_language_source"),
$request->request->get("meta_struct_id_source"),
$request->request->get("subtitle_language_destination"),
$request->request->get("meta_struct_id_destination")
json_decode($request->request->get("subtitle_destination"), true)
)
);

Expand Down Expand Up @@ -629,7 +617,8 @@ public function videoEditorAction(Request $request)
'videoEditorConfig' => $conf->get(['video-editor']),
'metadatas' => $metadatas,
'JSonFields' => json_encode($JSFields),
'videoTextTrackFields' => $videoTextTrackFields
'videoTextTrackFields' => $videoTextTrackFields,
'languages' => $this->languageList()
]);
}

Expand All @@ -644,4 +633,42 @@ private function isPhysicallyPresent(record_adapter $record, $subdefName)

return false;
}

private function languageList()
{
return [
'af-ZA' => 'af-ZA Afrikaans (South Africa)', 'am-ET' => 'am-ET Amharic (Ethiopia)',
'ar-DZ' => 'ar-DZ Arabic (Algeria)', 'ar-BH' => 'ar-BH Arabic (Bahrain)',
'ar-EG' => 'ar-EG Arabic (Egypt)', 'ar-IQ' => 'ar-IQ Arabic (Iraq)',
'ar-IL' => 'ar-IL Arabic (Israel)', 'ar-YE' => 'ar-YE Arabic (Yemen)',
'eu-ES' => 'eu-ES Basque (Spain)', 'bn-BD' => 'bn-BD Bengali (Bangladesh)',
'bn-IN' => 'bn-IN Bengali (India)', 'bg-BG' => 'bg-BG Bulgarian (Bulgaria)',
'ca-ES' => 'ca-ES Catalan (Spain)', 'yue-Hant-HK' => 'yue-Hant-HK Chinese, Cantonese (Traditional, Hong Kong)',
'cmn-Hans-CN' => 'cmn-Hans-CN Chinese, Mandarin (Simplified, China)', 'hr-HR' => 'hr-HR Croatian (Croatia)',
'cs-CZ' => 'cs-CZ Czech (Czech Republic)', 'da-DK' => 'da-DK Danish (Denmark)',
'nl-NL' => 'nl-NL Dutch (Netherlands)', 'nl-BE' => 'nl-BE Dutch (Belgium)',
'en-AU' => 'en-AU English (Australia)', 'en-CA' => 'en-CA English (Canada)',
'en-GB' => 'en-GB English (United Kingdom)', 'en-US' => 'en-US English (United States)',
'fr-CA' => 'fr-CA French (Canada)', 'fr-FR' => 'fr-FR French (France)',
'fr-BE' => 'fr-BE French (Belgium)', 'fr-CH' => 'fr-CH French (Switzerland)',
'ka-GE' => 'ka-GE Georgian (Georgia)', 'de-DE' => 'de-DE German (Germany)',
'el-GR' => 'el-GR Greek (Greece)', 'he-IL' => 'he-IL Hebrew (Israel)',
'hi-IN' => 'hi-IN Hindi (India)', 'hu-HU' => 'hu-HU Hungarian (Hungary)',
'is-IS' => 'is-IS Icelandic (Iceland)', 'id-ID' => 'id-ID Indonesian (Indonesia)',
'it-IT' => 'it-IT Italian (Italy)', 'ja-JP' => 'ja-JP Japanese (Japan)',
'ko-KR' => 'ko-KR Korean (South Korea)', 'lo-LA' => 'lo-LA Lao (Laos)',
'lt-LT' => 'lt-LT Lithuanian (Lithuania)', 'ms-MY' => 'ms-MY Malay (Malaysia)',
'ne-NP' => 'ne-NP Nepali (Nepal)', 'nb-NO' => 'nb-NO Norwegian Bokmål (Norway)',
'pl-PL' => 'pl-PL Polish (Poland)', 'pt-BR' => 'pt-BR Portuguese (Brazil)',
'pt-PT' => 'pt-PT Portuguese (Portugal)', 'ro-RO' => 'ro-RO Romanian (Romania)',
'ru-RU' => 'ru-RU Russian (Russia)', 'sr-RS' => 'sr-RS Serbian (Serbia)',
'sk-SK' => 'sk-SK Slovak (Slovakia)', 'sl-SI' => 'sl-SI Slovenian (Slovenia)',
'es-ES' => 'es-ES Spanish (Spain)', 'sv-SE' => 'sv-SE Swedish (Sweden)',
'th-TH' => 'th-TH Thai (Thailand)', 'tr-TR' => 'tr-TR Turkish (Turkey)',
'uk-UA' => 'uk-UA Ukrainian (Ukraine)', 'vi-VN' => 'vi-VN Vietnamese (Vietnam)',
'et-EE' => 'et-EE Estonian (Estonia)', 'mn-MN' => 'mn-MN Mongolian (Mongolia)',
'uz-UZ' => 'uz-UZ Uzbek (Uzbekistan)'

];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,24 @@ class RecordAutoSubtitleEvent extends RecordEvent
private $metaStructureIdSource;
private $languageDestination;
private $metaStructureIdDestination;
private $permalinkUrl;

public function __construct(
RecordInterface $record,
$permalinkUrl,
$languageSource,
$metaStructureIdSource,
$languageDestination,
$metaStructureIdDestination
$languageDestination
)
{
parent::__construct($record);

$this->languageSource = $languageSource;
$this->metaStructureIdSource = $metaStructureIdSource;
$this->languageDestination = $languageDestination;
$this->metaStructureIdDestination = $metaStructureIdDestination;
$this->permalinkUrl = $permalinkUrl;
}

public function getLanguageSource()
{
return $this->languageSource;
}

public function getMetaStructureIdSource()
{
return $this->metaStructureIdSource;
}

public function getLanguageDestination()
{
return $this->languageDestination;
Expand All @@ -49,9 +37,4 @@ public function getMetaStructureIdDestination()
{
return $this->metaStructureIdDestination;
}

public function getPermalinkUrl()
{
return $this->permalinkUrl;
}
}
5 changes: 4 additions & 1 deletion lib/Alchemy/Phrasea/Search/RecordTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ public function transform($recordView)
/** @var RecordView $recordView */
$record = $recordView->getRecord();

$resolver = $this->resourceIdResolver;
$resourceId = $resolver($record);

return [
'databox_id' => $record->getDataboxId(),
'record_id' => $record->getRecordId(),
'resource_id' => ($this->resourceIdResolver)($record),
'resource_id' => $resourceId,
'mime_type' => $record->getMimeType(),
'title' => $record->get_title(['encode'=> record_adapter::ENCODE_NONE]),
'original_name' => $record->get_original_name(),
Expand Down
4 changes: 3 additions & 1 deletion lib/Alchemy/Phrasea/Search/StoryTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ public function transform(StoryView $storyView)
{
$story = $storyView->getStory();

$resourceId = $this->recordTransformer->getResourceIdResolver()($story);

return [
'@entity@' => 'http://api.phraseanet.com/api/objects/story',
'databox_id' => $story->getDataboxId(),
'story_id' => $story->getRecordId(),
'resource_id' => ($this->recordTransformer->getResourceIdResolver())($story),
'resource_id' => $resourceId,
'cover_record_id' => $story->getCoverRecordId(),
'updated_on' => NullableDateTime::format($story->getUpdated()),
'created_on' => NullableDateTime::format($story->getUpdated()),
Expand Down
32 changes: 17 additions & 15 deletions lib/Alchemy/Phrasea/WorkerManager/Subscriber/SubtitleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,25 @@ public function __construct(callable $repoWorkerJobLocator, MessagePublisher $me

public function onRecordAutoSubtitle(RecordAutoSubtitleEvent $event)
{
$data = [
"databoxId" => $event->getRecord()->getDataboxId(),
"recordId" => $event->getRecord()->getRecordId(),
"permalinkUrl" => $event->getPermalinkUrl(),
"languageSource" => $event->getLanguageSource(),
"metaStructureIdSource" => $event->getMetaStructureIdSource(),
"languageDestination" => $event->getLanguageDestination(),
"metaStructureIdDestination" => $event->getMetaStructureIdDestination(),
"type" => MessagePublisher::SUBTITLE_TYPE // used to specify the final Q to publish message
];
if (!empty($event->getLanguageDestination())) {
$data = [
"databoxId" => $event->getRecord()->getDataboxId(),
"recordId" => $event->getRecord()->getRecordId(),
"languageSource" => $event->getLanguageSource(),
"languageDestination" => $event->getLanguageDestination(),
"type" => MessagePublisher::SUBTITLE_TYPE // used to specify the final Q to publish message
];

$payload = [
'message_type' => MessagePublisher::MAIN_QUEUE_TYPE,
'payload' => $data
];
$payload = [
'message_type' => MessagePublisher::MAIN_QUEUE_TYPE,
'payload' => $data
];

$this->messagePublisher->publishMessage($payload, MessagePublisher::MAIN_QUEUE_TYPE);
} else {
$this->messagePublisher->pushLog("There is no language destination selected when trying do do autosubtitle!");
}

$this->messagePublisher->publishMessage($payload, MessagePublisher::MAIN_QUEUE_TYPE);
}

public static function getSubscribedEvents()
Expand Down
Loading

0 comments on commit 9a8beea

Please sign in to comment.