src/Subjects/AbstractSubject.php
public function import($serial, $filename)
    {

        try {
            // initialize the serial/filename
            $this->setSerial($serial);
            $this->setFilename($filename);

            // invoke the events that has to be fired before the artfact will be processed
            $this->getEmitter()->emit(EventNames::SUBJECT_ARTEFACT_PROCESS_START, $this);

            // load the system logger instance
            $systemLogger = $this->getSystemLogger();

            // prepare the flag filenames
            $inProgressFilename = sprintf('%s.inProgress', $filename);
            $importedFilename = sprintf('%s.imported', $filename);
            $failedFilename = sprintf('%s.failed', $filename);

            // query whether or not the file has already been imported
            if ($this->isFile($failedFilename) ||
                $this->isFile($importedFilename) ||
                $this->isFile($inProgressFilename)
            ) {
                // log a debug message and exit
                $systemLogger->debug(sprintf('Import running, found inProgress file %s', $inProgressFilename));
                return;
            }

            // flag file as in progress
            $this->touch($inProgressFilename);

            // track the start time
            $startTime = microtime(true);

            // initialize the last time we've logged the counter with the processed rows per minute
            $this->lastLog = time();

            // log a message that the file has to be imported
            $systemLogger->info(sprintf('Now start processing file %s', $filename));

            // let the adapter process the file
            $this->getImportAdapter()->import(array($this, 'importRow'), $filename);

            // track the time needed for the import in seconds
            $endTime = microtime(true) - $startTime;

            // log a message that the file has successfully been imported
            $systemLogger->info(sprintf('Successfully processed file %s with %d lines in %f s', $filename, $this->lineNumber, $endTime));

            // rename flag file, because import has been successfull
            if ($this->getConfiguration()->isCreatingImportedFile()) {
                $this->rename($inProgressFilename, $importedFilename);
            } else {
                $this->getFilesystemAdapter()->delete($inProgressFilename);
            }

            // invoke the events that has to be fired when the artfact has been successfully processed
            $this->getEmitter()->emit(EventNames::SUBJECT_ARTEFACT_PROCESS_SUCCESS, $this);
        } catch (\Exception $e) {
            // rename the flag file, because import failed and write the stack trace
            $this->rename($inProgressFilename, $failedFilename);
            $this->write($failedFilename, $e->__toString());

            // invoke the events that has to be fired when the artfact can't be processed
            $this->getEmitter()->emit(EventNames::SUBJECT_ARTEFACT_PROCESS_FAILURE, $this, $e);

            // do not wrap the exception if not already done
            if ($e instanceof WrappedColumnException) {
                throw $e;
            }

            // else wrap and throw the exception
            throw $this->wrapException(array(), $e);
        }
    }
public function import($serial, $filename)
    {

        try {
            // initialize the serial/filename
            $this->setSerial($serial);
            $this->setFilename($filename);

            // invoke the events that has to be fired before the artfact will be processed
            $this->getEmitter()->emit(EventNames::SUBJECT_ARTEFACT_PROCESS_START, $this);

            // load the system logger instance
            $systemLogger = $this->getSystemLogger();

            // prepare the flag filenames
            $inProgressFilename = sprintf('%s.inProgress', $filename);
            $importedFilename = sprintf('%s.imported', $filename);
            $failedFilename = sprintf('%s.failed', $filename);

            // query whether or not the file has already been imported
            if ($this->isFile($failedFilename) ||
                $this->isFile($importedFilename) ||
                $this->isFile($inProgressFilename)
            ) {
                // log a debug message and exit
                $systemLogger->debug(sprintf('Import running, found inProgress file %s', $inProgressFilename));
                return;
            }

            // flag file as in progress
            $this->touch($inProgressFilename);

            // track the start time
            $startTime = microtime(true);

            // initialize the last time we've logged the counter with the processed rows per minute
            $this->lastLog = time();

            // log a message that the file has to be imported
            $systemLogger->info(sprintf('Now start processing file %s', $filename));

            // let the adapter process the file
            $this->getImportAdapter()->import(array($this, 'importRow'), $filename);

            // track the time needed for the import in seconds
            $endTime = microtime(true) - $startTime;

            // log a message that the file has successfully been imported
            $systemLogger->info(sprintf('Successfully processed file %s with %d lines in %f s', $filename, $this->lineNumber, $endTime));

            // rename flag file, because import has been successfull
            if ($this->getConfiguration()->isCreatingImportedFile()) {
                $this->rename($inProgressFilename, $importedFilename);
            } else {
                $this->getFilesystemAdapter()->delete($inProgressFilename);
            }

            // invoke the events that has to be fired when the artfact has been successfully processed
            $this->getEmitter()->emit(EventNames::SUBJECT_ARTEFACT_PROCESS_SUCCESS, $this);
        } catch (\Exception $e) {
            // rename the flag file, because import failed and write the stack trace
            $this->rename($inProgressFilename, $failedFilename);
            $this->write($failedFilename, $e->__toString());

            // invoke the events that has to be fired when the artfact can't be processed
            $this->getEmitter()->emit(EventNames::SUBJECT_ARTEFACT_PROCESS_FAILURE, $this, $e);

            // do not wrap the exception if not already done
            if ($e instanceof WrappedColumnException) {
                throw $e;
            }

            // else wrap and throw the exception
            throw $this->wrapException(array(), $e);
        }
    }
Imports the content of the file with the passed filename.


@param string $serial   The serial of the actual import
@param string $filename The filename to process

@return void
@throws \Exception Is thrown, if the import can't be processed