Changeset 3335327
- Timestamp:
- 07/28/2025 11:35:38 AM (8 months ago)
- Location:
- smartling-connector/trunk
- Files:
-
- 9 edited
-
inc/Smartling/ContentTypes/ConfigParsers/FieldFilterConfigParser.php (modified) (1 diff)
-
inc/Smartling/ContentTypes/ContentTypeNavigationMenuItem.php (modified) (2 diffs)
-
inc/Smartling/Helpers/MetaFieldProcessor/BulkProcessors/CustomTypeProcessor.php (modified) (1 diff)
-
inc/Smartling/Helpers/MetaFieldProcessor/NavigationMenuItemProcessor.php (modified) (2 diffs)
-
inc/Smartling/Helpers/MetaFieldProcessor/ReferencedContentProcessor.php (modified) (6 diffs)
-
inc/Smartling/Helpers/TranslationHelper.php (modified) (6 diffs)
-
inc/config/services.yml (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
smartling-connector.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
smartling-connector/trunk/inc/Smartling/ContentTypes/ConfigParsers/FieldFilterConfigParser.php
r2862047 r3335327 338 338 default: 339 339 $filter = new CustomTypeProcessor( 340 $this->getService('content.helper'), 341 $this->submissionManager, 340 342 $this->getService('translation.helper'), 341 343 $this->getPattern(), 342 344 $this->getFilterType() 343 345 ); 344 $filter->setContentHelper($this->getService('content.helper'));345 346 $filter->setSerializer($serializer); 346 347 break; -
smartling-connector/trunk/inc/Smartling/ContentTypes/ContentTypeNavigationMenuItem.php
r2862047 r3335327 3 3 namespace Smartling\ContentTypes; 4 4 5 use Smartling\Helpers\CustomMenuContentTypeHelper;6 5 use Smartling\Vendor\Symfony\Component\DependencyInjection\ContainerBuilder; 7 6 … … 76 75 } 77 76 78 /** 79 * @return void 80 */ 81 public function registerFilters() 77 public function registerFilters(): void 82 78 { 83 79 $di = $this->getContainerBuilder(); 84 $wrapperId = 'referenced-content.menu_item_parent';85 $definition = $di->register($wrapperId, 'Smartling\Helpers\MetaFieldProcessor\ReferencedContentProcessor');86 $definition87 ->addArgument($di->getDefinition('translation.helper'))88 ->addArgument(CustomMenuContentTypeHelper::META_KEY_MENU_ITEM_PARENT)89 ->addArgument($this->getSystemName())90 ->addMethodCall('setContentHelper', [$di->getDefinition('content.helper')]);91 92 $di->get('meta-field.processor.manager')->registerProcessor($di->get($wrapperId));93 94 95 $referenceWrapperId = 'referenced-content.menu_item_content';96 $definition = $di->register($referenceWrapperId, 'Smartling\Helpers\MetaFieldProcessor\NavigationMenuItemProcessor');97 $definition98 ->addArgument($di->getDefinition('translation.helper'))99 ->addArgument('^(_menu_item_object_id)$')100 ->addArgument($this->getSystemName())101 ->addMethodCall('setContentHelper', [$di->getDefinition('content.helper')]);102 103 $di->get('meta-field.processor.manager')->registerProcessor($di->get($referenceWrapperId));104 105 80 106 81 $cloneWrapperId = 'cloned-content.menu_item_meta'; -
smartling-connector/trunk/inc/Smartling/Helpers/MetaFieldProcessor/BulkProcessors/CustomTypeProcessor.php
r1606175 r3335327 16 16 17 17 /** 18 * @param SubmissionEntity $submission 19 * @param string $fieldName 20 * @param mixed $value 21 * 22 * @return mixed 18 * @param string $fieldName 19 * @param mixed $value 23 20 */ 24 public function processFieldPostTranslation(SubmissionEntity $submission, $fieldName, $value) 21 public function processFieldPostTranslation(SubmissionEntity $submission, $fieldName, $value): mixed 25 22 { 26 23 $originalValue = $value; -
smartling-connector/trunk/inc/Smartling/Helpers/MetaFieldProcessor/NavigationMenuItemProcessor.php
r3318909 r3335327 2 2 namespace Smartling\Helpers\MetaFieldProcessor; 3 3 4 use Smartling\ContentTypes\ContentTypeNavigationMenuItem;5 use Smartling\Helpers\ArrayHelper;6 use Smartling\Helpers\Parsers\IntegerParser;7 use Smartling\Jobs\JobEntityWithBatchUid;8 4 use Smartling\Submissions\SubmissionEntity; 9 5 10 6 class NavigationMenuItemProcessor extends ReferencedContentProcessor 11 7 { 12 /** 13 * @param SubmissionEntity $submission 14 * @param string $fieldName 15 * @param mixed $value 16 * @return mixed 17 */ 18 public function processFieldPostTranslation(SubmissionEntity $submission, $fieldName, $value) 8 public function processFieldPreTranslation(SubmissionEntity $submission, $fieldName, $value, array $collectedFields, string $contentType = null): mixed 19 9 { 20 $originalValue = $value;21 22 if (is_array($value)) {23 $value = ArrayHelper::first($value);24 }25 26 if (!IntegerParser::tryParseString($value, $value)) {27 $message = vsprintf(28 'Got bad reference number for submission id=%s metadata field=\'%s\' with value=\'%s\', expected integer > 0. Skipping.',29 [$submission->getId(), $fieldName, var_export($originalValue, true),]30 );31 $this->getLogger()->warning($message);32 33 return $originalValue;34 }35 36 if (0 === $value) {37 return $value;38 }39 40 10 try { 41 $this->getLogger()->debug( 42 vsprintf( 43 'Sending for translation referenced content id = \'%s\' related to submission = \'%s\'.', 44 [$value, $submission->getId()] 45 ) 46 ); 47 48 $originalMetadata = $this->getContentHelper()->readSourceMetadata($submission); 49 11 $originalMetadata = $this->contentHelper->readSourceMetadata($submission); 50 12 if (array_key_exists('_menu_item_type', $originalMetadata) && 51 13 in_array($originalMetadata['_menu_item_type'], ['taxonomy', 'post_type'], true) 52 14 ) { 53 $relatedContentType = $originalMetadata['_menu_item_object']; 54 $sourceBlogId = $submission->getSourceBlogId(); 55 $targetBlogId = $submission->getTargetBlogId(); 56 if ($this->getTranslationHelper()->isRelatedSubmissionCreationNeeded($relatedContentType, $sourceBlogId, $value, $targetBlogId)) { 57 $this->getLogger()->debug(sprintf("Sending for translation object = '$relatedContentType' id = '$value' related to '%s' related to submission = '{$submission->getId()}'.", ContentTypeNavigationMenuItem::WP_CONTENT_TYPE)); 58 59 return $this->getTranslationHelper()->tryPrepareRelatedContent( 60 $relatedContentType, 61 $sourceBlogId, 62 $value, 63 $targetBlogId, 64 JobEntityWithBatchUid::fromJob($submission->getJobInfo(), ''), 65 $submission->isCloned(), 66 )->getTargetId(); 15 $contentType = $originalMetadata['_menu_item_object'] ?? null; 16 if ($contentType !== null) { 17 return parent::processFieldPreTranslation($submission, $fieldName, $value, $collectedFields, $contentType); 67 18 } 68 69 $this->getLogger()->debug("Skip sending object = '$relatedContentType' id = '$value' due to manual relations handling");70 19 } 71 20 } catch (\Exception $e) { … … 73 22 } 74 23 75 return 0;24 return $value; 76 25 } 77 26 } -
smartling-connector/trunk/inc/Smartling/Helpers/MetaFieldProcessor/ReferencedContentProcessor.php
r3318909 r3335327 6 6 use Smartling\Helpers\ArrayHelper; 7 7 use Smartling\Helpers\ContentHelper; 8 use Smartling\Helpers\LoggerSafeTrait; 8 9 use Smartling\Helpers\Parsers\IntegerParser; 9 10 use Smartling\Helpers\TranslationHelper; 10 11 use Smartling\Jobs\JobEntityWithBatchUid; 11 12 use Smartling\Submissions\SubmissionEntity; 13 use Smartling\Submissions\SubmissionManager; 12 14 13 15 class ReferencedContentProcessor extends MetaFieldProcessorAbstract 14 16 { 15 /** 16 * @var ContentHelper 17 */ 18 private $contentHelper; 17 use LoggerSafeTrait; 19 18 20 /** 21 * @var string 22 */ 23 private $contentType; 24 25 /** 26 * @return string 27 */ 28 public function getContentType() 29 { 30 return $this->contentType; 19 public function __construct( 20 protected ContentHelper $contentHelper, 21 private SubmissionManager $submissionManager, 22 TranslationHelper $translationHelper, 23 string $fieldRegexp, 24 private string $contentType, 25 ) { 26 parent::__construct(); 27 $this->setTranslationHelper($translationHelper); 28 $this->setFieldRegexp($fieldRegexp); 31 29 } 32 30 33 31 /** 34 * @param string $contentType 32 * @param string $fieldName 33 * @param mixed $value 35 34 */ 36 public function setContentType($contentType) 37 { 38 $this->contentType = $contentType; 39 } 40 41 /** 42 * @return ContentHelper 43 */ 44 public function getContentHelper() 45 { 46 return $this->contentHelper; 47 } 48 49 /** 50 * @param ContentHelper $contentHelper 51 */ 52 public function setContentHelper($contentHelper) 53 { 54 $this->contentHelper = $contentHelper; 55 } 56 57 /** 58 * MetaFieldProcessorInterface constructor. 59 * 60 * @param TranslationHelper $translationHelper 61 * @param string $fieldRegexp 62 * @param string $contentType Expected content type in the field 63 */ 64 public function __construct(TranslationHelper $translationHelper, $fieldRegexp, $contentType) 65 { 66 parent::__construct(); 67 $this->setTranslationHelper($translationHelper); 68 $this->setFieldRegexp($fieldRegexp); 69 $this->setContentType($contentType); 70 } 71 72 /** 73 * @param SubmissionEntity $submission 74 * @param string $fieldName 75 * @param mixed $value 76 * 77 * @return mixed 78 */ 79 public function processFieldPostTranslation(SubmissionEntity $submission, $fieldName, $value) 35 public function processFieldPostTranslation(SubmissionEntity $submission, $fieldName, $value): mixed 80 36 { 81 37 $originalValue = $value; … … 99 55 } 100 56 57 if (is_int($value)) { 58 $related = $this->submissionManager->findOne([ 59 SubmissionEntity::FIELD_CONTENT_TYPE => $this->contentType, 60 SubmissionEntity::FIELD_SOURCE_BLOG_ID => $submission->getSourceBlogId(), 61 SubmissionEntity::FIELD_SOURCE_ID => $value, 62 SubmissionEntity::FIELD_TARGET_BLOG_ID => $submission->getTargetBlogId(), 63 ]); 64 if ($related !== null) { 65 return $related->getTargetId(); 66 } 67 } 68 69 return $originalValue; 70 } 71 72 /** 73 * @param string $fieldName 74 * @param mixed $value 75 */ 76 public function processFieldPreTranslation( 77 SubmissionEntity $submission, 78 $fieldName, 79 $value, 80 array $collectedFields, 81 string $contentType = null, 82 ): mixed { 83 if ($contentType === null) { 84 $contentType = $this->contentType; 85 } 101 86 try { 102 $contentType = $this->getContentType();103 87 $sourceBlogId = $submission->getSourceBlogId(); 104 88 $targetBlogId = $submission->getTargetBlogId(); … … 106 90 $this->getLogger()->debug("Sending for translation referenced content id = '$value' related to submission = '{$submission->getId()}'."); 107 91 108 return$this->getTranslationHelper()->tryPrepareRelatedContent(92 $this->getTranslationHelper()->tryPrepareRelatedContent( 109 93 $contentType, 110 94 $sourceBlogId, … … 113 97 JobEntityWithBatchUid::fromJob($submission->getJobInfo(), ''), 114 98 $submission->isCloned(), 115 ) ->getTargetId();99 ); 116 100 } 117 101 118 102 $this->getLogger()->debug("Skipped sending referenced content id = '$value' related to submission = '{$submission->getId()} due to manual relations handling"); 119 } catch (SmartlingDataReadException $e) {103 } catch (SmartlingDataReadException) { 120 104 $message = vsprintf( 121 105 'An error happened while processing referenced content with original value=%s. Keeping original value.', 122 106 [ 123 var_export($ originalValue, true),107 var_export($value, true), 124 108 ] 125 109 ); … … 129 113 'An exception occurred while sending related item=%s, submission=%s for translation. Message: %s', 130 114 [ 131 var_export($ originalValue, true),115 var_export($value, true), 132 116 $submission->getId(), 133 117 $e->getMessage(), … … 137 121 } 138 122 139 return $originalValue; 140 } 141 142 /** 143 * @param SubmissionEntity $submission 144 * @param string $fieldName 145 * @param mixed $value 146 * @param array $collectedFields 147 * 148 * @return mixed or empty string (to skip translation) 149 */ 150 public function processFieldPreTranslation(SubmissionEntity $submission, $fieldName, $value, array $collectedFields) 151 { 152 return $this->processFieldPostTranslation($submission, $fieldName, $value); 123 return $value; 153 124 } 154 125 } -
smartling-connector/trunk/inc/Smartling/Helpers/TranslationHelper.php
r3077564 r3335327 37 37 ); 38 38 39 $this-> logger->warning(39 $this->getLogger()->warning( 40 40 vsprintf( 41 41 'Trying to get/create submission with invalid sourceBlogId, trace:\n\n%s\nRequest dump:\n%s', … … 55 55 ); 56 56 57 $this-> logger->warning(57 $this->getLogger()->warning( 58 58 vsprintf( 59 59 'Trying to get/create submission with invalid targetBlogId, trace:\n\n%s\nRequest dump:\n%s', … … 70 70 $exception = new UnexpectedValueException('Unexpected value: sourceBlogId cannot be same as targetBlogId'); 71 71 72 $this-> logger->warning(72 $this->getLogger()->warning( 73 73 vsprintf( 74 74 'Trying to get/create submission with same sourceBlogId and targetBlogId, trace:\n\n%s\nRequest dump:\n%s', … … 151 151 $submission = $this->submissionManager->getSubmissionEntity($contentType, $sourceBlogId, $contentId, $targetBlogId, $this->multilangProxy); 152 152 if ($submission->getTargetId() === 0) { 153 $this-> logger->debug("Got submission with 0 target id");153 $this->getLogger()->debug("Got submission with 0 target id"); 154 154 $submission = $this->tryPrepareRelatedContent($contentType, $sourceBlogId, $contentId, $targetBlogId, $jobInfo); 155 155 } … … 187 187 $relatedSubmission = apply_filters(ExportedAPI::FILTER_SMARTLING_PREPARE_TARGET_CONTENT, $relatedSubmission); 188 188 if (!($relatedSubmission instanceof SubmissionEntity)) { 189 $this-> logger->critical('Related submission not instance of ' . SubmissionEntity::class . ' after filter ' . ExportedAPI::FILTER_SMARTLING_PREPARE_TARGET_CONTENT . '. This is most likely due to an error outside of the plugins code.');189 $this->getLogger()->critical('Related submission not instance of ' . SubmissionEntity::class . ' after filter ' . ExportedAPI::FILTER_SMARTLING_PREPARE_TARGET_CONTENT . '. This is most likely due to an error outside of the plugins code.'); 190 190 } 191 191 … … 203 203 } 204 204 205 $this-> logger->debug($message);205 $this->getLogger()->debug($message); 206 206 207 207 return $this->reloadSubmission($relatedSubmission); -
smartling-connector/trunk/inc/config/services.yml
r3333320 r3335327 457 457 - "@wp.proxy" 458 458 459 referenced-content.menu_item_content: 460 class: Smartling\Helpers\MetaFieldProcessor\NavigationMenuItemProcessor 461 arguments: 462 - "@content.helper" 463 - "@manager.submission" 464 - "@translation.helper" 465 - "_menu_item_object_id" 466 - "nav_menu_item" 467 468 referenced-content.menu_item_parent: 469 class: Smartling\Helpers\MetaFieldProcessor\ReferencedContentProcessor 470 arguments: 471 - "@content.helper" 472 - "@manager.submission" 473 - "@translation.helper" 474 - "_menu_item_menu_item_parent" 475 - "nav_menu_item" 476 459 477 meta-field.processor.manager: 460 478 class: Smartling\Helpers\MetaFieldProcessor\MetaFieldProcessorManager … … 465 483 calls: 466 484 - [ "registerProcessor", ["@post.content.processor"]] 485 - [ "registerProcessor", ["@referenced-content.menu_item_content"]] 486 - [ "registerProcessor", ["@referenced-content.menu_item_parent"]] 467 487 468 488 service.blog-removal-handler: -
smartling-connector/trunk/readme.txt
r3333344 r3335327 5 5 Tested up to: 6.6.2 6 6 Requires PHP: 8.0 7 Stable tag: 4. 0.07 Stable tag: 4.1.0 8 8 License: GPLv2 or later 9 9 … … 63 63 64 64 == Changelog == 65 = 4.1.0 = 66 * Fixed navigation menu item parent relations after translation 67 65 68 = 4.0.0 = 66 69 * Reworked upload and download cron jobs to only work with submissions from the blog that initiates the cron job -
smartling-connector/trunk/smartling-connector.php
r3333344 r3335327 12 12 * Plugin URI: https://www.smartling.com/products/automate/integrations/wordpress/ 13 13 * Description: Integrate your WordPress site with Smartling to upload your content and download translations. 14 * Version: 4. 0.014 * Version: 4.1.0 15 15 * Author: Smartling 16 16 * Author URI: https://www.smartling.com
Note: See TracChangeset
for help on using the changeset viewer.