Skip to content

Share one recursive delete and validate hashes before deleting - #141

Merged
erseco merged 1 commit into
feature/make-up-offlinefrom
feature/extraction-helpers
Sep 26, 2026
Merged

erseco merged 1 commit into
feature/make-up-offlinefrom
feature/extraction-helpers

Conversation

@erseco

@erseco erseco commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #140.

One recursive delete, and hash-validated deletes

  • Shared delete helper:
    • The upload handler and the reprocessor each had a private copy of the recursive delete that ExeLearning_Styles_Service already exposes publicly. They now call that one.
    • It stops on an unreadable directory instead of passing scandir()'s false to array_diff(), which is a TypeError on PHP 8.
  • Hash validation:
    • Problem: exelearning_delete_extracted_folder() (on delete_attachment) and ExeLearning_Reprocessor::cleanup_by_hash() deleted whatever folder the stored value or argument named. A _exelearning_extracted value of .. resolved to uploads/ itself.
    • Fix: both now act only on a well-formed 40-character hash (ExeLearning_Content_Hash_Aliases::is_valid_hash()), which is all the plugin ever writes.

The REST controller's own copy is removed with the rest of its dead code in the next PR.

Tests

  • New test: a malformed hash (..) never deletes the extraction root.
  • Tests that reflected on the removed private method were dropped.
  • Full suite: OK (950 tests).

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Test in WordPress Playground

Test the plugin with the code from this branch:

Preview in WordPress Playground

ℹ️ The eXeLearning editor is fetched from the shared release and unpacked into the plugin when the playground boots, so the first load may take a few extra seconds. ELP upload, shortcode, Gutenberg block and preview work normally.

@codecov-commenter

codecov-commenter commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.86%. Comparing base (0fd11b7) to head (93abef9).

Files with missing lines Patch % Lines
includes/class-styles-service.php 75.00% 1 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                      @@
##             feature/make-up-offline     #141      +/-   ##
=============================================================
- Coverage                      96.87%   96.86%   -0.02%     
+ Complexity                       864      855       -9     
=============================================================
  Files                             39       39              
  Lines                           4324     4308      -16     
=============================================================
- Hits                            4189     4173      -16     
  Misses                           135      135              
Flag Coverage Δ
javascript 95.71% <ø> (ø)
php 97.23% <88.88%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
includes/class-elp-reprocessor.php 99.36% <100.00%> (+0.56%) ⬆️
includes/class-elp-upload-handler.php 100.00% <100.00%> (ø)
includes/class-styles-service.php 96.34% <75.00%> (-0.38%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@erseco
erseco added this pull request to stack #144 September 26, 2026 07:38
@erseco
erseco force-pushed the feature/extraction-helpers branch from 6af4445 to 2509397 Compare September 26, 2026 07:43
@erseco
erseco force-pushed the feature/extraction-helpers branch from 2509397 to 0cc18b2 Compare September 26, 2026 08:01
The upload handler and the reprocessor each carried a private copy of the
recursive delete already public on ExeLearning_Styles_Service; use that one,
and have it stop on an unreadable directory instead of passing scandir()'s
false to array_diff().

Deleting an attachment removed whatever folder its _exelearning_extracted
meta named, and cleanup_by_hash() whatever hash it was given, without checking
that the value is an extraction hash; '..' resolved to uploads/ itself. Both
now act only on a well-formed 40-character hash, which is all the plugin ever
writes.
@erseco
erseco force-pushed the feature/extraction-helpers branch from 0cc18b2 to 93abef9 Compare September 26, 2026 08:29
@erseco
erseco merged commit d9b1fb1 into main Sep 26, 2026
5 checks passed
@erseco
erseco deleted the feature/extraction-helpers branch September 26, 2026 08:47
erseco added a commit that referenced this pull request Sep 26, 2026
…locks (#146)

Since #141 the upload handler, the reprocessor and most tests deleted
extraction folders through ExeLearning_Styles_Service::recursive_delete(),
which made shared filesystem cleanup look like a styles concern. Move it,
unchanged, to a small ExeLearning_Filesystem class and update every caller;
its two tests move to FilesystemTest.

Also bring comments in line with the code: file-service, upload-handler,
upload-block and editor docblocks said .elp although only .elpx packages are
accepted; drop a boilerplate 'optionally unlink the original' note; and fix a
REST docblock that still compared against the removed cleanup_old_extraction().
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.

2 participants