Skip to content

Commit

Permalink
Add href at db-path-provider. (#13)
Browse files Browse the repository at this point in the history
* Add href at db-path-provider.

* Quote special char

* Fix pattern for additional parameter
  • Loading branch information
zonky2 authored Dec 3, 2024
1 parent 1275fac commit 27f2e47
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Provider/DatabasePathProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
use InspiredMinds\ContaoFileUsage\Result\ResultsCollection;

/**
* Searches the database for file references.
* Searches the database for file references in attributes href and src.
*/
class DatabasePathProvider extends AbstractDatabaseProvider
{
private string $pathPattern = '~src\s*=\s*"(__contao_upload_path__/.+?)"~';
private string $pathPattern = '~(href|src)\s*=\s*"(__contao_upload_path__/.+?)([?"])~';

public function __construct(
Connection $db,
Expand All @@ -35,7 +35,7 @@ public function __construct(
string $uploadPath,
array $ignoreTables,
) {
$this->pathPattern = str_replace('__contao_upload_path__', $uploadPath, $this->pathPattern);
$this->pathPattern = str_replace('__contao_upload_path__', preg_quote($uploadPath, '~'), $this->pathPattern);

parent::__construct($db, $ignoreTables);
}
Expand Down Expand Up @@ -85,7 +85,7 @@ private function findPathReferences(ResultsCollection $collection, string $table
}

if (preg_match_all($this->pathPattern, $data, $matches)) {
foreach ($matches[1] ?? [] as $path) {
foreach ($matches[2] ?? [] as $path) {
$file = FilesModel::findByPath(urldecode($path));

if (null === $file) {
Expand Down

0 comments on commit 27f2e47

Please sign in to comment.