Skip to content

Submit related content selected on the Bulk Submit page (WP-1027) - #640

Open
achursin-smartling wants to merge 1 commit into
masterfrom
WP-1027-bulk-submit-related
Open

achursin-smartling wants to merge 1 commit into
masterfrom
WP-1027-bulk-submit-related

Conversation

@achursin-smartling

Copy link
Copy Markdown

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: in ContentRelationsDiscoveryService::createSubmissions, the isBulk() branch called bulkUpload() 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

  • The bulk branch now also submits the related items from relations, per target blog, through bulkUpload() 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.
  • Queueing moved into a private enqueueBulk() (no behavior change), so the main items and related items go into one batch.
  • bulkUpload() merged the menu item queue IDs with ArrayHelper::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 uses array_merge.
  • Changelog entry under 5.8.3 in readme.txt, and version bumped to 5.8.3 (composer.json, smartling-connector.php, readme.txt stable tag).

Tests

Added ContentRelationsDiscoveryServiceTest::testBulkSubmitHandlerSubmitsSelectedRelations. Not run locally (no PHP environment available), please rely on CI.

Jira: WP-1027

🤖 Generated with Claude Code

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 sl-mmuradov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review for WP-1027: 4 findings (2 High, 2 Medium).

));
}
}
$this->enqueueBulk($queueIds, $profile, $jobInfo, $authorize);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure here again, do we still use the audit log service? Maybe we should remove the audit logs from the connector entirely?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants