Skip to content

Commit

Permalink
removed obsolete cache cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
akaunderr committed Dec 29, 2023
1 parent c9139cb commit 4f34406
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.0.3 (2023.12.29)
### Removed
- Obsolete cache cleanup.

## 0.0.2 (2023.12.28)
### Fixed
- Error message while log (by null coalescing).
Expand Down
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# To-Do

- Obsolete cache cleanup. It is necessary to decide whether it is needed or whether to run it from the outside...
39 changes: 6 additions & 33 deletions src/ShrinkWrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,6 @@ private function minRefByType(string $type = 'js'): void {
$minifier = $this->{$type . 'Minifier'}->init();
$minifier->add($fname);
$minifier->minify($mfile);

$this->clearPrev($fname);
}

if ($this->doLog) {
Expand All @@ -444,8 +442,6 @@ private function minRefByType(string $type = 'js'): void {
}

$minifier->minify($mfile);

$this->clearPrev($mfile);
}

if ($this->doLog) {
Expand Down Expand Up @@ -473,48 +469,25 @@ private function minRefByType(string $type = 'js'): void {
}

/**
* Returns the full path and name of the minified file.
* Returns path to minified file by source file name.
*
* @param string $fname The name of a file that will be minified
* @param string $file Name or full path of a file to be minified
*
* @return string The name of the minified file
* @return string Minified file path
*/
private function getMfile(string $fname): string {
$finfo = pathinfo($fname);
private function getMfile(string $file): string {
$finfo = pathinfo($file);

if (preg_match('/[0-9a-f]{32}/i', explode('.', $finfo['filename'])[0])) {
$finfo['filename'] = explode('.', $finfo['filename'])[0];
$tmpl = '.min.' . $finfo['extension'];
} else {
$tmpl = '_' . filemtime($fname) . '.min.' . $finfo['extension'];
$tmpl = '_' . filemtime($file) . '.min.' . $finfo['extension'];
}

return $this->assetDir . $finfo['filename'] . $tmpl;
}

/**
* Clear out of date minified files.
*
* @param string (optional) $fname File name to delete from cache
*/
private function clearPrev(string $fname = ''): void {
if ($fname) {
$finfo = pathinfo($fname);

if (preg_match('/[0-9a-f]{32}/i', $finfo['filename'])) {
$files = glob($this->assetDir . '*.' . $finfo['extension']);
} else {
$files = glob($this->assetDir . $finfo['filename'] . '*.' . $finfo['extension']);
}

foreach ($files as $file) {
if (is_file($file) && $file != $this->getMfile($fname)) {
@unlink($file);
}
}
}
}

/**
* @param string[] $files File list
*
Expand Down

0 comments on commit 4f34406

Please sign in to comment.