Beispiel #1
0
 /**
  * resolves project id, from slug by using internal mapper
  *
  * @param int|string $param
  *
  * @return int|string
  */
 private function resolveProjectId($param)
 {
     if (!is_numeric($param)) {
         $config = $this->getApplication()->config();
         $slugMapper = new ProjectIdSlugMapper($config);
         return $slugMapper->getIdBySlug($param) ?: $param;
     }
     return $param;
 }
Beispiel #2
0
 /**
  * executes the command
  */
 protected function handle()
 {
     $client = $this->getClient();
     $command = new IndexCommand();
     try {
         $response = $client->send($command);
     } catch (ClientException $e) {
         if ($e->getCode() === 401) {
             $this->callSilent('dpm:token');
             $client->setToken($this->getApplication()->resetConfig()->config()->get('token'));
             $response = $client->send($command);
         } else {
             $this->error($e->getMessage());
             return 1;
         }
     }
     if ($response->getStatusCode() >= 300) {
         $this->info('No Projects found');
         return 0;
     }
     $projects = json_decode($response->getBody()->getContents(), true);
     $projectsList = array_get($projects, 'data', []);
     if (empty($projectsList)) {
         $this->info('No Projects found');
         return 0;
     }
     $config = $this->getApplication()->config();
     $slugMapper = new ProjectIdSlugMapper($config);
     $table = new Table($this->output);
     $table->setHeaders(['Id', 'Slug', 'Project', 'Status']);
     foreach ($projectsList as $project) {
         $table->addRow([$project['id'], $project['attributes']['slug'], $project['attributes']['name'], $project['attributes']['status']]);
         $slugMapper->addMapping($project['id'], $project['attributes']['slug']);
     }
     $table->render();
     $this->getApplication()->writeConfig($slugMapper->getConfig());
     return 0;
 }