Skip to content

[#168] Fix fileid backfill and save_error for chunked file docids - #169

Merged
dmitriim merged 3 commits into
catalyst:MOODLE_404_STABLEfrom
tsmilan:issue-168
Jul 21, 2026
Merged

dmitriim merged 3 commits into
catalyst:MOODLE_404_STABLEfrom
tsmilan:issue-168

Conversation

@tsmilan

@tsmilan tsmilan commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Testing Instructions

Verify the upgrade backfill

  1. On a test site, insert some rows in search_elastic_errors to cover each case (or use ones already there from testing chunking):
  • docid = '123' (plain file, not chunked) → should backfill to fileid = 123
  • docid = '123_c1' (chunked file) → should backfill to fileid = 123
  • docid = 'mod_assign-activity-123' (non-file) → fileid stays null
  • docid = 'mod_assign-activity-123_c1' (non-file, chunked) → fileid stays null
  1. Set the plugin version back below 2026051405 and navigate to <moodlesite>/admin/index.php (or CLI upgrade) to trigger the upgrade step, then check the fileid column matches the expectations above.

Comment thread db/upgrade.php Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Version doesn't match. Should be 2026051405

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated :)

Comment thread db/upgrade.php Outdated
}
$rs->close();

upgrade_plugin_savepoint(true, 2026051404, 'search', 'elastic');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Version doesn't match. Should be 2026051405

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated :)

@dmitriim dmitriim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please fix version mismatch. Otherwise looks good.

@dmitriim dmitriim self-assigned this Jul 20, 2026
@dmitriim
dmitriim self-requested a review July 20, 2026 23:42

Copilot AI 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.

Pull request overview

This PR updates the search_elastic plugin’s error tracking to correctly derive/backfill fileid from chunked file document IDs (e.g. 123_c1), ensuring both upgrade-time backfill and runtime save_error() behavior work with chunked docids.

Changes:

  • Bumps plugin version to trigger a new upgrade step.
  • Updates the upgrade backfill logic to correctly parse numeric + chunk-suffix docids and populate search_elastic_errors.fileid.
  • Updates error_service::save_error() to derive fileid via a dedicated helper and adds PHPUnit coverage for the docid→fileid mapping.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
version.php Bumps plugin version to run the new upgrade step.
db/upgrade.php Adjusts fileid backfill to handle chunked docids safely.
classes/local/service/error_service.php Uses a helper to extract fileid from chunked/plain file docids.
tests/local/service/error_service_test.php Adds tests covering fileid extraction for multiple docid formats.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread db/upgrade.php Outdated
Comment on lines +127 to +135
$select = $DB->sql_like('docid', ':pattern', true, true, true);
$rs = $DB->get_recordset_select('search_elastic_errors', $select, ['pattern' => '%-%']);
foreach ($rs as $record) {
if (preg_match('/^(\d+)(?:_c\d+)?$/', $record->docid, $matches)) {
$record->fileid = (int) $matches[1];
$DB->update_record('search_elastic_errors', $record);
}
}
$rs->close();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @dmitriim I've updated the code as per copilot feedback :)

Comment thread classes/local/service/error_service.php Outdated
Comment on lines +148 to +153
private static function extract_fileid($documentid): ?int {
if (preg_match('/^(\d+)(?:_c\d+)?$/', (string)$documentid, $matches)) {
return (int) $matches[1];
}
return null;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @dmitriim I've updated the code as per copilot feedback :)

@dmitriim

Copy link
Copy Markdown
Member

@tsmilan can you please have a look at comments raised by AI review and action if it makes sense.

@dmitriim
dmitriim merged commit bf1a053 into catalyst:MOODLE_404_STABLE Jul 21, 2026
20 checks passed
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