Run data import.

@param \CsvMigrations\Model\Entity\Import $import Import entity
@param int $count Progress count
@return void
423592
protected function _run(Import $import, int $count) : void
    {
        // generate import results records
        $this->createImportResults($import, $count);

        $this->out('Importing records ..');
        $progress = $this->helper('Progress');
        Assert::isInstanceOf($progress, ProgressHelper::class);
        $progress->init();

        $headers = ImportUtility::getUploadHeaders($import);
        $filename = ImportUtility::getProcessedFile($import);
        $reader = Reader::createFromPath($filename, 'r');
        foreach ($reader as $index => $row) {
            // skip first csv row
            if (0 === $index) {
                continue;
            }

            // skip empty row
            if (empty($row)) {
                continue;
            }

            $this->_importResult($import, $headers, $index, $row);

            $progress->increment(100 / $count);
            $progress->draw();
        }

        $this->out(null);
    }
708336
public function importArticleStatistics()
    {
        $pendingImports = $this->em->getRepository('ImportBundle:PendingStatisticImport')->findAll();
        $this->consoleOutput->writeln("Importing article statistics...");

        foreach ($pendingImports as $import) {
            $this->importArticleStatistic($import->getOldId(), $import->getArticle()->getId());
            $this->em->remove($import);
            $this->em->flush($import);
        }
    }
1305968
def after_import(self, dataset, result, using_transactions, dry_run, **kwargs):
        
        # Adapted from django's loaddata
        if not dry_run and any(r.import_type == RowResult.IMPORT_TYPE_NEW for r in result.rows):
            connection = connections[DEFAULT_DB_ALIAS]
            sequence_sql = connection.ops.sequence_reset_sql(no_style(), [self._meta.model])
            if sequence_sql:
                cursor = connection.cursor()
                try:
                    for line in sequence_sql:
                        cursor.execute(line)
                finally:
                    cursor.close()
111125
public static function find($import, int $startRow = null)
    {
        if (!$import instanceof WithLimit) {
            return null;
        }

        // When no start row given,
        // use the first row as start row.
        $startRow = $startRow ?? 1;

        // Subtract 1 row from the start row, so a limit
        // of 1 row, will have the same start and end row.
        return ($startRow - 1) + $import->limit();
    }
844329
public function buildDryrunWorkflow(Import $import, ImportRun $importRun = null)
    {
        //build basics
        $workflow = $this->buildBaseWorkflow($import);

        //collect statistics by default
        $statisticsCollector = new ImportRunEventSubscriber($import, true);
        $this->eventDispatcher->addSubscriber($statisticsCollector);

        return $workflow;
    }
1164437
public function headers(Import $import)
	{
		// autodetect adapter
		$this->autoDetectAdapter($import);

		// call count on adapter
		return $this->getAdapter()->headers($import);
	}
1081107
function importFor(node) {
      self.pendingImports++;

      if (isSync) {
        // Sync import:
        var file = self.importer.resolveSync(node.uri, self);
        _.mapNodeToFile(node, file.parse());
        _.mapIncludedFiles(self, file);
        self.resolvedImports++;
        return;
      }

      // Async import:
      self.importer.resolve(node.uri, self, function(err, file) {
        if (err) return finish(err);

        file.parse(function(err, file) {
          if (err) return finish(err);

          _.mapNodeToFile(node, file);
          _.mapIncludedFiles(self, file);
          self.resolvedImports++;
          finish(null);
        });
      });
    }
20427
protected function _ExecuteCron()
    {
        parent::_ExecuteCron();

        $oList = TdbPkgShopRatingServiceList::GetList();
        while ($oService = $oList->Next()) {
            if ($oService->fieldActive && $oService->fieldAllowImport) {
                echo 'Importing: '.$oService->fieldClass.'...';
                if ($oService->Import()) {
                    echo 'ok.<br />';
                } else {
                    echo 'error!<br />';
                }
            }
        }
    }
261549
protected function processImportFile(Import $import) : void
    {
        $this->out('Processing import file ..');

        $path = ImportUtility::getProcessedFile($import);
        if (file_exists($path)) {
            return;
        }

        // create processed file
        $writer = Writer::createFromPath($path, 'w+');

        $reader = Reader::createFromPath($import->get('filename'), 'r');

        $results = $reader->fetch();
        foreach ($results as $row) {
            if (empty(array_filter($row))) {
                continue;
            }

            $writer->insertOne($row);
        }
    }
1368115
public void addStaticImport(ImportDescr importDescr) {
        for (Dialect dialect : this.map.values()) {
            dialect.addStaticImport(importDescr);
        }
    }
469704
private function validateRows(WithValidation $import)
    {
        try {
            $this->validator->validate($this->rows, $import);
        } catch (RowSkippedException $e) {
            foreach ($e->skippedRows() as $row) {
                unset($this->rows[$row]);
            }
        }
    }
271075
public function toArray($import, int $startRow = null, $nullValue = null, $calculateFormulas = false, $formatData = false)
    {
        $endRow     = EndRowFinder::find($import, $startRow);
        $headingRow = HeadingRowExtractor::extract($this->worksheet, $import);

        $rows = [];
        foreach ($this->worksheet->getRowIterator($startRow, $endRow) as $row) {
            $row = (new Row($row, $headingRow))->toArray($nullValue, $calculateFormulas, $formatData);

            if ($import instanceof WithMapping) {
                $row = $import->map($row);
            }

            $rows[] = $row;

            if ($import instanceof WithProgressBar) {
                $import->getConsoleOutput()->progressAdvance();
            }
        }

        return $rows;
    }
872372
public function count(Import $import)
	{
		// create iterator
		$iterator = new Reader($import->getDatapath(), $this->key);

		// return count
		return $iterator->total();
	}
962699
public function importAction()
    {

        $form = $this->formFactory->create(new ImportUserType(true));
        $form->handleRequest($this->request);
        $mode = $form->get('mode')->getData();

        if ($mode === 'update') {
            $form = $this->formFactory->create(new ImportUserType(true, 1));
            $form->handleRequest($this->request);
        }

        if ($form->isValid()) {
            $file = $form->get('file')->getData();
            $sendMail = $form->get('sendMail')->getData();
            $data = file_get_contents($file);
            $data = $this->container->get('claroline.utilities.misc')->formatCsvOutput($data);
            $lines = str_getcsv($data, PHP_EOL);
            $users = array();
            $toUpdate = array();
            $sessionFlashBag = $this->session->getFlashBag();

            foreach ($lines as $line) {

                if ($mode === 'update') {
                    $datas = str_getcsv($line, ';');
                    $username = $datas[2];
                    $email = $datas[4];
                    $existingUser = $this->userManager->getUserByUsernameOrMail(
                        $username,
                        $email
                    );

                    if (is_null($existingUser)) {
                        $users[] = $datas;
                    } else {
                        $toUpdate[] = $datas;
                    }
                } else {
                    $users[] = str_getcsv($line, ';');
                }
            }

            $roleUser = $this->roleManager->getRoleByName('ROLE_USER');
            $max = $roleUser->getMaxUsers();
            $total = $this->userManager->countUsersByRoleIncludingGroup($roleUser);

            if ($total + count($users) > $max) {

                return array('form' => $form->createView(), 'error' => 'role_user unavailable');
            }

            $additionalRoles = $form->get('roles')->getData();

            foreach ($additionalRoles as $additionalRole) {
                $max = $additionalRole->getMaxUsers();
                $total = $this->userManager->countUsersByRoleIncludingGroup($additionalRole);

                if ($total + count($users) > $max) {

                    return array(
                        'form' => $form->createView(),
                        'error' => $additionalRole->getName() . ' unavailable'
                    );
                }
            }

            if (count($toUpdate) > 0) {
                $updatedNames = $this->userManager->updateImportedUsers(
                    $toUpdate,
                    $additionalRoles->toArray()
                );

                foreach ($updatedNames as $name) {
                    $msg =  '<' . $name . '> ';
                    $msg .= $this->translator->trans(
                        'has_been_updated',
                        array(),
                        'platform'
                    );
                    $sessionFlashBag->add('success', $msg);
                }
            }
            $createdNames = $this->userManager->importUsers(
                $users,
                $sendMail,
                null,
                $additionalRoles
            );

            foreach ($createdNames as $name) {
                $msg =  '<' . $name . '> ';
                $msg .= $this->translator->trans(
                    'has_been_created',
                    array(),
                    'platform'
                );
                $sessionFlashBag->add('success', $msg);
            }

            return new RedirectResponse($this->router->generate('claro_admin_users_index'));
        }

        return array('form' => $form->createView());
    }
861624
public function addExistingRoundsToModel(\ArrayObject $import, \MUtil_Model_ModelAbstract $model)
    {
        $currentRounds = $this->trackEngine->getRounds();

        if (! $currentRounds) {
            return;
        }

        $importRounds    = array();
        $newImportRounds = array();
        $tracker         = $this->loader->getTracker();

        foreach ($import['rounds'] as $lineNr => $roundData) {
            if (isset($roundData['survey_export_code'], $import['surveyCodes'][$roundData['survey_export_code']])) {
                $roundData['gro_id_survey'] = $import['surveyCodes'][$roundData['survey_export_code']];
                $round = $tracker->createTrackClass('Round', $roundData);

                $importRounds[$round->getRoundOrder()] = $round->getFullDescription();
                $newImportRounds[$round->getRoundOrder()] = sprintf(
                        $this->_('Set round to round %s'),
                        $round->getFullDescription()
                        );

                $import['roundOrderToLine'][$round->getRoundOrder()] = $lineNr;
            }
        }

        // Filter for rounds not in current track
        foreach ($currentRounds as $roundId => $round) {
            if ($round instanceof Round) {
                $order = $round->getRoundOrder();

                if (isset($newImportRounds[$order])) {
                    unset($newImportRounds[$order]);
                }
            }
        }

        $except     = array(self::ROUND_LEAVE, self::ROUND_DEACTIVATE);
        $notEqualTo = array();  // Make sure no round is imported twice
        foreach ($currentRounds as $roundId => $round) {
            if ($round instanceof Round) {
                $name  = "round_$roundId";
                $order = $round->getRoundOrder();

                $model->set($name,
                        'existingRound', true,
                        'required', true,
                        'roundId', $roundId
                        );
                if (isset($importRounds[$order])) {
                    if ($round->getFullDescription() == $importRounds[$order]) {
                        $options = array(
                            self::ROUND_LEAVE => $this->_('Leave current round'),
                            $order => $this->_('Replace with import round'),
                            );
                    } else {
                        $options = array(
                            self::ROUND_LEAVE => $this->_('Leave current round'),
                            $order => sprintf(
                                    $this->_('Replace with import round %s'),
                                    $importRounds[$order]
                                    ),
                            );
                    }
                    $model->set($name,
                            'label', sprintf(
                                    $this->_('Matching round %s'),
                                    $round->getFullDescription()
                                    ),
                            'elementClass', 'Radio',
                            'multiOptions', $options
                            );
                    $value = $order;
                } else {
                    $model->set($name,
                            'label', sprintf(
                                    $this->_('Round not in import: %s'),
                                    $round->getFullDescription()
                                    ),
                            'elementClass', 'Select',
                            'multiOptions', array(
                                self::ROUND_LEAVE => sprintf($this->_('Leave current round %d unchanged'), $order),
                                self::ROUND_DEACTIVATE => sprintf($this->_('Deactivate current round %d'), $order),
                                ) + $newImportRounds,
                            'size', 3 + count($newImportRounds)
                            );
                    $value = null;

                    if ($notEqualTo) {
                        $notEqualVal = new NotEqualExcept($notEqualTo, $except);
                        $model->set($name, 'validators[notequal]', $notEqualVal);
                    }
                    $notEqualTo[] = $name;
                }
                if (! array_key_exists($name, $this->formData)) {
                    $this->formData[$name] = $value;
                }
            }
        }
    }
39399
private void importFromCsv(File importFile){

        final AtomicInteger imported= new AtomicInteger();
        final AtomicInteger failed= new AtomicInteger();
        FileReader fileReader = null;
        try {
            fileReader = new FileReader(importFile);
            CSVReader reader = new CSVReader(fileReader);
            String[] nextLine = reader.readNext();
            while ((nextLine = reader.readNext()) != null) {
                // nextLine[] is an array of values from the line
                try {
                    String lat = nextLine[0];
                    String lon = nextLine[1];
                    String description = nextLine[2];
                    String title = nextLine[3];
                    Marker m = new Marker(getmMapView());
                    m.setTitle(title);
                    m.setSubDescription(description);
                    m.setPosition(new GeoPoint(Double.parseDouble(lat), Double.parseDouble(lon)));
                    datastore.addBookmark(m);
                    getmMapView().getOverlayManager().add(m);
                    imported.getAndIncrement();
                }catch (Exception ex) {
                    ex.printStackTrace();
                    failed.getAndIncrement();
                }
            }
        }catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (fileReader!=null)
                try {
                    fileReader.close();
                }catch (Exception ex) {}
        }

        final Activity act = getActivity();
        if (act!=null) {
            act.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(act,"Import Complete: " + imported.get() + "/" + failed.get() + "(imported/failed)", Toast.LENGTH_LONG).show();
                }
            });
        }
    }
1153950
public function addImport(string $importFilePath)
    {
        $normalizedImportPath = $this->normalizePath($importFilePath);

        $this->addSectionIfMissing($this::IMPORTS_SECTION);
        foreach ($this->getImports() as $import) {
            if ($import[$this::RESOURCE_KEY] === $normalizedImportPath) {
                return;
            }
        }
        $this->configArray[$this::IMPORTS_SECTION][] = [$this::RESOURCE_KEY => $normalizedImportPath];
    }