Plugin Directory

Changeset 3335327


Ignore:
Timestamp:
07/28/2025 11:35:38 AM (8 months ago)
Author:
smartling
Message:

Update to v 4.1.0

Location:
smartling-connector/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • smartling-connector/trunk/inc/Smartling/ContentTypes/ConfigParsers/FieldFilterConfigParser.php

    r2862047 r3335327  
    338338            default:
    339339                $filter = new CustomTypeProcessor(
     340                    $this->getService('content.helper'),
     341                    $this->submissionManager,
    340342                    $this->getService('translation.helper'),
    341343                    $this->getPattern(),
    342344                    $this->getFilterType()
    343345                );
    344                 $filter->setContentHelper($this->getService('content.helper'));
    345346                $filter->setSerializer($serializer);
    346347                break;
  • smartling-connector/trunk/inc/Smartling/ContentTypes/ContentTypeNavigationMenuItem.php

    r2862047 r3335327  
    33namespace Smartling\ContentTypes;
    44
    5 use Smartling\Helpers\CustomMenuContentTypeHelper;
    65use Smartling\Vendor\Symfony\Component\DependencyInjection\ContainerBuilder;
    76
     
    7675    }
    7776
    78     /**
    79      * @return void
    80      */
    81     public function registerFilters()
     77    public function registerFilters(): void
    8278    {
    8379        $di = $this->getContainerBuilder();
    84         $wrapperId = 'referenced-content.menu_item_parent';
    85         $definition = $di->register($wrapperId, 'Smartling\Helpers\MetaFieldProcessor\ReferencedContentProcessor');
    86         $definition
    87             ->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         $definition
    98             ->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 
    10580
    10681        $cloneWrapperId = 'cloned-content.menu_item_meta';
  • smartling-connector/trunk/inc/Smartling/Helpers/MetaFieldProcessor/BulkProcessors/CustomTypeProcessor.php

    r1606175 r3335327  
    1616
    1717    /**
    18      * @param SubmissionEntity $submission
    19      * @param string           $fieldName
    20      * @param mixed            $value
    21      *
    22      * @return mixed
     18     * @param string $fieldName
     19     * @param mixed $value
    2320     */
    24     public function processFieldPostTranslation(SubmissionEntity $submission, $fieldName, $value)
     21    public function processFieldPostTranslation(SubmissionEntity $submission, $fieldName, $value): mixed
    2522    {
    2623        $originalValue = $value;
  • smartling-connector/trunk/inc/Smartling/Helpers/MetaFieldProcessor/NavigationMenuItemProcessor.php

    r3318909 r3335327  
    22namespace Smartling\Helpers\MetaFieldProcessor;
    33
    4 use Smartling\ContentTypes\ContentTypeNavigationMenuItem;
    5 use Smartling\Helpers\ArrayHelper;
    6 use Smartling\Helpers\Parsers\IntegerParser;
    7 use Smartling\Jobs\JobEntityWithBatchUid;
    84use Smartling\Submissions\SubmissionEntity;
    95
    106class NavigationMenuItemProcessor extends ReferencedContentProcessor
    117{
    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
    199    {
    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 
    4010        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);
    5012            if (array_key_exists('_menu_item_type', $originalMetadata) &&
    5113                in_array($originalMetadata['_menu_item_type'], ['taxonomy', 'post_type'], true)
    5214            ) {
    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);
    6718                }
    68 
    69                 $this->getLogger()->debug("Skip sending object = '$relatedContentType' id = '$value' due to manual relations handling");
    7019            }
    7120        } catch (\Exception $e) {
     
    7322        }
    7423
    75         return 0;
     24        return $value;
    7625    }
    7726}
  • smartling-connector/trunk/inc/Smartling/Helpers/MetaFieldProcessor/ReferencedContentProcessor.php

    r3318909 r3335327  
    66use Smartling\Helpers\ArrayHelper;
    77use Smartling\Helpers\ContentHelper;
     8use Smartling\Helpers\LoggerSafeTrait;
    89use Smartling\Helpers\Parsers\IntegerParser;
    910use Smartling\Helpers\TranslationHelper;
    1011use Smartling\Jobs\JobEntityWithBatchUid;
    1112use Smartling\Submissions\SubmissionEntity;
     13use Smartling\Submissions\SubmissionManager;
    1214
    1315class ReferencedContentProcessor extends MetaFieldProcessorAbstract
    1416{
    15     /**
    16      * @var ContentHelper
    17      */
    18     private $contentHelper;
     17    use LoggerSafeTrait;
    1918
    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);
    3129    }
    3230
    3331    /**
    34      * @param string $contentType
     32     * @param string $fieldName
     33     * @param mixed $value
    3534     */
    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
    8036    {
    8137        $originalValue = $value;
     
    9955        }
    10056
     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        }
    10186        try {
    102             $contentType = $this->getContentType();
    10387            $sourceBlogId = $submission->getSourceBlogId();
    10488            $targetBlogId = $submission->getTargetBlogId();
     
    10690                $this->getLogger()->debug("Sending for translation referenced content id = '$value' related to submission = '{$submission->getId()}'.");
    10791
    108                 return $this->getTranslationHelper()->tryPrepareRelatedContent(
     92                $this->getTranslationHelper()->tryPrepareRelatedContent(
    10993                    $contentType,
    11094                    $sourceBlogId,
     
    11397                    JobEntityWithBatchUid::fromJob($submission->getJobInfo(), ''),
    11498                    $submission->isCloned(),
    115                 )->getTargetId();
     99                );
    116100            }
    117101
    118102            $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) {
    120104            $message = vsprintf(
    121105                'An error happened while processing referenced content with original value=%s. Keeping original value.',
    122106                [
    123                     var_export($originalValue, true),
     107                    var_export($value, true),
    124108                ]
    125109            );
     
    129113                'An exception occurred while sending related item=%s, submission=%s for translation. Message: %s',
    130114                [
    131                     var_export($originalValue, true),
     115                    var_export($value, true),
    132116                    $submission->getId(),
    133117                    $e->getMessage(),
     
    137121        }
    138122
    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;
    153124    }
    154125}
  • smartling-connector/trunk/inc/Smartling/Helpers/TranslationHelper.php

    r3077564 r3335327  
    3737            );
    3838
    39             $this->logger->warning(
     39            $this->getLogger()->warning(
    4040                vsprintf(
    4141                    'Trying to get/create submission with invalid sourceBlogId, trace:\n\n%s\nRequest dump:\n%s',
     
    5555            );
    5656
    57             $this->logger->warning(
     57            $this->getLogger()->warning(
    5858                vsprintf(
    5959                    'Trying to get/create submission with invalid targetBlogId, trace:\n\n%s\nRequest dump:\n%s',
     
    7070            $exception = new UnexpectedValueException('Unexpected value: sourceBlogId cannot be same as targetBlogId');
    7171
    72             $this->logger->warning(
     72            $this->getLogger()->warning(
    7373                vsprintf(
    7474                    'Trying to get/create submission with same sourceBlogId and targetBlogId, trace:\n\n%s\nRequest dump:\n%s',
     
    151151        $submission = $this->submissionManager->getSubmissionEntity($contentType, $sourceBlogId, $contentId, $targetBlogId, $this->multilangProxy);
    152152        if ($submission->getTargetId() === 0) {
    153             $this->logger->debug("Got submission with 0 target id");
     153            $this->getLogger()->debug("Got submission with 0 target id");
    154154            $submission = $this->tryPrepareRelatedContent($contentType, $sourceBlogId, $contentId, $targetBlogId, $jobInfo);
    155155        }
     
    187187            $relatedSubmission = apply_filters(ExportedAPI::FILTER_SMARTLING_PREPARE_TARGET_CONTENT, $relatedSubmission);
    188188            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.');
    190190            }
    191191
     
    203203        }
    204204
    205         $this->logger->debug($message);
     205        $this->getLogger()->debug($message);
    206206
    207207        return $this->reloadSubmission($relatedSubmission);
  • smartling-connector/trunk/inc/config/services.yml

    r3333320 r3335327  
    457457      - "@wp.proxy"
    458458
     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
    459477  meta-field.processor.manager:
    460478    class: Smartling\Helpers\MetaFieldProcessor\MetaFieldProcessorManager
     
    465483    calls:
    466484      - [ "registerProcessor", ["@post.content.processor"]]
     485      - [ "registerProcessor", ["@referenced-content.menu_item_content"]]
     486      - [ "registerProcessor", ["@referenced-content.menu_item_parent"]]
    467487
    468488  service.blog-removal-handler:
  • smartling-connector/trunk/readme.txt

    r3333344 r3335327  
    55Tested up to: 6.6.2
    66Requires PHP: 8.0
    7 Stable tag: 4.0.0
     7Stable tag: 4.1.0
    88License: GPLv2 or later
    99
     
    6363
    6464== Changelog ==
     65= 4.1.0 =
     66* Fixed navigation menu item parent relations after translation
     67
    6568= 4.0.0 =
    6669* 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  
    1212 * Plugin URI:        https://www.smartling.com/products/automate/integrations/wordpress/
    1313 * Description:       Integrate your WordPress site with Smartling to upload your content and download translations.
    14  * Version:           4.0.0
     14 * Version:           4.1.0
    1515 * Author:            Smartling
    1616 * Author URI:        https://www.smartling.com
Note: See TracChangeset for help on using the changeset viewer.