Пример #1
0
 /**
  * Implements DrupalEntityControllerInterface::load().
  *
  * @param array $names
  * @param array $conditions
  *
  * @return array
  */
 public function load($ids = array(), $conditions = array('show_private' => FALSE))
 {
     static $string_keys = array('description', 'displayName', 'name', 'quota', 'quotaInterval', 'quotaTimeUnit');
     static $array_keys = array('apiResources', 'attributes', 'environments', 'proxies', 'scopes');
     if (!isset($conditions['show_private'])) {
         $conditions['show_private'] = FALSE;
     }
     $list = array();
     foreach (self::getOrgs($conditions) as $org) {
         $api_product = new Apigee\ManagementAPI\APIProduct(devconnect_default_org_config($org));
         if (empty($ids)) {
             try {
                 $sub_list = $api_product->listProducts($conditions['show_private']);
                 if (!empty($sub_list)) {
                     foreach ($list as $p) {
                         $this->productCache[$p->getName()] = $p;
                     }
                 }
                 $list += $sub_list;
             } catch (Apigee\Exceptions\ResponseException $e) {
             }
         } else {
             foreach ($ids as $name) {
                 if (array_key_exists($name, $this->productCache)) {
                     $list[] = $this->productCache[$name];
                 } else {
                     $my_product = clone $api_product;
                     try {
                         $my_product->load($name);
                         $this->productCache[$my_product->getName()] = $my_product;
                         if ($my_product->isPublic() || $conditions['show_private']) {
                             $list[] = $my_product;
                         }
                     } catch (Apigee\Exceptions\ResponseException $e) {
                         // do nothing
                     }
                 }
             }
         }
     }
     $return = array();
     foreach ($list as $api_product) {
         $array = $api_product->toArray();
         $array['isPublic'] = $api_product->isPublic();
         $array['orgName'] = $api_product->getConfig()->orgName;
         // Ensure that non-null values exist for non-nullable fields.
         foreach ($string_keys as $string_key) {
             if (!array_key_exists($string_key, $array)) {
                 $array[$string_key] = '';
             }
         }
         foreach ($array_keys as $array_key) {
             if (!array_key_exists($array_key, $array)) {
                 $array[$array_key] = array();
             }
         }
         $return[$api_product->getName()] = new ApiProductEntity($array);
     }
     return $return;
 }
 protected static function getConfig(DeveloperAppEntity $entity = NULL)
 {
     if (empty($entity)) {
         $org = 'default';
     } else {
         try {
             $org = devconnect_multiorg_find_requested_org($entity->orgName);
         } catch (Exception $e) {
             $org = 'default';
             watchdog('devconnect_multiorg', 'Invalid requested org “@orgName”; returning default instead', array('@orgName' => $entity->orgName), WATCHDOG_WARNING);
         }
     }
     $config = devconnect_default_org_config($org);
     $config->tags['org'] = $org;
     return $config;
 }
Пример #3
0
 /**
  * Lists all email addresses for all developers in all configured orgs.
  *
  * @return array
  *   List of all email addresses of all developers in all configured orgs.
  */
 public function listEmails()
 {
     $emails = array();
     foreach (self::getOrgs() as $org) {
         $config = devconnect_default_org_config($org);
         try {
             $dev = new Developer($config);
             if (variable_get('devconnect_paging_enabled', FALSE) && method_exists($dev, 'usePaging')) {
                 $dev->usePaging();
             }
             $emails += $dev->listDevelopers();
         } catch (Exception $e) {
         }
     }
     sort($emails);
     return array_unique($emails);
 }
Пример #4
0
 /**
  * Implements DrupalEntityControllerInterface::load().
  *
  * @param array $names
  * @param array $conditions
  * @return array
  */
 public function load($ids = array(), $conditions = array())
 {
     $orgs = self::getOrgs($conditions);
     $disableLogging = isset($conditions['disableLogging']) && $conditions['disableLogging'] === TRUE;
     $list = array();
     foreach ($orgs as $org) {
         $config = devconnect_default_org_config($org);
         if ($disableLogging) {
             $config->logger = new \Psr\Log\NullLogger();
             $config->subscribers = array();
         }
         if (array_key_exists('mail', $conditions)) {
             $identifier = $conditions['mail'];
         } elseif (array_key_exists('developerId', $conditions)) {
             $identifier = $conditions['developerId'];
         } else {
             $identifier = NULL;
         }
         if (isset($identifier) && empty($ids)) {
             $dev_app = new DeveloperApp($config, $identifier);
             if (variable_get('devconnect_paging_enabled', FALSE) && method_exists($dev_app, 'usePaging')) {
                 $dev_app->usePaging();
             }
             if (array_key_exists('name', $conditions)) {
                 try {
                     $dev_app->load($conditions['name']);
                     $list += array($dev_app);
                 } catch (ResponseException $e) {
                     self::$lastException = $e;
                 }
             } else {
                 try {
                     $list += $dev_app->getListDetail();
                 } catch (ResponseException $e) {
                     self::$lastException = $e;
                 }
             }
         } elseif (empty($ids)) {
             // Fetch all apps in the org.
             $dev_app = new DeveloperApp($config, '');
             if (variable_get('devconnect_paging_enabled', FALSE) && method_exists($dev_app, 'usePaging')) {
                 $dev_app->usePaging();
             }
             try {
                 $list += $dev_app->listAllApps();
                 $this->addListToCache($list, $ids);
             } catch (ResponseException $e) {
                 self::$lastException = $e;
             }
         } else {
             $sub_list = array();
             // We have a list of appIds. Fetch them now.
             foreach ($ids as $id) {
                 if (isset($this->appCache[$id])) {
                     $sub_list[$id] = $this->appCache[$id];
                 }
             }
             if (count($list) < count($ids)) {
                 $remaining_ids = array_diff($ids, array_keys($list));
                 $dev_app = new DeveloperApp($config, '');
                 foreach ($remaining_ids as $id) {
                     $app = clone $dev_app;
                     try {
                         $app->loadByAppId($id, TRUE);
                         $sub_list[] = $app;
                     } catch (ResponseException $e) {
                         self::$lastException = $e;
                     } catch (ParameterException $e) {
                         self::$lastException = $e;
                     }
                 }
             }
             $list += array_values($sub_list);
         }
     }
     $this->addListToCache($list, $ids);
     $uids = array();
     foreach ($list as $dev_app) {
         if ($dev_app instanceof Apigee\ManagementAPI\DeveloperApp) {
             $email = $dev_app->getDeveloperMail();
             if (!array_key_exists($email, $uids)) {
                 $uids[strtolower($email)] = NULL;
             }
         }
     }
     if (!empty($uids)) {
         $stmt = db_select('users', 'u');
         $stmt->addExpression('LOWER(mail)', 'mail');
         $uids = $stmt->fields('u', array('uid'))->condition('mail', array_keys($uids))->execute()->fetchAllKeyed();
     }
     $uids = array_flip($uids);
     $app_entities = array();
     $include_debug_data = count($list) == 1;
     foreach ($list as $dev_app) {
         if ($dev_app instanceof Apigee\ManagementAPI\DeveloperApp) {
             $id = $dev_app->getAppId();
             $mail = strtolower($dev_app->getDeveloperMail());
             $array = $dev_app->toArray($include_debug_data);
             $array['orgName'] = $dev_app->getConfig()->orgName;
             $array['uid'] = array_key_exists($mail, $uids) ? $uids[$mail] : NULL;
             $app_entity = new DeveloperAppEntity($array);
             $app_entity->checkStatusChange();
             $app_entities[$id] = $app_entity;
         }
     }
     return $app_entities;
 }