diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2013-09-20 06:48:02 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2013-09-20 06:52:50 +0400 |
commit | 6cd07963976102139db0de2b5faf78a4d427edcf (patch) | |
tree | ca1a14e1b4f9a9942b50bc48cb33bf33b41c35a3 | |
parent | 6f5cb36acc27aa61420c3905b852165307c1a22f (diff) |
cache marketplace requests only for 20minutes, clear cache entries once a day
-rw-r--r-- | core/ScheduledTask.php | 4 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/Controller.php | 4 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/CorePluginsAdmin.php | 17 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/MarketplaceApiClient.php | 11 |
4 files changed, 32 insertions, 4 deletions
diff --git a/core/ScheduledTask.php b/core/ScheduledTask.php index 5262e7cbc3..d2349329de 100644 --- a/core/ScheduledTask.php +++ b/core/ScheduledTask.php @@ -81,6 +81,10 @@ class ScheduledTask protected function getClassNameFromInstance($_objectInstance) { + if (is_string($_objectInstance)) { + return $_objectInstance + } + $namespaced = get_class($_objectInstance); $class = explode('\\', $namespaced); return end($class); diff --git a/plugins/CorePluginsAdmin/Controller.php b/plugins/CorePluginsAdmin/Controller.php index 431fafbd90..d1e4cc6f53 100644 --- a/plugins/CorePluginsAdmin/Controller.php +++ b/plugins/CorePluginsAdmin/Controller.php @@ -219,7 +219,9 @@ class Controller extends \Piwik\Controller\Admin $view->updateNonce = Nonce::getNonce('CorePluginsAdmin.updatePlugin'); $view->activateNonce = Nonce::getNonce('CorePluginsAdmin.activatePlugin'); $view->pluginsInfo = $pluginsInfo; - $view->pluginsHavingUpdate = $this->getPluginsHavingUpdate($pluginsInfo, $themesOnly = true); + $marketplace = new Marketplace(); + + $view->pluginsHavingUpdate = $marketplace->getPluginsHavingUpdate($pluginsInfo, $themesOnly = true); echo $view->render(); } diff --git a/plugins/CorePluginsAdmin/CorePluginsAdmin.php b/plugins/CorePluginsAdmin/CorePluginsAdmin.php index 347dfd82e7..8f4e44c866 100644 --- a/plugins/CorePluginsAdmin/CorePluginsAdmin.php +++ b/plugins/CorePluginsAdmin/CorePluginsAdmin.php @@ -11,6 +11,8 @@ namespace Piwik\Plugins\CorePluginsAdmin; use Piwik\Piwik; +use Piwik\ScheduledTask; +use Piwik\ScheduledTime\Daily; /** * @@ -27,6 +29,21 @@ class CorePluginsAdmin extends \Piwik\Plugin 'AdminMenu.add' => 'addMenu', 'AssetManager.getJsFiles' => 'getJsFiles', 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', + 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks', + ); + } + + /** + * Gets all scheduled tasks executed by this plugin. + */ + public function getScheduledTasks(&$tasks) + { + $tasks[] = new ScheduledTask( + 'Piwik\Plugins\CorePluginsAdmin\MarketplaceApiClient', + 'clearAllCacheEntries', + null, + new Daily(), + ScheduledTask::LOWEST_PRIORITY ); } diff --git a/plugins/CorePluginsAdmin/MarketplaceApiClient.php b/plugins/CorePluginsAdmin/MarketplaceApiClient.php index 4c9de800fe..cd57e58a18 100644 --- a/plugins/CorePluginsAdmin/MarketplaceApiClient.php +++ b/plugins/CorePluginsAdmin/MarketplaceApiClient.php @@ -11,7 +11,6 @@ namespace Piwik\Plugins\CorePluginsAdmin; use Piwik\CacheFile; use Piwik\Http; -use Piwik\Tracker\Cache; /** * @@ -19,7 +18,7 @@ use Piwik\Tracker\Cache; */ class MarketplaceApiClient { - private $domain = 'http://plugins.piwik.org/'; + private $domain = 'http://plugins.piwik.org'; /** * @var CacheFile @@ -28,7 +27,13 @@ class MarketplaceApiClient public function __construct() { - $this->cache = new CacheFile('marketplace', 7200); + $this->cache = new CacheFile('marketplace', 1200); + } + + public static function clearAllCacheEntries() + { + $cache = new CacheFile('marketplace'); + $cache->deleteAll(); } private function fetch($action, $params) |