Plugin Directory

Changeset 3333344


Ignore:
Timestamp:
07/24/2025 07:58:19 AM (8 months ago)
Author:
smartling
Message:

Update to v 4.0.0

Location:
smartling-connector/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • smartling-connector/trunk/inc/Smartling/DbAl/UploadQueueManager.php

    r3132239 r3333344  
    4141    }
    4242
    43     public function dequeue(): ?UploadQueueItem
     43    public function dequeue(int $blogId): ?UploadQueueItem
    4444    {
    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'
     49select 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
     52SQL,
     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]);
    5664            $locales = new IntStringPairCollection();
    5765            $submissions = [];
    58             foreach(IntegerIterator::fromString($result[UploadQueueEntity::FIELD_SUBMISSION_IDS]) as $submissionId) {
     66            foreach (IntegerIterator::fromString($row[UploadQueueEntity::FIELD_SUBMISSION_IDS]) as $submissionId) {
    5967                $submission = $this->submissionManager->getEntityById($submissionId);
    6068                if ($submission === null) {
     
    7179            }
    7280
    73             return new UploadQueueItem($submissions, $batchUid, $locales);
     81            return new UploadQueueItem($submissions, $row[UploadQueueEntity::FIELD_BATCH_UID], $locales);
    7482        }
    7583
     
    104112            }
    105113        });
     114    }
     115
     116    public function length(): int
     117    {
     118        return (int)$this->db->getRowArray("SELECT COUNT(*) cnt FROM $this->tableName")['cnt'];
    106119    }
    107120
     
    162175        $this->db->query(QueryBuilder::buildDeleteQuery($this->tableName, $block));
    163176    }
     177
    164178}
  • smartling-connector/trunk/inc/Smartling/Jobs/DownloadTranslationJob.php

    r3333320 r3333344  
    77use Smartling\Helpers\ArrayHelper;
    88use Smartling\Helpers\Cache;
     9use Smartling\Helpers\WordpressFunctionProxyHelper;
    910use Smartling\Queue\QueueInterface;
    1011use Smartling\Settings\SettingsManager;
     
    2021        SettingsManager $settingsManager,
    2122        SubmissionManager $submissionManager,
     23        private WordpressFunctionProxyHelper $wpProxy,
    2224        int $throttleIntervalSeconds,
    2325        string $jobRunInterval,
     
    3638        $this->getLogger()->debug('Started Translation Download Job.');
    3739
    38         $this->processDownloadQueue();
     40        $this->processDownloadQueue($this->wpProxy->get_current_blog_id());
    3941
    4042        $this->getLogger()->debug('Finished Translation Download Job.');
    4143    }
    4244
    43     private function processDownloadQueue(): void
     45    private function processDownloadQueue(int $blogId): void
    4446    {
    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);
    4856
    49             if (0 < count($result)) {
    50                 $entity = ArrayHelper::first($result);
    51             } else {
     57            if ($entity === null) {
    5258                $this->getLogger()
    5359                    ->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);
    5464                continue;
    5565            }
  • smartling-connector/trunk/inc/Smartling/Jobs/UploadJob.php

    r3333320 r3333344  
    99use Smartling\Helpers\Cache;
    1010use Smartling\Helpers\FileUriHelper;
     11use Smartling\Helpers\WordpressFunctionProxyHelper;
    1112use Smartling\Settings\SettingsManager;
    1213use Smartling\Submissions\SubmissionManager;
     
    2324        SubmissionManager $submissionManager,
    2425        private UploadQueueManager $uploadQueueManager,
     26        private WordpressFunctionProxyHelper $wpProxy,
    2527        int $throttleIntervalSeconds,
    2628        string $jobRunInterval,
     
    4345        $this->getLogger()->debug("Started $message");
    4446
    45         $this->processUploadQueue();
     47        $this->processUploadQueue($this->wpProxy->get_current_blog_id());
    4648
    4749        $this->processCloning();
     
    5052    }
    5153
    52     private function processUploadQueue(): void
     54    private function processUploadQueue(int $blogId): void
    5355    {
     56        $processed = 0;
    5457        $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            }
    5664            $submission = $item->getSubmissions()[0];
    5765            if ($submission->isCloned()) {
  • smartling-connector/trunk/inc/config/cron.yml

    r3333320 r3333344  
    2828      - "@manager.submission"
    2929      - "@manager.upload.queue"
     30      - "@wp.proxy"
    3031      - "%cron.interval.throttle%"
    3132      - "%cron.interval.upload%"
     
    7374      - "@manager.settings"
    7475      - "@manager.submission"
     76      - "@wp.proxy"
    7577      - "%cron.interval.throttle%"
    7678      - "%cron.interval.download%"
  • smartling-connector/trunk/readme.txt

    r3333320 r3333344  
    55Tested up to: 6.6.2
    66Requires PHP: 8.0
    7 Stable tag: 3.12.1
     7Stable tag: 4.0.0
    88License: GPLv2 or later
    99
     
    6363
    6464== 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
    6568= 3.12.1 =
    6669* Fixed Elementor Templates type mismatch after translation or cloning with Elementor Pro
  • smartling-connector/trunk/smartling-connector.php

    r3333320 r3333344  
    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:           3.12.1
     14 * Version:           4.0.0
    1515 * Author:            Smartling
    1616 * Author URI:        https://www.smartling.com
Note: See TracChangeset for help on using the changeset viewer.