Repository navigation
Submit related content selected on the Bulk Submit page (WP-1027) - #640
achursin-smartling wants to merge 1 commit into
Conversation
The bulk branch of createSubmissions() ignored the relations sent by the job wizard since WP-973, so e.g. featured images were never submitted. Also fix menu item queue ids being dropped by the key-based array union. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sl-mmuradov
left a comment
There was a problem hiding this comment.
Code review for WP-1027: 4 findings (2 High, 2 Medium).
| )); | ||
| } | ||
| } | ||
| $this->enqueueBulk($queueIds, $profile, $jobInfo, $authorize); |
There was a problem hiding this comment.
[High] Enqueueing is deferred to the end, so a failure leaves submissions stuck in NEW.
The primary items are stored as NEW with the job info. If any later relation bulkUpload throws (bad content type, DB error, failure in getTitle/generateFileUri), enqueueBulk is never reached. The user sees an error, the submissions stay in NEW, are never uploaded, and no batch is created. Before this change the primary items were enqueued before any relation was processed.
Consider enqueueing the primary items first, or wrapping the relations loop in try/finally so whatever was created still gets enqueued.
There was a problem hiding this comment.
Persisting as new, creating the batch and enqueueing is how the plugin works. A failure in the middle is recoverable by resubmitting, this approach is used everywhere in the connector. If resubmitting fails consistently, it would mean that there's something that need fixing. Adding a try/finally could ultimately fail, we could use try/catch (\Throwable $e) {enqueueBulk(...); throw $e} to avoid masking the original exception, but I don't think this prevents merging.
| if (count($ids) === 0) { | ||
| continue; | ||
| } | ||
| $queueIds = array_merge($queueIds, $this->bulkUpload( |
There was a problem hiding this comment.
[High] Related items go through bulkUpload, which force-resets existing submissions.
bulkUpload resets every existing submission to NEW, clears the cloned flag and re-stamps the profile. That is right for the explicit bulk selection, but not for implicit related content. If a related attachment or term already has a COMPLETED or IN_PROGRESS submission for the target blog, it is silently reset to NEW and re-uploaded. A cloned submission loses its cloned flag, and a submission under a different profile is re-stamped.
Consider a code path for relations that only creates missing submissions, or one that skips existing ones, as the single-item flow does.
There was a problem hiding this comment.
This is fine, a manual upload request should be honored regardless of the status, it should reset to new and stamp the requested profile. Losing the cloned flag is ok because cloning is obsolete.
| } | ||
| $queueIds = array_merge($queueIds, $this->bulkUpload( | ||
| $authorize, | ||
| array_map('intval', array_values($ids)), |
There was a problem hiding this comment.
[Medium] Relation content types and ids from the request are not validated.
The $contentType key (line 178) and the ids come from the request. array_map('intval', ...) turns non-numeric ids such as 'abc' into 0, and an unknown type string reaches getSubmissionEntity/generateFileUri/getTitle. That can throw midway or create junk submissions for ID 0 or an unregistered type. The single-item path resolves relations through discovery services, so it does not accept arbitrary input like this.
Suggest validating the type against the registered content types, and dropping ids that are not positive integers, before calling bulkUpload.
There was a problem hiding this comment.
The way WP works it's possible to have registered content types at enqueue time and fail at the upload time, this is a non-issue. Dropping the ids that are 0 after intval is done might be a good idea.
| @@ -157,14 +162,39 @@ public function createSubmissions(UserTranslationRequest $request): void | |||
| $jobInfo = new JobEntity($job->getName(), $job->getId(), $profile->getProjectId()); | |||
|
|
|||
| if ($request->isBulk()) { | |||
There was a problem hiding this comment.
[Medium] The bulk branch writes no audit log record.
The non-bulk path below calls createAuditLogRecord, including relatedContentIds. This bulk branch now submits related content but records nothing, so the related ids sent to Smartling are not tracked. Suggest writing an audit record here with the primary ids and the related ids per target blog.
There was a problem hiding this comment.
Not sure here again, do we still use the audit log service? Maybe we should remove the audit logs from the connector entirely?
Problem
Since WP-973 (5.1.0) the Bulk Submit job wizard loads related content (featured images, terms, …) for the selected items and sends the user's selection as
relations. The backend ignored it: inContentRelationsDiscoveryService::createSubmissions, theisBulk()branch calledbulkUpload()with only the selected IDs and returned. Related content selected on Bulk Submit was never submitted, so for example featured images stayed unmapped on the target site.Fix
relations, per target blog, throughbulkUpload()so existing submissions are reused. They are queued in the same batch as the selected items. Related IDs that are themselves bulk-selected items of the same type are skipped.enqueueBulk()(no behavior change), so the main items and related items go into one batch.bulkUpload()merged the menu item queue IDs withArrayHelper::add(), which unions by key ([1] + [2, 3, 4]gives[1, 3, 4]), so some menu item submissions were stored but never queued. It now usesarray_merge.readme.txt, and version bumped to 5.8.3 (composer.json,smartling-connector.php,readme.txtstable tag).Tests
Added
ContentRelationsDiscoveryServiceTest::testBulkSubmitHandlerSubmitsSelectedRelations. Not run locally (no PHP environment available), please rely on CI.Jira: WP-1027
🤖 Generated with Claude Code