forked from fbrnc/Aoe_Static
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fbrnc#16 from AOEpeople/feature/purge_via_sns
Feature/purge via sns
- Loading branch information
Showing
6 changed files
with
205 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/** | ||
* Class Aoe_Static_Model_Cache_Adapter_Sns | ||
*/ | ||
class Aoe_Static_Model_Cache_Adapter_Sns extends Aoe_Static_Model_Cache_Adapter_Varnish | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $snsTopic; | ||
|
||
/** | ||
* @var \Aws\Sns\SnsClient | ||
*/ | ||
protected $snsClient; | ||
|
||
|
||
public function getSnsTopic() | ||
{ | ||
if (is_null($this->snsTopic)) { | ||
$this->snsTopic = Mage::getStoreConfig('dev/aoestatic/snsTopic'); | ||
if (empty($this->snsTopic)) { | ||
throw new Exception('Invalid SNS topic'); | ||
} | ||
} | ||
return $this->snsTopic; | ||
} | ||
|
||
public function getSnsClient() | ||
{ | ||
if (is_null($this->snsClient)) { | ||
|
||
$file = Mage::getBaseDir('lib') . DS . 'AwsSdk' . DS . 'autoload.php'; | ||
if (!is_file($file)) { | ||
throw new Exception('Please install Mage_AwsSdk'); | ||
} | ||
require_once $file; | ||
|
||
// use EC2 instance profile of ENV vars to configure the client | ||
$this->snsClient = new \Aws\Sns\SnsClient([ | ||
'version' => '2010-03-31', | ||
'region' => Mage::getStoreConfig('dev/aoestatic/snsRegion') | ||
]); | ||
} | ||
return $this->snsClient; | ||
} | ||
|
||
protected function sendRequests(array $actions) | ||
{ | ||
Mage::log('[Aoe_Static SNS] Public SNS message'); | ||
$this->getSnsClient()->publish([ | ||
'Message' => json_encode($actions), | ||
'Subject' => 'Aoe_Static', | ||
'TopicArn' => $this->getSnsTopic(), | ||
]); | ||
return array(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
require_once 'abstract.php'; | ||
|
||
class Aoe_Static_Shell extends Mage_Shell_Abstract | ||
{ | ||
|
||
public function purgeAllAction() | ||
{ | ||
$errors = Mage::helper('aoestatic')->purgeAll(); | ||
var_dump($errors); | ||
} | ||
|
||
/** | ||
* Run script | ||
*/ | ||
public function run() | ||
{ | ||
$action = $this->getArg('action'); | ||
if (empty($action)) { | ||
echo $this->usageHelp(); | ||
} else { | ||
$actionMethodName = $action . 'Action'; | ||
if (method_exists($this, $actionMethodName)) { | ||
$this->$actionMethodName(); | ||
} else { | ||
echo "Action $action not found!\n"; | ||
echo $this->usageHelp(); | ||
exit(1); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Retrieve Usage Help Message | ||
* | ||
* @return string | ||
*/ | ||
public function usageHelp() | ||
{ | ||
$help = 'Available actions: ' . "\n"; | ||
$methods = get_class_methods($this); | ||
foreach ($methods as $method) { | ||
if (substr($method, -6) == 'Action') { | ||
$help .= ' -action ' . substr($method, 0, -6); | ||
$helpMethod = $method . 'Help'; | ||
if (method_exists($this, $helpMethod)) { | ||
$help .= $this->$helpMethod(); | ||
} | ||
$help .= "\n"; | ||
} | ||
} | ||
return $help; | ||
} | ||
|
||
} | ||
|
||
$shell = new Aoe_Static_Shell(); | ||
$shell->run(); |