Ejemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Importing tracker...');
     $lib = \TikiLib::lib('tabular');
     $info = $lib->getInfo($input->getArgument('tabularId'));
     $perms = \Perms::get('tabular', $info['tabularId']);
     if (!$info || !$perms->tabular_import) {
         throw new \Exception('Tracker Import: Tabular Format not found');
     }
     $fileName = $input->getArgument('filename');
     if (!file_exists($fileName)) {
         throw new \Exception('Tracker Import: File not found');
     }
     // from \Services_Tracker_TabularController::getSchema TODO refactor?
     $tracker = \Tracker_Definition::get($info['trackerId']);
     if (!$tracker) {
         throw new \Exception('Tracker Import: Tracker not found');
     }
     $schema = new \Tracker\Tabular\Schema($tracker);
     $schema->loadFormatDescriptor($info['format_descriptor']);
     $schema->loadFilterDescriptor($info['filter_descriptor']);
     $schema->validate();
     if (!$schema->getPrimaryKey()) {
         throw new \Exception(tr('Primary Key required'));
     }
     // this will throw exceptions and not return if there's a problem
     $source = new \Tracker\Tabular\Source\CsvSource($schema, $fileName);
     $writer = new \Tracker\Tabular\Writer\TrackerWriter();
     $writer->write($source);
     $output->writeln('Import done');
     return 0;
 }
Ejemplo n.º 2
0
 function action_import_csv($input)
 {
     $lib = TikiLib::lib('tabular');
     $info = $lib->getInfo($input->tabularId->int());
     $trackerId = $info['trackerId'];
     Services_Exception_Denied::checkObject('tiki_p_tabular_import', 'tabular', $info['tabularId']);
     $schema = $this->getSchema($info);
     $schema->validate();
     if (!$schema->getPrimaryKey()) {
         throw new Services_Exception_NotAvailable(tr('Primary Key required'));
     }
     $done = false;
     if ($_SERVER['REQUEST_METHOD'] == 'POST' && is_uploaded_file($_FILES['file']['tmp_name'])) {
         $source = new \Tracker\Tabular\Source\CsvSource($schema, $_FILES['file']['tmp_name']);
         $writer = new \Tracker\Tabular\Writer\TrackerWriter();
         $writer->write($source);
         unlink($_FILES['file']['tmp_name']);
         $done = true;
     }
     return ['title' => tr('Import'), 'tabularId' => $info['tabularId'], 'completed' => $done];
 }