fix: prevent file deletion on relink + restore button now visible + OOB-style in-place update

Two critical fixes:

1. Relink flow no longer destroys/recreates FilePond instances:
   The relink (XamxamRelinkFile) and PeerTube relink (XamxamRelinkPeerTube)
   previously refreshed the entire fichiers fragment via HTMX after
   pond.addFile(). This triggered destroyFilePondsIn on ALL pools, which
   could fire server.remove callbacks and move existing files to corbeille.
   Now just closes the modal — the file is already added to the pool in-place,
   and syncOrderInput creates the hidden form input.

2. Cleanup page « Corbeille (restaurable) » now actually shows files:
   _cleanup-stats-data.php previously classified trash files by checking if
   the thesis_files DB row still existed. But both deleteThesisFileToTrash
   and FilepondHandler::handleRemove DELETE the DB row. So ALL trash files
   appeared as `stale` (not restorable). Now uses the JSON sidecar file
   presence as the classification criterion — if the sidecar exists and is
   recent, the file is restorable regardless of DB row state.

Also removed unused DB query from _cleanup-stats-data.php.
This commit is contained in:
Pontoporeia
2026-07-10 16:29:04 +02:00
parent ed19e30cf0
commit 3cecee10c9
12 changed files with 587 additions and 73 deletions
+89
View File
@@ -38,6 +38,17 @@ class PureLogicTest extends TestCase
};
}
/**
* Invoke the private hasFilePondQueueData() method via reflection.
* The method lives in the ThesisFileHandler trait, used by ThesisCreateController.
*/
private function invokeHasFilePondQueueData(array $post): bool
{
$ctrl = $this->getThesisCreateController();
$ref = new ReflectionMethod(ThesisCreateController::class, 'hasFilePondQueueData');
return $ref->invoke($ctrl, $post);
}
// ── splitJuryByRole ──────────────────────────────────────────────────────
public function testSplitJuryByRoleAllRoles(): void
@@ -150,4 +161,82 @@ class PureLogicTest extends TestCase
$this->assertSame('image', $ctrl->exposedDetectFileType('application/octet-stream', 'webp'));
$this->assertSame('caption', $ctrl->exposedDetectFileType('application/octet-stream', 'vtt'));
}
// ── hasFilePondQueueData ────────────────────────────────────────────────
public function testHasFilePondQueueDataReturnsTrueForHexId(): void
{
$post = ['queue_file' => ['tfe' => ['abc123def456abc123def456abc123de']]];
$this->assertTrue($this->invokeHasFilePondQueueData($post));
}
public function testHasFilePondQueueDataReturnsTrueForPeertubeVideo(): void
{
$post = ['queue_file' => ['tfe' => ['peertube:video:bmpQZTUPv4ou8ufiwajV63']]];
$this->assertTrue(
$this->invokeHasFilePondQueueData($post),
'peertube:video:UUID should be detected as FilePond data'
);
}
public function testHasFilePondQueueDataReturnsTrueForPeertubeAudio(): void
{
$post = ['queue_file' => ['tfe' => ['peertube:audio:xyz123']]];
$this->assertTrue(
$this->invokeHasFilePondQueueData($post),
'peertube:audio:UUID should be detected as FilePond data'
);
}
public function testHasFilePondQueueDataReturnsTrueForMixedIds(): void
{
$post = ['queue_file' => ['tfe' => ['123', 'peertube:video:abc123', '456']]];
$this->assertTrue(
$this->invokeHasFilePondQueueData($post),
'Mixed array containing a peertube: ID should be detected'
);
}
public function testHasFilePondQueueDataReturnsTrueForHexInCoverQueue(): void
{
$post = ['queue_file' => ['cover' => ['abcdef1234567890abcdef1234567890']]];
$this->assertTrue($this->invokeHasFilePondQueueData($post));
}
public function testHasFilePondQueueDataReturnsTrueForPeertubeInCoverQueue(): void
{
$post = ['queue_file' => ['cover' => ['peertube:video:uuid1']]];
$this->assertTrue($this->invokeHasFilePondQueueData($post));
}
public function testHasFilePondQueueDataReturnsFalseForNumericIdsOnly(): void
{
$post = ['queue_file' => ['tfe' => ['123', '456']]];
$this->assertFalse($this->invokeHasFilePondQueueData($post));
}
public function testHasFilePondQueueDataReturnsFalseForEmptyInput(): void
{
$this->assertFalse($this->invokeHasFilePondQueueData([]));
$this->assertFalse($this->invokeHasFilePondQueueData(['queue_file' => []]));
$this->assertFalse($this->invokeHasFilePondQueueData(['queue_file' => ['tfe' => []]]));
}
public function testHasFilePondQueueDataReturnsFalseForEmptyStrings(): void
{
$post = ['queue_file' => ['tfe' => ['', ' ']]];
$this->assertFalse($this->invokeHasFilePondQueueData($post));
}
public function testHasFilePondQueueDataHandlesScalarNotArray(): void
{
$post = ['queue_file' => ['tfe' => 'peertube:video:singleUuid']];
$this->assertTrue($this->invokeHasFilePondQueueData($post));
$post2 = ['queue_file' => ['tfe' => 'abc123def456abc123def456abc123de']];
$this->assertTrue($this->invokeHasFilePondQueueData($post2));
$post3 = ['queue_file' => ['tfe' => '123']];
$this->assertFalse($this->invokeHasFilePondQueueData($post3));
}
}