protected function execute(InputInterface $input, OutputInterface $output) { $isVerbose = $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE; $sourceProjectCode = $input->getOption('source-project-code'); $targetProjectCode = $input->getOption('target-project-code'); $targetSurveyCode = $input->getOption('target-survey-code'); $sourceProjectResource = new ProjectResource($this->sourceClient); $projectResource = new ProjectResource($this->client); $sourceProject = $sourceProjectResource->getByCode($sourceProjectCode); $targetProject = $projectResource->getByCode($targetProjectCode); if (!$sourceProject) { $output->writeln("<error>Project '{$sourceProjectCode}' not found</error>"); exit; } if (!$targetProject) { $output->writeln("<error>Project '{$targetProjectCode}' not found</error>"); exit; } $sourceSurveyId = $input->getOption('source-survey-id'); /** @type SurveyResource $fromSurveyResource */ $fromSurveyResource = new SurveyResource($this->sourceClient); $toSurveyResource = new SurveyResource($this->client); $survey = $fromSurveyResource->getById($sourceSurveyId); $surveyJson = $fromSurveyResource->getExportJson($survey['id']); if ($targetSurveyCode) { $surveyJson['code'] = $targetSurveyCode; } $result = $toSurveyResource->importSurvey(['import_data' => $surveyJson, 'name' => $survey['name'], 'code' => $survey['code'], 'project_id' => $targetProject['id'], 'category_code' => $survey['category_code'], 'description' => $survey['description']]); $output->writeln("Survey {$result['code']} #{$result['id']} transferred"); }
protected function execute(InputInterface $input, OutputInterface $output) { $projectResource = new ProjectResource($this->sourceClient); $memberResource = new MemberResource($this->sourceClient); $surveyResource = new SurveyResource($this->sourceClient); $result = $projectResource->getList(); foreach ($result['items'] as $idx => $project) { $projectCode = $project['code']; $result = $memberResource->getList(1, 1000, ['project_id' => $project['id'], 'permission_type_code' => 'owner']); $owners = implode(', ', array_map(function ($member) { return isset($member['code']) ? $member['code'] : '#' . $member['id']; }, $result['items'])); $result = $surveyResource->getList(1, 1000, ['project_id' => $project['id']]); $surveys = implode("\n", array_map(function ($survey) { return '"' . $survey['name'] . '"'; }, $result['items'])); $data[] = ['code' => $projectCode, 'owners' => $owners, 'surveys' => $surveys]; } $table = new Table($output); $table->setHeaders(['code', 'owners', 'surveys'])->setRows($data); $table->render(); }