diff --git a/module/Application/config/module.config.php b/module/Application/config/module.config.php index ff5ccbe3..5396b57e 100644 --- a/module/Application/config/module.config.php +++ b/module/Application/config/module.config.php @@ -141,7 +141,7 @@ ), 'view_helpers' => array( 'factories' => array( - 'flashMessenger' => function($sm) { + 'flashMessenger' => function ($sm) { $sm = $sm->getServiceLocator(); $plugin = $sm->get('ControllerPluginManager')->get('flashMessenger'); diff --git a/module/User/Module.php b/module/User/Module.php index 0576d3c3..84f7e559 100644 --- a/module/User/Module.php +++ b/module/User/Module.php @@ -13,7 +13,7 @@ public function bootstrap(ModuleManager $moduleManager, ApplicationInterface $ap $em = $app->getEventManager()->getSharedManager(); $sm = $app->getServiceManager(); - $em->attach('ScnSocialAuth\Authentication\Adapter\HybridAuth','githubToLocalUser', function($e) { + $em->attach('ScnSocialAuth\Authentication\Adapter\HybridAuth','githubToLocalUser', function ($e) { $localUser = $e->getTarget(); $userProfile = $e->getParam('userProfile'); $nickname = substr( @@ -24,7 +24,7 @@ public function bootstrap(ModuleManager $moduleManager, ApplicationInterface $ap $localUser->setPhotoUrl($userProfile->photoURL); }); - $em->attach('EdpGithub\Client', 'api', function($e) use ($sm) { + $em->attach('EdpGithub\Client', 'api', function ($e) use ($sm) { $hybridAuth = $sm->get('HybridAuth'); $adapter = $hybridAuth->getAdapter('github'); diff --git a/module/ZfModule/Module.php b/module/ZfModule/Module.php index 18d5222c..092d9474 100644 --- a/module/ZfModule/Module.php +++ b/module/ZfModule/Module.php @@ -48,7 +48,7 @@ public function getServiceConfig() { return array( 'factories' => array( - 'zfmodule_cache' => function($sm) { + 'zfmodule_cache' => function ($sm) { $config = $sm->get('Config'); $storage = StorageFactory::factory($config['zfmodule']['cache']); @@ -61,16 +61,16 @@ public function getServiceConfig() $mapper->setHydrator(new Mapper\ModuleHydrator()); return $mapper; }, - 'zfmodule_service_module' => function($sm) { + 'zfmodule_service_module' => function ($sm) { $service = new Service\Module; return $service; }, - 'zfmodule_service_repository' => function($sm) { + 'zfmodule_service_repository' => function ($sm) { $service = new Service\Repository; $service->setApi($sm->get('EdpGithub\Client')); return $service; }, - /*'github_client' => function($sm) { + /*'github_client' => function ($sm) { $hybridAuth = $sm->get('HybridAuth'); $adapter = $hybridAuth->getAdapter('github'); $token = $adapter->getAccessToken(); diff --git a/module/ZfModule/src/ZfModule/Controller/IndexController.php b/module/ZfModule/src/ZfModule/Controller/IndexController.php index 3c443990..10f3ce37 100644 --- a/module/ZfModule/src/ZfModule/Controller/IndexController.php +++ b/module/ZfModule/src/ZfModule/Controller/IndexController.php @@ -125,48 +125,35 @@ public function fetchModules($repos, $cacheKey) $cache = $sl->get('zfmodule_cache'); $repositories = array(); - //fetch only modules from github - foreach($repos as $repo) { - //Need to see first if any repository has been updated + + foreach($repos as $key => $repo) { + //Verify if repos have been modified $httpClient = $client->getHttpClient(); - $response= $httpClient->getResponse(); + $response = $httpClient->getResponse(); if($response->getStatusCode() == 304) { if($cache->hasItem($cacheKey . '-github')) { $repositories = $cache->getItem($cacheKey . '-github'); break; } + } elseif ($cache->hasItem($cacheKey . '-github')) { + $cache->removeItem($cacheKey . '-github'); } - if(!$repo->fork && $repo->permissions->push) { - if($this->getModuleService()->isModule($repo)) { - $repositories[] = $repo; - } + + if($repo->fork || !$repo->permissions->push || !$this->getModuleService()->isModule($repo) ) { + continue; } - } - //save list of modules to cache - if(!$cache->hasItem($cacheKey . '-github')) { - $cache->setItem($cacheKey . '-github', $repositories); - } - //check if cache for modules exist - if(!$cache->hasItem($cacheKey)) { - //check if module is in database - foreach($repositories as $key => $repo) { - $module = $mapper->findByName($repo->name); - if($module) { - unset($repositories[$key]); - } + $module = $mapper->findByName($repo->name); + if($module) { + continue; } - //save database mapped list to cache - $cache->setItem($cacheKey , $repositories); - // create cache tags - $identity = $this->zfcUserAuthentication()->getIdentity(); - $tags = array($identity->getUsername() . '-' . $identity->getId()); - $cache->setTags($cacheKey, $tags); - } else { - $repositories = $cache->getItem($cacheKey); + $repositories[] = $repo; } + //save list of modules to cache + $cache->setItem($cacheKey . '-github', $repositories); + return $repositories; } diff --git a/module/ZfModule/src/ZfModule/Mapper/Module.php b/module/ZfModule/src/ZfModule/Mapper/Module.php index 1810f50f..2849a382 100644 --- a/module/ZfModule/src/ZfModule/Mapper/Module.php +++ b/module/ZfModule/src/ZfModule/Mapper/Module.php @@ -21,7 +21,7 @@ public function pagination($page, $limit, $query = null, $orderBy = null, $sort } if(null !== $query) { - $spec = function ( $where) use ($query) { + $spec = function ($where) use ($query) { $where->like('name', '%'.$query.'%')->or->like('description', '%'.$query.'%'); }; $select->where($spec); @@ -72,7 +72,7 @@ public function findByLike($query, $limit = null, $orderBy = null, $sort = 'ASC' $select->limit($limit); } - $spec = function ( $where) use ($query) { + $spec = function ($where) use ($query) { $where->like('name', '%'.$query.'%')->or->like('description', '%'.$query.'%'); }; $select->where($spec);