Fix syntax error, prime manga cache too. See #19

This commit is contained in:
Timothy Warren 2017-03-22 12:28:19 -04:00
parent 857d484b61
commit 1fd2dd1146
3 changed files with 16 additions and 5 deletions

View File

@ -35,9 +35,9 @@ unset($CONF_DIR);
// --------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------------
$console = new \ConsoleKit\Console([ $console = new \ConsoleKit\Console([
'cache-prime' => '\Aviat\AnimeClient\Command\CachePrime', 'cache-prime' => '\Aviat\AnimeClient\Command\CachePrime',
'cache-clear' => '\Aviat\AnimeClient\Command\CacheClear' 'cache-clear' => '\Aviat\AnimeClient\Command\CacheClear',
'clear-cache' => '\Aviat\AnimeClient\Command\CacheClear', 'clear-cache' => '\Aviat\AnimeClient\Command\CacheClear',
'sync-lists' => '\Aviat\AnimeClient\Command\SyncKitsuWithMal' 'sync-lists' => '\Aviat\AnimeClient\Command\SyncKitsuWithMal',
]); ]);
$console->run(); $console->run();

View File

@ -69,6 +69,11 @@ trait KitsuTrait {
if ($sessionSegment->get('auth_token') !== NULL && $url !== K::AUTH_URL) if ($sessionSegment->get('auth_token') !== NULL && $url !== K::AUTH_URL)
{ {
$token = $sessionSegment->get('auth_token'); $token = $sessionSegment->get('auth_token');
if ( ! $cacheItem->isHit())
{
$cacheItem->set($token);
$cacheItem->save();
}
} }
else if ($sessionSegment->get('auth_token') === NULL && $cacheItem->isHit()) else if ($sessionSegment->get('auth_token') === NULL && $cacheItem->isHit())
{ {

View File

@ -32,14 +32,16 @@ class CachePrime extends BaseCommand {
{ {
$this->setContainer($this->setupContainer()); $this->setContainer($this->setupContainer());
$cache = $container->get('cache'); $cache = $this->container->get('cache');
// Save the user id, if it exists, for priming the cache // Save the user id, if it exists, for priming the cache
$userIdItem = $cache->getItem('kitsu-auth-token'); $userIdItem = $cache->getItem('kitsu-auth-token');
$userId = $userIdItem->isHit() ? $userIdItem->get : null; $userId = $userIdItem->isHit() ? $userIdItem->get() : null;
$cache->clear(); $cache->clear();
$this->echoBox('Cache cleared, re-priming...');
if ( ! is_null($userId)) if ( ! is_null($userId))
{ {
$userIdItem = $cache->getItem('kitsu-auth-token'); $userIdItem = $cache->getItem('kitsu-auth-token');
@ -47,9 +49,13 @@ class CachePrime extends BaseCommand {
$userIdItem->save(); $userIdItem->save();
} }
$kitsuModel = $container->get('kitsu-model'); // Prime anime list cache
$kitsuModel = $this->container->get('kitsu-model');
$kitsuModel->getFullOrganizedAnimeList(); $kitsuModel->getFullOrganizedAnimeList();
// Prime manga list cache
$kitsuModel->getFullOrganizedMangaList();
$this->echoBox('API Cache has been primed.'); $this->echoBox('API Cache has been primed.');
} }
} }