protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('');
     $app = $this->getSilexApplication();
     /** @var RepositoryManager $repositoryManager */
     $repositoryManager = $app['repos'];
     $contentTypeName = $input->getArgument('content type');
     $repositoryName = $input->getArgument('repository');
     $workspace = $input->getArgument('workspace');
     $language = $input->getArgument('language');
     $filename = $input->getArgument('filename');
     $output->writeln('Starting import for content type ' . $contentTypeName);
     $output->writeln('');
     $repository = $repositoryManager->getRepositoryById($repositoryName);
     if (!$repository->hasContentType($contentTypeName)) {
         $output->writeln(self::escapeError . 'Repository ' . $repositoryName . ' does not have a content type named ' . $contentTypeName . '. Use the list command to show available content types.' . self::escapeReset);
         return;
     }
     if (!$repository->getContentTypeDefinition($contentTypeName)->hasWorkspace($workspace)) {
         $output->writeln(self::escapeError . 'Content type ' . $contentTypeName . ' does not have a workspace named ' . $workspace . self::escapeReset);
     }
     if (!$repository->getContentTypeDefinition($contentTypeName)->hasLanguage($language)) {
         $output->writeln(self::escapeError . 'Content type ' . $contentTypeName . ' does not have a language named ' . $language . self::escapeReset);
     }
     if (strpos($filename, '/') !== 0) {
         $filename = getcwd() . '/' . $filename;
     }
     $filename = realpath($filename);
     if (!file_exists($filename)) {
         $output->writeln(self::escapeError . 'Could not find/access file.' . self::escapeReset);
         return;
     }
     $output->writeln('Reading ' . $filename);
     $output->writeln('');
     $importer = new Importer();
     $importer->setOutput($output);
     if ($input->getOption('xlsx') == true) {
         $importer->importXLSX($repository, $contentTypeName, $filename, $workspace, $language);
     } else {
         $data = file_get_contents($filename);
         $importer->importJSON($repository, $contentTypeName, $data, $workspace, $language);
     }
 }
 public static function executeImportRecords(Application $app, Request $request, $contentTypeAccessHash, Module $module = null)
 {
     /** @var Repository $repository */
     $repository = $app['repos']->getRepositoryByContentTypeAccessHash($contentTypeAccessHash);
     $success = false;
     $filename = null;
     if ($repository) {
         $contentTypeDefinition = $repository->getContentTypeDefinition();
         $app['context']->setCurrentRepository($repository);
         $app['context']->setCurrentContentType($contentTypeDefinition);
         $workspace = $request->get('workspace');
         if (!$contentTypeDefinition->hasWorkspace($workspace)) {
             $workspace = 'default';
         }
         $language = $request->get('language');
         if (!$contentTypeDefinition->hasLanguage($language)) {
             $language = 'default';
         }
         $format = $request->get('format');
         if ($request->files->get('file')) {
             /** @var UploadedFile $uploadedFile */
             $uploadedFile = $request->files->get('file');
             if ($uploadedFile->isValid()) {
                 $filename = $uploadedFile->getClientOriginalName();
                 $importer = new Importer();
                 $importer->setTruncateRecords((bool) $request->get('truncate'));
                 $importer->setGenerateNewIDs((bool) $request->get('newids'));
                 $importer->setPropertyChangesCheck((bool) $request->get('propertyupdate'));
                 $importer->setNewerRevisionUpdateProtection((bool) $request->get('protectedrevisions'));
                 set_time_limit(0);
                 if ($format == 'j') {
                     $data = file_get_contents($uploadedFile->getRealPath());
                     if ($data) {
                         if ($importer->importJSON($repository, $contentTypeDefinition->getName(), $data, $workspace, $language)) {
                             $success = true;
                         }
                     }
                 } else {
                     if ($importer->importXLSX($repository, $contentTypeDefinition->getName(), $uploadedFile->getRealPath(), $workspace, $language)) {
                         $success = true;
                     }
                 }
             }
         } else {
             $app['context']->addInfoMessage('Did you actually upload a file? Nothing here.');
         }
     }
     if ($success) {
         $app['context']->addSuccessMessage($importer->getCount() . ' record(s) imported from ' . $filename);
     } else {
         $app['context']->addErrorMessage('Could not import records.');
     }
     return new RedirectResponse($app['url_generator']->generate('listRecords', array('contentTypeAccessHash' => $contentTypeAccessHash, 'page' => $app['context']->getCurrentListingPage(), 'workspace' => $app['context']->getCurrentWorkspace(), 'language' => $app['context']->getCurrentLanguage())));
 }