protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $force = $input->getOption('force'); /** * @var QuestionHelper $helper */ $helper = $this->getHelper('question'); $question = new Question('Please enter your manage token: '); $question->setHidden(true); $question->setHiddenFallback(false); $manageToken = $helper->ask($input, $output, $question); $manageClient = new \Keboola\ManageApi\Client(["token" => $manageToken]); $this->client = new \GuzzleHttp\Client(['base_uri' => 'https://connection.keboola.com/manage/', 'headers' => ['X-KBC-ManageApiToken' => $manageToken, 'Accept-Encoding' => 'gzip', 'User-Agent' => $this->getUserAgent()]]); $this->dbOrchestrationManager = $this->getContainer()->get('orchestrator.doctrine.orchestration_manager'); foreach ($manageClient->listMaintainers() as $maintainer) { $maintainerPrinted = false; $output->write('M'); foreach ($this->loadOrganizations($maintainer) as $organization) { $organizationPrinted = false; $output->write('O'); foreach ($manageClient->listOrganizationProjects($organization['id']) as $project) { if ($project['isDisabled']) { $output->write('P'); continue; } if (!$this->loadProjectOrchestrations($project['id']) && !$this->loadProjectDeletedOrchestrations($project['id'])) { $output->write('P'); continue; } // delete orchestrator bucket if exists if (!$maintainerPrinted) { $maintainerPrinted = true; $output->writeln("\t" . $maintainer['name']); } if (!$organizationPrinted) { $organizationPrinted = true; $output->writeln("\t\t" . $organization['name']); } $output->writeln("\t\t\t" . $project['name'] . " (" . $project['id'] . ")"); $projectToken = $manageClient->createProjectStorageToken($project['id'], ["description" => "Orchestrator old table deletion", "canManageBuckets" => true, "canReadAllFileUploads" => true, "expiresIn" => 1800]); $client = new Client(["token" => $projectToken["token"]]); foreach ($client->listBuckets() as $bucket) { $bucketId = 'sys.c-orchestrator'; if ($bucket['id'] != $bucketId) { continue; } // bucket delete if ($force) { try { $client->dropBucket($bucketId, array('force' => true)); $output->writeln("\t\t\t\tOrchestrator bucket deleted"); } catch (Exception $e) { $output->writeln("\t\t\t\t" . $e->getMessage()); continue; } $manageClient->addNotification(array('type' => 'common', 'projectId' => $project['id'], 'title' => sprintf(' Orchestrator bucket %s was removed from your project -- %s', 'sys.c-orchestrator', $project['name']), 'message' => 'As we announced on our [blog](http://status.keboola.com/orchestrator-table-deletion-announcement), ' . 'we have deleted the unused orchestrator bucket from your KBC storage. ' . 'This message is just for your information and has no effect on your existing orchestrations.')); $output->writeln("\t\t\t\tNotification created"); } else { $output->writeln("\t\t\t\tOrchestrator bucket will be deleted"); } } } } } }