예제 #1
0
 /**
  * @param $token
  *
  * @throws RokUpdater_Exception
  */
 public function updateAccessToken($site_id, $token = null)
 {
     // get the RT update items
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('update_site_id, location')->from('#__update_sites');
     $query->where('location like ' . $query->quote($this->container->updaters_server_regex_pattern));
     $db->setQuery($query);
     try {
         $update_items = $db->loadAssocList('update_site_id');
         if ($db->getErrorNum()) {
             throw new RokUpdater_Exception(sprintf('Database error - %s', $db->getErrorMsg(true)));
         }
     } catch (Exception $e) {
         throw new RokUpdater_Exception(sprintf('Database error - %s', $e->getMessage()));
     }
     $jversion = new JVersion();
     // Append the access token to any RT update URL
     foreach ($update_items as $id => $row_info) {
         $uri = new RokUpdater_Uri(trim($row_info['location']));
         $uri->addQueryParam(self::SITE_ID_QUERY_KEY, $site_id);
         if (null !== $token) {
             $uri->addQueryParam(self::ACCESS_TOKEN_QUERY_KEY, $token);
             $uri->removeQueryParam(self::IGNORED_QUERY_KEY);
         } else {
             $uri->removeQueryParam(self::ACCESS_TOKEN_QUERY_KEY);
             $uri->removeQueryParam(self::IGNORED_QUERY_KEY);
         }
         $location = $uri->getAbsoluteUri();
         $location .= !count($uri->getQueryParams()) ? '?' : '&';
         $location .= self::IGNORED_QUERY_KEY . '=update.xml';
         $update_query = $db->getQuery(true);
         $update_query->update('#__update_sites')->set(sprintf('location = %s', $update_query->quote($location)));
         $update_query->where(sprintf('update_site_id = %d', (int) $id));
         $db->setQuery($update_query);
         try {
             if (method_exists($db, 'execute') && !$db->execute() || method_exists($db, 'query') && !$db->query()) {
                 throw new RokUpdater_Exception(sprintf('Database error - %s', $db->getErrorMsg(true)));
             }
         } catch (Exception $e) {
             throw new RokUpdater_Exception(sprintf('Database error - %s', $e->getMessage()));
         }
     }
 }