-
-
Notifications
You must be signed in to change notification settings - Fork 44
Allow cleaning namespace only #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
You changed some tabs to spaces, can you fix it and repush? |
Yeah sorry, didn't notice in my editor. |
There are still a lot of modifications in phpDoc which are not needed. |
OK, i will delete that later. I usually do that because phpStorm hints are broken when phpDoc is off, but i guess that is for different pull request anyway. |
OK, comments are back as they were and i added test, i wasn't sure with SQLite test, so i didn't do that one yet. PS: I had some problems with testing, is there some way to download whole nette package with tests? |
src/Caching/Storages/FileStorage.php
Outdated
} | ||
|
||
foreach ($namespaces as $namespace) { | ||
$dir = $this->dir . "/_$namespace"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be $dir = $this->dir . '/_' . urlencode($namespace);
src/Caching/Storages/FileStorage.php
Outdated
foreach ($namespaces as $namespace) { | ||
$dir = $this->dir . "/_$namespace"; | ||
if (is_dir($dir)) { | ||
$items = Nette\Utils\Finder::findFiles('')->from($dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findFiles('*') seems more readable
src/Caching/Storages/FileStorage.php
Outdated
foreach ($items as $item) { | ||
$this->delete((string) $item); | ||
} | ||
@rmdir($dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comment // may already contain new files
src/Caching/Storages/FileStorage.php
Outdated
@@ -249,6 +249,7 @@ public function clean(array $conditions): void | |||
{ | |||
$all = !empty($conditions[Cache::ALL]); | |||
$collector = empty($conditions); | |||
$namespaces = $conditions[Cache::NAMESPACE] ?? false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can convert it to array immediately, for example $namespace = (array) $conditions[Cache::NAMESPACE] ?? null;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, probably better name is NAMESPACES
to be consistent with TAGS
and FILES
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how you mean it with retyping it to array at top. It wouldn't work even if it were enclosed in brackets.
} | ||
|
||
foreach ($namespaces as $namespace) { | ||
$this->pdo->prepare("DELETE FROM cache WHERE key LIKE %/_$namespace/%")->execute(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is sql injection, it should be
$this->pdo->prepare('DELETE FROM cache WHERE key LIKE ?)')->execute([$namespace . Cache::NAMESPACE_SEPARATOR])
Good work! When you install it via Composer |
add test for cleaning SQLite namespace
Merged with a small modification, thanks! |
…rage & SqliteStorage [Closes #52]
Added option to clean only selected workspace. Repaired comments in changed files.