/**
  * @param string          $property
  * @param string          $value
  * @param Project         $project
  * @param OutputInterface $output
  *
  * @return int
  */
 protected function setProperty($property, $value, Project $project, OutputInterface $output)
 {
     if (!$this->validateValue($property, $value, $output)) {
         return 1;
     }
     $type = $this->getType($property);
     if ($type === 'boolean' && $value === 'false') {
         $value = false;
     }
     settype($value, $type);
     $currentValue = $project->getProperty($property, false);
     if ($currentValue === $value) {
         $output->writeln("Property <info>{$property}</info> already set as: " . $project->getProperty($property, false));
         return 0;
     }
     $project->update(array($property => $value));
     $output->writeln("Property <info>{$property}</info> set to: " . $project[$property]);
     return 0;
 }
 /**
  * @param string          $property
  * @param string          $value
  * @param Project         $project
  *
  * @return int
  */
 protected function setProperty($property, $value, Project $project)
 {
     if (!$this->validateValue($property, $value)) {
         return 1;
     }
     $type = $this->getType($property);
     if ($type === 'boolean' && $value === 'false') {
         $value = false;
     }
     settype($value, $type);
     $currentValue = $project->getProperty($property);
     if ($currentValue === $value) {
         $this->stdErr->writeln("Property <info>{$property}</info> already set as: " . $this->formatter->format($value, $property));
         return 0;
     }
     $project->ensureFull();
     $project->update(array($property => $value));
     $this->stdErr->writeln("Property <info>{$property}</info> set to: " . $this->formatter->format($value, $property));
     $this->getProjects(true);
     return 0;
 }
Esempio n. 3
0
 /**
  * Return the user's environments.
  *
  * @param Project   $project The project.
  * @param bool|null $refresh Whether to refresh the list.
  * @param bool      $events  Whether to update Drush aliases if the list changes.
  *
  * @return Environment[] The user's environments.
  */
 public function getEnvironments(Project $project, $refresh = null, $events = true)
 {
     $projectId = $project->getProperty('id');
     static $staticEnvironmentsCache;
     if (!$refresh && isset($staticEnvironmentsCache[$projectId])) {
         return $staticEnvironmentsCache[$projectId];
     }
     $cacheKey = 'environments:' . $projectId;
     $cached = self::$cache->fetch($cacheKey);
     if ($refresh === false && !$cached) {
         return [];
     } elseif ($refresh || !$cached) {
         $environments = [];
         $toCache = [];
         foreach ($project->getEnvironments() as $environment) {
             $environments[$environment->id] = $environment;
             $toCache[$environment->id] = $environment->getData();
         }
         // Dispatch an event if the list of environments has changed.
         if (isset($this->dispatcher) && $events && (!$cached || array_diff_key($environments, $cached))) {
             $this->dispatcher->dispatch('environments_changed', new EnvironmentsChangedEvent($project, $environments));
         }
         self::$cache->save($cacheKey, $toCache, $this->config->get('api.environments_ttl'));
     } else {
         $environments = [];
         $endpoint = $project->hasLink('self') ? $project->getLink('self', true) : $project->getProperty('endpoint');
         $guzzleClient = $this->getClient()->getConnector()->getClient();
         foreach ((array) $cached as $id => $data) {
             $environments[$id] = new Environment($data, $endpoint, $guzzleClient, true);
         }
     }
     $staticEnvironmentsCache[$projectId] = $environments;
     return $environments;
 }
 /**
  * @param string  $property
  * @param string  $value
  * @param Project $project
  * @param bool    $noWait
  *
  * @return int
  */
 protected function setProperty($property, $value, Project $project, $noWait)
 {
     if (!$this->validateValue($property, $value)) {
         return 1;
     }
     $type = $this->getType($property);
     if ($type === 'boolean' && $value === 'false') {
         $value = false;
     }
     settype($value, $type);
     $currentValue = $project->getProperty($property);
     if ($currentValue === $value) {
         $this->stdErr->writeln("Property <info>{$property}</info> already set as: " . $this->formatter->format($value, $property));
         return 0;
     }
     $project->ensureFull();
     $result = $project->update([$property => $value]);
     $this->stdErr->writeln("Property <info>{$property}</info> set to: " . $this->formatter->format($value, $property));
     $this->api()->clearProjectsCache();
     $success = true;
     if (!$noWait) {
         $success = ActivityUtil::waitMultiple($result->getActivities(), $this->stdErr, $project);
     }
     return $success ? 0 : 1;
 }