Changeset 3333344
- Timestamp:
- 07/24/2025 07:58:19 AM (8 months ago)
- Location:
- smartling-connector/trunk
- Files:
-
- 6 edited
-
inc/Smartling/DbAl/UploadQueueManager.php (modified) (4 diffs)
-
inc/Smartling/Jobs/DownloadTranslationJob.php (modified) (3 diffs)
-
inc/Smartling/Jobs/UploadJob.php (modified) (4 diffs)
-
inc/config/cron.yml (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
smartling-connector.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
smartling-connector/trunk/inc/Smartling/DbAl/UploadQueueManager.php
r3132239 r3333344 41 41 } 42 42 43 public function dequeue( ): ?UploadQueueItem43 public function dequeue(int $blogId): ?UploadQueueItem 44 44 { 45 while (($result = $this->db->getRowArray(QueryBuilder::buildSelectQuery( 46 tableName: $this->tableName, 47 fieldsList: [ 48 UploadQueueEntity::FIELD_ID, 49 UploadQueueEntity::FIELD_BATCH_UID, 50 UploadQueueEntity::FIELD_SUBMISSION_IDS, 51 ], 52 sortOptions: [UploadQueueEntity::FIELD_ID => 'ASC'], 53 ))) !== null) { 54 $this->delete($result[UploadQueueEntity::FIELD_ID]); 55 $batchUid = $result[UploadQueueEntity::FIELD_BATCH_UID]; 45 // Get queue items with first submission having its source blog id = $blogId. 46 // It's impossible to create a single queue item with submissions from multiple source blog ids, 47 // so only checking one is enough. 48 $query = sprintf(<<<'SQL' 49 select q.%1$s, q.%2$s, q.%3$s from %7$s q left join %8$s s 50 on if(locate(',', q.%2$s), left(%2$s, locate(',', %2$s) - 1), %2$s) = s.%4$s 51 where s.%5$s = %6$d 52 SQL, 53 UploadQueueEntity::FIELD_ID, 54 UploadQueueEntity::FIELD_SUBMISSION_IDS, 55 UploadQueueEntity::FIELD_BATCH_UID, 56 SubmissionEntity::FIELD_ID, 57 SubmissionEntity::FIELD_SOURCE_BLOG_ID, 58 $blogId, 59 $this->db->completeTableName(UploadQueueEntity::getTableName()), 60 $this->db->completeTableName(SubmissionEntity::getTableName()), 61 ); 62 while (($row = $this->db->getRowArray($query)) !== null) { 63 $this->delete($row[UploadQueueEntity::FIELD_ID]); 56 64 $locales = new IntStringPairCollection(); 57 65 $submissions = []; 58 foreach (IntegerIterator::fromString($result[UploadQueueEntity::FIELD_SUBMISSION_IDS]) as $submissionId) {66 foreach (IntegerIterator::fromString($row[UploadQueueEntity::FIELD_SUBMISSION_IDS]) as $submissionId) { 59 67 $submission = $this->submissionManager->getEntityById($submissionId); 60 68 if ($submission === null) { … … 71 79 } 72 80 73 return new UploadQueueItem($submissions, $ batchUid, $locales);81 return new UploadQueueItem($submissions, $row[UploadQueueEntity::FIELD_BATCH_UID], $locales); 74 82 } 75 83 … … 104 112 } 105 113 }); 114 } 115 116 public function length(): int 117 { 118 return (int)$this->db->getRowArray("SELECT COUNT(*) cnt FROM $this->tableName")['cnt']; 106 119 } 107 120 … … 162 175 $this->db->query(QueryBuilder::buildDeleteQuery($this->tableName, $block)); 163 176 } 177 164 178 } -
smartling-connector/trunk/inc/Smartling/Jobs/DownloadTranslationJob.php
r3333320 r3333344 7 7 use Smartling\Helpers\ArrayHelper; 8 8 use Smartling\Helpers\Cache; 9 use Smartling\Helpers\WordpressFunctionProxyHelper; 9 10 use Smartling\Queue\QueueInterface; 10 11 use Smartling\Settings\SettingsManager; … … 20 21 SettingsManager $settingsManager, 21 22 SubmissionManager $submissionManager, 23 private WordpressFunctionProxyHelper $wpProxy, 22 24 int $throttleIntervalSeconds, 23 25 string $jobRunInterval, … … 36 38 $this->getLogger()->debug('Started Translation Download Job.'); 37 39 38 $this->processDownloadQueue( );40 $this->processDownloadQueue($this->wpProxy->get_current_blog_id()); 39 41 40 42 $this->getLogger()->debug('Finished Translation Download Job.'); 41 43 } 42 44 43 private function processDownloadQueue( ): void45 private function processDownloadQueue(int $blogId): void 44 46 { 45 while (null !== ($submissionId = $this->queue->dequeue(QueueInterface::QUEUE_NAME_DOWNLOAD_QUEUE))) { 46 $submissionId = ArrayHelper::first($submissionId); 47 $result = $this->submissionManager->find(['id' => $submissionId]); 47 $processed = 0; 48 $queueLength = $this->queue->stats()[QueueInterface::QUEUE_NAME_DOWNLOAD_QUEUE] ?? 0; 49 while ($processed++ < $queueLength) { 50 $queueItem = $this->queue->dequeue(QueueInterface::QUEUE_NAME_DOWNLOAD_QUEUE); 51 if ($queueItem === null) { 52 break; 53 } 54 $submissionId = ArrayHelper::first($queueItem); 55 $entity = $this->submissionManager->getEntityById($submissionId); 48 56 49 if (0 < count($result)) { 50 $entity = ArrayHelper::first($result); 51 } else { 57 if ($entity === null) { 52 58 $this->getLogger() 53 59 ->warning(vsprintf('Got submission id=%s that does not exists in database. Skipping.', [$submissionId])); 60 continue; 61 } 62 if ($entity->getSourceBlogId() !== $blogId) { 63 $this->queue->enqueue($queueItem, QueueInterface::QUEUE_NAME_DOWNLOAD_QUEUE); 54 64 continue; 55 65 } -
smartling-connector/trunk/inc/Smartling/Jobs/UploadJob.php
r3333320 r3333344 9 9 use Smartling\Helpers\Cache; 10 10 use Smartling\Helpers\FileUriHelper; 11 use Smartling\Helpers\WordpressFunctionProxyHelper; 11 12 use Smartling\Settings\SettingsManager; 12 13 use Smartling\Submissions\SubmissionManager; … … 23 24 SubmissionManager $submissionManager, 24 25 private UploadQueueManager $uploadQueueManager, 26 private WordpressFunctionProxyHelper $wpProxy, 25 27 int $throttleIntervalSeconds, 26 28 string $jobRunInterval, … … 43 45 $this->getLogger()->debug("Started $message"); 44 46 45 $this->processUploadQueue( );47 $this->processUploadQueue($this->wpProxy->get_current_blog_id()); 46 48 47 49 $this->processCloning(); … … 50 52 } 51 53 52 private function processUploadQueue( ): void54 private function processUploadQueue(int $blogId): void 53 55 { 56 $processed = 0; 54 57 $profiles = []; 55 while (($item = $this->uploadQueueManager->dequeue()) !== null) { 58 $max = $this->uploadQueueManager->length(); 59 while ($processed++ < $max) { 60 $item = $this->uploadQueueManager->dequeue($blogId); 61 if ($item === null) { 62 break; 63 } 56 64 $submission = $item->getSubmissions()[0]; 57 65 if ($submission->isCloned()) { -
smartling-connector/trunk/inc/config/cron.yml
r3333320 r3333344 28 28 - "@manager.submission" 29 29 - "@manager.upload.queue" 30 - "@wp.proxy" 30 31 - "%cron.interval.throttle%" 31 32 - "%cron.interval.upload%" … … 73 74 - "@manager.settings" 74 75 - "@manager.submission" 76 - "@wp.proxy" 75 77 - "%cron.interval.throttle%" 76 78 - "%cron.interval.download%" -
smartling-connector/trunk/readme.txt
r3333320 r3333344 5 5 Tested up to: 6.6.2 6 6 Requires PHP: 8.0 7 Stable tag: 3.12.17 Stable tag: 4.0.0 8 8 License: GPLv2 or later 9 9 … … 63 63 64 64 == Changelog == 65 = 4.0.0 = 66 * Reworked upload and download cron jobs to only work with submissions from the blog that initiates the cron job 67 65 68 = 3.12.1 = 66 69 * Fixed Elementor Templates type mismatch after translation or cloning with Elementor Pro -
smartling-connector/trunk/smartling-connector.php
r3333320 r3333344 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: 3.12.114 * Version: 4.0.0 15 15 * Author: Smartling 16 16 * Author URI: https://www.smartling.com
Note: See TracChangeset
for help on using the changeset viewer.