Changeset 3401776
- Timestamp:
- 11/24/2025 11:09:20 AM (4 months ago)
- Location:
- smartling-connector/trunk
- Files:
-
- 5 edited
-
inc/Smartling/Extensions/Acf/AcfDynamicSupport.php (modified) (3 diffs)
-
inc/Smartling/Helpers/TranslationHelper.php (modified) (4 diffs)
-
inc/Smartling/Helpers/XmlHelper.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
-
smartling-connector.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
smartling-connector/trunk/inc/Smartling/Extensions/Acf/AcfDynamicSupport.php
r3359747 r3401776 127 127 $defs[$groupKey] = [ 128 128 'global_type' => 'group', 129 'active' => 1,129 'active' => 1, 130 130 ]; 131 $fields = $this->getFieldsByGroup($blog, [$groupKey => $group]); 132 if (0 < count($fields)) { 133 foreach ($fields as $fieldKey => $field) { 134 $defs[$fieldKey] = [ 135 'global_type' => 'field', 136 'type' => $field['type'], 137 'name' => $field['name'], 138 'parent' => $field['parent'], 139 ]; 140 141 if ('clone' === $field['type']) { 142 if (array_key_exists('clone', $field)) { 143 $defs[$fieldKey]['clone'] = $field['clone']; 144 } else { 145 $this->getLogger()->debug('ACF field fieldType="clone" has no target. ' . json_encode($field)); 146 } 147 } 131 } 132 foreach ($this->getFields($blog, array_map(static fn($item) => $item['post_id'], $groups)) as $fieldKey => $field) { 133 $defs[$fieldKey] = [ 134 'global_type' => 'field', 135 'type' => $field['type'], 136 ]; 137 138 if ('clone' === $field['type']) { 139 if (array_key_exists('clone', $field)) { 140 $defs[$fieldKey]['clone'] = $field['clone']; 141 } else { 142 $this->getLogger()->debug('ACF field fieldType="clone" has no target. ' . json_encode($field)); 148 143 } 149 144 } … … 206 201 } 207 202 208 private function rawReadFields($parentId, $parentKey): array 209 { 210 $posts = (new \WP_Query( 211 [ 212 'post_type' => self::POST_TYPE_FIELD, 213 'suppress_filters' => true, 214 'posts_per_page' => -1, 215 'post_status' => 'publish', 216 'post_parent' => $parentId, 217 ] 218 ))->get_posts(); 219 220 $fields = []; 221 foreach ($posts as $post) { 222 $configuration = unserialize($post->post_content); 223 $fields[$post->post_name] = [ 224 'parent' => $parentKey, 225 'name' => $post->post_excerpt, 226 'type' => $configuration['type'], 227 ]; 228 $subFields = $this->rawReadFields($post->ID, $post->post_name); 229 if (0 < count($subFields)) { 230 $fields = array_merge($fields, $subFields); 231 } 232 } 233 234 return $fields; 235 } 236 237 protected function getFieldsByGroup($blogId, $group): array 238 { 239 $dbFields = []; 240 $needChange = $this->siteHelper->getCurrentBlogId() !== $blogId; 241 try { 242 if ($needChange) { 243 $this->siteHelper->switchBlogId($blogId); 244 } 245 $keys = array_keys($group); 246 $key = reset($keys); 247 $_group = reset($group); 248 $id = $_group['post_id']; 249 250 $dbFields = $this->rawReadFields($id, $key); 251 252 } catch (\Exception $e) { 253 $this->getLogger()->warning( 254 vsprintf('Error occurred while reading ACF data from blog %s. Message: %s', [$blogId, $e->getMessage()]) 255 ); 256 } finally { 257 if ($needChange) { 258 $this->siteHelper->restoreBlogId(); 259 } 260 } 261 262 return $dbFields; 203 private function rawReadFields($parentId): array 204 { 205 return $this->getFieldsFromPosts($this->getQueryByParentId($parentId)->get_posts()); 206 } 207 208 private function getFields(int $blogId, array $parentIds): array 209 { 210 return $this->siteHelper->withBlog($blogId, function () use ($parentIds): array { 211 return $this->getFieldsFromPosts($this->getQueryByParentIds($parentIds)->get_posts()); 212 }); 263 213 } 264 214 … … 715 665 return array_pop($matches[0]) ?? $key; 716 666 } 667 668 private function getQueryByParentId($parentId): \WP_Query 669 { 670 return new \WP_Query(array_merge($this->getQueryArray(), ['post_parent' => $parentId])); 671 } 672 673 private function getQueryByParentIds(array $parentIds): \WP_Query 674 { 675 return new \WP_Query(array_merge($this->getQueryArray(), ['post_parent__in' => $parentIds])); 676 } 677 678 private function getQueryArray(): array 679 { 680 return [ 681 'post_type' => self::POST_TYPE_FIELD, 682 'suppress_filters' => true, 683 'posts_per_page' => -1, 684 'post_status' => 'publish', 685 ]; 686 } 687 688 private function getFieldsFromPosts(array $posts): array 689 { 690 $fields = []; 691 foreach ($posts as $post) { 692 $configuration = unserialize($post->post_content); 693 $fields[$post->post_name] = [ 694 'type' => $configuration['type'], 695 ]; 696 $subFields = $this->rawReadFields($post->ID); 697 if (0 < count($subFields)) { 698 $fields = array_merge($fields, $subFields); 699 } 700 } 701 702 return $fields; 703 } 717 704 } -
smartling-connector/trunk/inc/Smartling/Helpers/TranslationHelper.php
r3335327 r3401776 6 6 use Smartling\Bootstrap; 7 7 use Smartling\DbAl\LocalizationPluginProxyInterface; 8 use Smartling\Exception\BlogNotFoundException; 9 use Smartling\Exception\SmartlingConfigException; 8 10 use Smartling\Exception\SmartlingDataReadException; 11 use Smartling\Exception\SmartlingDirectRunRuntimeException; 12 use Smartling\Exception\SmartlingInvalidFactoryArgumentException; 9 13 use Smartling\Jobs\JobEntityWithBatchUid; 10 14 use Smartling\Submissions\SubmissionEntity; … … 98 102 99 103 /** 100 * @throws SmartlingDataReadException 104 * @throws BlogNotFoundException 105 * @throws SmartlingConfigException 106 * @throws SmartlingDirectRunRuntimeException 107 * @throws SmartlingDataReadException 108 * @throws SmartlingInvalidFactoryArgumentException 101 109 */ 102 110 public function prepareSubmission(string $contentType, int $sourceBlog, int $sourceId, int $targetBlog, bool $clone = false): SubmissionEntity … … 111 119 $targetBlog 112 120 ); 121 if ($submission->getFileUri() === '') { 122 $submission->setFileUri($this->fileUriHelper->generateFileUri($submission)); 123 } 113 124 114 125 if (0 === (int)$submission->getId()) { … … 158 169 159 170 /** 160 * @throws SmartlingDataReadException 171 * @throws BlogNotFoundException 172 * @throws SmartlingConfigException 173 * @throws SmartlingDirectRunRuntimeException 174 * @throws SmartlingDataReadException 175 * @throws SmartlingInvalidFactoryArgumentException 161 176 */ 162 177 public function tryPrepareRelatedContent(string $contentType, int $sourceBlog, int $sourceId, int $targetBlog, JobEntityWithBatchUid $jobInfo, bool $clone = false): SubmissionEntity -
smartling-connector/trunk/inc/Smartling/Helpers/XmlHelper.php
r3041280 r3401776 10 10 use Smartling\Bootstrap; 11 11 use Smartling\Exception\InvalidXMLException; 12 use Smartling\Exception\SmartlingDbException; 12 13 use Smartling\Helpers\EventParameters\TranslationStringFilterParameters; 13 14 use Smartling\Helpers\Serializers\SerializerInterface; 15 use Smartling\Settings\ConfigurationProfileEntity; 14 16 use Smartling\Settings\SettingsManager; 15 17 use Smartling\Services\GlobalSettingsManager; … … 27 29 } 28 30 29 const XML_ROOT_NODE_NAME = 'data';31 private const XML_ROOT_NODE_NAME = 'data'; 30 32 31 33 private const XML_STRING_NODE_NAME = 'string'; … … 38 40 } 39 41 40 private function setTranslationComments(DOMDocument $document ): DOMDocument42 private function setTranslationComments(DOMDocument $document, ?ConfigurationProfileEntity $profile): DOMDocument 41 43 { 42 44 $comments = [ … … 50 52 ]; 51 53 54 if ($profile !== null) { 55 $comments[] = 'Profile config:'; 56 try { 57 $comments[] = $this->escapeCommentString(json_encode( 58 $profile->toArray(), 59 JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR, 60 )); 61 } catch (\Throwable $e) { 62 $this->getLogger()->warning('Failed to encode profile config: ' . $e->getMessage()); 63 } 64 } 65 52 66 foreach (explode("\n", GlobalSettingsManager::getCustomDirectives()) as $comment) { 53 67 if ($comment !== '') { … … 76 90 { 77 91 $this->getLogger()->debug(sprintf('Started creating XML for fields: %s', base64_encode(var_export($source, true)))); 78 $xml = $this->setTranslationComments($this->initXml()); 92 try { 93 $profile = $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId()); 94 } catch (SmartlingDbException) { 95 $profile = null; 96 } 97 $xml = $this->setTranslationComments($this->initXml(), $profile); 79 98 $settings = $this->contentSerializationHelper->prepareFieldProcessorValues($submission); 80 99 $rootNode = $xml->createElement(self::XML_ROOT_NODE_NAME); … … 199 218 return []; 200 219 } 220 221 private function escapeCommentString(string $string): string 222 { 223 return preg_replace('~-{2,}~', '--', $string); 224 } 201 225 } -
smartling-connector/trunk/readme.txt
r3397138 r3401776 5 5 Tested up to: 6.6.2 6 6 Requires PHP: 8.0 7 Stable tag: 5.0. 17 Stable tag: 5.0.2 8 8 License: GPLv2 or later 9 9 … … 63 63 64 64 == Changelog == 65 = 5.0.2 = 66 * Improved performance when working on installations with a large number of ACF fields 67 65 68 = 5.0.1 = 66 69 * Fixed issue where an exception during submission cloning would prevent the cloning queue from processing other items -
smartling-connector/trunk/smartling-connector.php
r3397138 r3401776 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: 5.0. 114 * Version: 5.0.2 15 15 * Author: Smartling 16 16 * Author URI: https://www.smartling.com
Note: See TracChangeset
for help on using the changeset viewer.