Skip to content

Commit 96561e1

Browse files
author
Rafael Grigorian
committed
Fixed #52
1 parent d67e78a commit 96561e1

File tree

5 files changed

+234
-6
lines changed

5 files changed

+234
-6
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace JetRails\Cloudflare\Console\Command\Caching\PurgeCache;
4+
5+
use JetRails\Cloudflare\Console\Command\AbstractCommand;
6+
use JetRails\Cloudflare\Model\Adminhtml\Api\Caching\PurgeCache;
7+
use Magento\Store\Model\StoreManagerInterface;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Input\InputOption;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class Host extends AbstractCommand {
13+
14+
protected $_storeManager;
15+
protected $_model;
16+
17+
public function __construct (
18+
StoreManagerInterface $storeManager,
19+
PurgeCache $model
20+
) {
21+
// Call the parent constructor
22+
parent::__construct ( $storeManager );
23+
// Save injected classes internally
24+
$this->_storeManager = $storeManager;
25+
$this->_model = $model;
26+
}
27+
28+
/**
29+
* Inside we set the command name and set the command description.
30+
* @return void
31+
*/
32+
protected function configure () {
33+
// Register the command and set the arguments
34+
$options = [
35+
new InputOption (
36+
"domain",
37+
null,
38+
InputOption::VALUE_REQUIRED,
39+
"What is the domain name?"
40+
),
41+
new InputOption (
42+
"host",
43+
null,
44+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
45+
"Host to purge from cache"
46+
)
47+
];
48+
$this
49+
->setName ("cloudflare:caching:purge-cache:host")
50+
->setDescription ("Purge hosts from Cloudflare cache")
51+
->setDefinition ( $options );
52+
parent::configure ();
53+
}
54+
55+
/**
56+
* This method is here because it interfaces with the abstract parent class. It takes in an
57+
* input and output interface and it runs the command.
58+
* @param InputInterface input The input interface
59+
* @param OutputInterface output The output interface
60+
* @return void
61+
*/
62+
public function runCommand ( InputInterface $input, OutputInterface $output ) {
63+
$old = $this->_storeManager->getStore ()->getId ();
64+
$domain = $input->getOption ("domain");
65+
$hosts = $input->getOption ("host");
66+
$store = $this->_getStoreByDomain ( $domain );
67+
$this->_storeManager->setCurrentStore ( $store->getId () );
68+
$response = $this->_model->purgeHosts ( $hosts );
69+
$this->_storeManager->setCurrentStore ( $old );
70+
if ( $this->_isSuccessful ( $response, $input, $output ) ) {
71+
$output->writeln ("Successfully purged hosts!");
72+
}
73+
}
74+
75+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace JetRails\Cloudflare\Console\Command\Caching\PurgeCache;
4+
5+
use JetRails\Cloudflare\Console\Command\AbstractCommand;
6+
use JetRails\Cloudflare\Model\Adminhtml\Api\Caching\PurgeCache;
7+
use Magento\Store\Model\StoreManagerInterface;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Input\InputOption;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class Prefix extends AbstractCommand {
13+
14+
protected $_storeManager;
15+
protected $_model;
16+
17+
public function __construct (
18+
StoreManagerInterface $storeManager,
19+
PurgeCache $model
20+
) {
21+
// Call the parent constructor
22+
parent::__construct ( $storeManager );
23+
// Save injected classes internally
24+
$this->_storeManager = $storeManager;
25+
$this->_model = $model;
26+
}
27+
28+
/**
29+
* Inside we set the command name and set the command description.
30+
* @return void
31+
*/
32+
protected function configure () {
33+
// Register the command and set the arguments
34+
$options = [
35+
new InputOption (
36+
"domain",
37+
null,
38+
InputOption::VALUE_REQUIRED,
39+
"What is the domain name?"
40+
),
41+
new InputOption (
42+
"prefix",
43+
null,
44+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
45+
"Prefix to purge from cache"
46+
)
47+
];
48+
$this
49+
->setName ("cloudflare:caching:purge-cache:prefix")
50+
->setDescription ("Purge prefixes from Cloudflare cache")
51+
->setDefinition ( $options );
52+
parent::configure ();
53+
}
54+
55+
/**
56+
* This method is here because it interfaces with the abstract parent class. It takes in an
57+
* input and output interface and it runs the command.
58+
* @param InputInterface input The input interface
59+
* @param OutputInterface output The output interface
60+
* @return void
61+
*/
62+
public function runCommand ( InputInterface $input, OutputInterface $output ) {
63+
$old = $this->_storeManager->getStore ()->getId ();
64+
$domain = $input->getOption ("domain");
65+
$prefixes = $input->getOption ("prefix");
66+
$store = $this->_getStoreByDomain ( $domain );
67+
$this->_storeManager->setCurrentStore ( $store->getId () );
68+
$response = $this->_model->purgePrefixes ( $prefixes );
69+
$this->_storeManager->setCurrentStore ( $old );
70+
if ( $this->_isSuccessful ( $response, $input, $output ) ) {
71+
$output->writeln ("Successfully purged prefixes!");
72+
}
73+
}
74+
75+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace JetRails\Cloudflare\Console\Command\Caching\PurgeCache;
4+
5+
use JetRails\Cloudflare\Console\Command\AbstractCommand;
6+
use JetRails\Cloudflare\Model\Adminhtml\Api\Caching\PurgeCache;
7+
use Magento\Store\Model\StoreManagerInterface;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Input\InputOption;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class Tag extends AbstractCommand {
13+
14+
protected $_storeManager;
15+
protected $_model;
16+
17+
public function __construct (
18+
StoreManagerInterface $storeManager,
19+
PurgeCache $model
20+
) {
21+
// Call the parent constructor
22+
parent::__construct ( $storeManager );
23+
// Save injected classes internally
24+
$this->_storeManager = $storeManager;
25+
$this->_model = $model;
26+
}
27+
28+
/**
29+
* Inside we set the command name and set the command description.
30+
* @return void
31+
*/
32+
protected function configure () {
33+
// Register the command and set the arguments
34+
$options = [
35+
new InputOption (
36+
"domain",
37+
null,
38+
InputOption::VALUE_REQUIRED,
39+
"What is the domain name?"
40+
),
41+
new InputOption (
42+
"tag",
43+
null,
44+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
45+
"Tag to purge from cache"
46+
)
47+
];
48+
$this
49+
->setName ("cloudflare:caching:purge-cache:tag")
50+
->setDescription ("Purge tags from Cloudflare cache")
51+
->setDefinition ( $options );
52+
parent::configure ();
53+
}
54+
55+
/**
56+
* This method is here because it interfaces with the abstract parent class. It takes in an
57+
* input and output interface and it runs the command.
58+
* @param InputInterface input The input interface
59+
* @param OutputInterface output The output interface
60+
* @return void
61+
*/
62+
public function runCommand ( InputInterface $input, OutputInterface $output ) {
63+
$old = $this->_storeManager->getStore ()->getId ();
64+
$domain = $input->getOption ("domain");
65+
$tags = $input->getOption ("tag");
66+
$store = $this->_getStoreByDomain ( $domain );
67+
$this->_storeManager->setCurrentStore ( $store->getId () );
68+
$response = $this->_model->purgeTags ( $tags );
69+
$this->_storeManager->setCurrentStore ( $old );
70+
if ( $this->_isSuccessful ( $response, $input, $output ) ) {
71+
$output->writeln ("Successfully purged tags!");
72+
}
73+
}
74+
75+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Symfony\Component\Console\Input\InputOption;
1010
use Symfony\Component\Console\Output\OutputInterface;
1111

12-
class Individual extends AbstractCommand {
12+
class Url extends AbstractCommand {
1313

1414
protected $_storeManager;
1515
protected $_model;
@@ -46,8 +46,8 @@ protected function configure () {
4646
)
4747
];
4848
$this
49-
->setName ("cloudflare:caching:purge-cache:individual")
50-
->setDescription ("Purge individual URL from Cloudflare cache")
49+
->setName ("cloudflare:caching:purge-cache:url")
50+
->setDescription ("Purge URLs from Cloudflare cache")
5151
->setDefinition ( $options );
5252
parent::configure ();
5353
}
@@ -65,10 +65,10 @@ public function runCommand ( InputInterface $input, OutputInterface $output ) {
6565
$urls = $input->getOption ("url");
6666
$store = $this->_getStoreByDomain ( $domain );
6767
$this->_storeManager->setCurrentStore ( $store->getId () );
68-
$response = $this->_model->purgeIndividual ( $urls );
68+
$response = $this->_model->purgeUrls ( $urls );
6969
$this->_storeManager->setCurrentStore ( $old );
7070
if ( $this->_isSuccessful ( $response, $input, $output ) ) {
71-
$output->writeln ("Successfully purged individual urls!");
71+
$output->writeln ("Successfully purged urls!");
7272
}
7373
}
7474

src/app/code/JetRails/Cloudflare/etc/di.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
<item name="cloudflare:caching:development-mode:get" xsi:type="object" >JetRails\Cloudflare\Console\Command\Caching\DevelopmentMode\Get</item>
1111
<item name="cloudflare:caching:development-mode:set" xsi:type="object" >JetRails\Cloudflare\Console\Command\Caching\DevelopmentMode\Set</item>
1212
<item name="cloudflare:caching:purge-cache:everything" xsi:type="object" >JetRails\Cloudflare\Console\Command\Caching\PurgeCache\Everything</item>
13-
<item name="cloudflare:caching:purge-cache:individual" xsi:type="object" >JetRails\Cloudflare\Console\Command\Caching\PurgeCache\Individual</item>
13+
<item name="cloudflare:caching:purge-cache:url" xsi:type="object" >JetRails\Cloudflare\Console\Command\Caching\PurgeCache\Url</item>
14+
<item name="cloudflare:caching:purge-cache:host" xsi:type="object" >JetRails\Cloudflare\Console\Command\Caching\PurgeCache\Host</item>
15+
<item name="cloudflare:caching:purge-cache:tag" xsi:type="object" >JetRails\Cloudflare\Console\Command\Caching\PurgeCache\Tag</item>
16+
<item name="cloudflare:caching:purge-cache:prefix" xsi:type="object" >JetRails\Cloudflare\Console\Command\Caching\PurgeCache\Prefix</item>
1417
</argument>
1518
</arguments>
1619
</type>

0 commit comments

Comments
 (0)