Skip to content

Commit f254ce4

Browse files
author
Rafael Grigorian
committed
Fixed GH-12
1 parent e9f6c37 commit f254ce4

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

src/app/code/JetRails/Varnish/Console/Command/Purge/Url.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use JetRails\Varnish\Console\Command\AbstractCommand;
66
use Symfony\Component\Console\Input\InputArgument;
77
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Input\InputOption;
89

910
/**
1011
* Url.php - This class inherits from the AbstractCommand. This command takes in a url and asks
@@ -35,7 +36,8 @@ protected function configure () {
3536
// Register the command and set the arguments
3637
$this->setName ("varnish:purge:url")
3738
->setDescription ("Purge specific url from varnish cache")
38-
->addArgument ( "url", InputArgument::REQUIRED, "What URL do you want to purge?" );
39+
->addArgument ( "url", InputArgument::REQUIRED, "What URL do you want to purge?" )
40+
->addOption ( "substring", null, InputOption::VALUE_NONE, "Purge all URLs that contain the given URL" );
3941
}
4042

4143
/**
@@ -51,12 +53,14 @@ protected function runCommand ( InputInterface $input ) {
5153
$url = $this->_purger->validateUrl ( $url );
5254
// If an object was returned, then it was a valid url
5355
if ( gettype ( $url ) == "object" ) {
56+
// Check to see if purge type is substring
57+
$purgeType = $input->getOption ("substring") ? "purgeStore" : "purgeUrl";
5458
// Initialize the accounting variables and payload array
5559
$total = 0;
5660
$success = 0;
5761
$payload = [];
5862
// Ask to purge and iterate over responses
59-
foreach ( $this->_purger->purgeUrl ( $url ) as $response ) {
63+
foreach ( $this->_purger->{ $purgeType } ( $url ) as $response ) {
6064
// Log what we are trying to do
6165
$message = [
6266
"status" => $response->status,
@@ -96,4 +100,4 @@ protected function runCommand ( InputInterface $input ) {
96100
return [ "status" => false, "message" => $url ];
97101
}
98102

99-
}
103+
}

src/app/code/JetRails/Varnish/Controller/Adminhtml/Purge/Url.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ public function execute () {
6666
// Load passed url parameter and validate it
6767
$url = $this->getRequest ()->getParam ("url");
6868
$url = $this->_purger->validateUrl ( $url );
69+
// Set they purge type based on passed value
70+
$isSubString = $this->getRequest ()->getParam ("type") === "substring";
6971
// If an object was returned, then it was a valid url
7072
if ( gettype ( $url ) == "object" ) {
7173
// Ask to purge and iterate over responses
72-
foreach ( $this->_purger->purgeUrl ( $url ) as $response ) {
74+
foreach ( $this->_purger->{ $isSubString ? "purgeStore" : "purgeUrl" } ( $url ) as $response ) {
7375
// Log what we are trying to do
7476
$message = [
7577
"status" => $response->status,
@@ -111,4 +113,4 @@ public function execute () {
111113
return $redirect->setPath ("adminhtml/cache/index");
112114
}
113115

114-
}
116+
}

src/app/code/JetRails/Varnish/view/adminhtml/templates/adminhtml/cache/index/cache_management.phtml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<span>Purge By URL:</span>
1313
<input type="text" placeholder="URL" name="url" />
1414
<button type="submit" ><span>Purge</span></button>
15+
<br>
16+
<select name="type" class="admin__control-select add-left-space" >
17+
<option value="exact" selected="selected" >Exact Match</option>
18+
<option value="substring" >Sub-String</option>
19+
</select>
1520
</form>
1621
<form method="post" action="<?= $block->getUrl ('varnish/purge/store') ?>" >
1722
<span>Purge By Store:</span>
@@ -26,4 +31,4 @@
2631
<span style="margin-right: 324px;" >Purge All:</span>
2732
<button type="submit" ><span>Purge</span></button>
2833
</form>
29-
</div>
34+
</div>
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
div.varnish-cache-management {
2-
padding-bottom: 15px;
2+
padding-bottom: 15px;
33
}
44

55
div.varnish-cache-management > form {
6-
margin-bottom: 10px;
6+
margin-bottom: 10px;
77
}
88

99
div.varnish-cache-management > form > span {
10-
position: relative;
11-
display: inline;
12-
float: left;
13-
width: 125px;
14-
line-height: 33px;
15-
margin: 0;
10+
position: relative;
11+
display: inline;
12+
float: left;
13+
width: 125px;
14+
line-height: 33px;
15+
margin: 0;
1616
}
1717

1818
div.varnish-cache-management > form > input[type=text] {
19-
min-width: 300px;
20-
margin-right: 20px;
21-
padding: 5px 10px;
19+
min-width: 300px;
20+
margin-right: 20px;
21+
padding: 5px 10px;
22+
}
23+
24+
div.varnish-cache-management > form > select.add-left-space {
25+
margin-left: 125px;
26+
margin-top: 10px;
2227
}
2328

2429
div.varnish-cache-management > form > select {
25-
min-width: 300px;
26-
margin-right: 20px;
27-
}
30+
min-width: 300px;
31+
margin-right: 20px;
32+
}

0 commit comments

Comments
 (0)