protected function prepareLocale() {
        global $conf;
        global $language;

        $country = isset($conf['site_default_country']) ? trim($conf['site_default_country']) : '';
        if ($country === '') {
            $country = 'us';
            LogHelper::log_warn(t("Default country was not defined. Go to 'Configuration' | 'Regional and language' | 'Regional settings' to set default country"));
        }

        $localeSubTags = array('language' => $language->language, 'region' => $country);

        return Locale::composeLocale($localeSubTags);
    }
Ejemplo n.º 2
0
/**
* This file is part of the Checkbook NYC financial transparency software.
* 
* Copyright (C) 2012, 2013 New York City
* 
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Affero General Public License for more details.
* 
* You should have received a copy of the GNU Affero General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
function ContentTypeDatasetSourceAssembler_nodereference(DatasetSourceAssembler $assembler, DataControllerCallContext $callcontext, $parameterNames, $statement, $tableIndex, $supportedField)
{
    $tableAlias = $assembler->prepareTableAlias($tableIndex);
    $field = $assembler->config->drupal['fields'][$supportedField->original_name];
    // preparing referenceable content type
    $referenceableContentTypes = array_keys(array_filter($field['referenceable_types']));
    if (count($referenceableContentTypes) != 1) {
        $message = t("Unsupported configuration for referenced types for '@supportedFieldName' field: [@contentTypes]", array('@supportedFieldName' => $supportedField->name, '@contentTypes' => implode(', ', $referenceableContentTypes)));
        LogHelper::log_warn($message);
        return;
    }
    $referenceableContentType = $referenceableContentTypes[0];
    $referenceableContentTypeKey = 'nid';
    // preparing list of parameters which should be supported by the referenceable content type
    // if parameter names are not defined we should return all available parameters
    $contentTypeParameterNames = NULL;
    if (isset($parameterNames)) {
        $parameterNamePrefix = $supportedField->name . '_';
        foreach ($parameterNames as $parameterName) {
            if (strpos($parameterName, $parameterNamePrefix) === 0) {
                $contentTypeParameterName = substr($parameterName, strlen($parameterNamePrefix));
                $contentTypeParameterNames[] = $contentTypeParameterName;
            }
        }
        if (!isset($contentTypeParameterNames)) {
            return;
        }
    }
    if (isset($contentTypeParameterNames)) {
        // we will use the field to link with parent content type
        $contentTypeParameterNames[] = $referenceableContentTypeKey;
    }
    // adding check to prevent recursive/circular references
    if ($assembler->registerContentTypeInStack($callcontext, $referenceableContentType)) {
        // requesting SQL sections related to the content type
        $contentTypeDatasetName = DrupalContentTypeMetaModelLoader::getDatasetName($referenceableContentType);
        $contentTypeDataset = $callcontext->metamodel->getDataset($contentTypeDatasetName);
        $contentTypeTableAliasPrefix = $assembler->prepareColumnAlias($supportedField->name);
        $contentTypeAssembler = new ContentTypeDatasetSourceAssembler($contentTypeDataset->source->assembler->config, $contentTypeTableAliasPrefix);
        $contentTypeStatement = $contentTypeAssembler->assemble($callcontext, $contentTypeParameterNames);
        // adding condition to join with 'main' statement
        $contentTypeTableSection = $contentTypeStatement->tables[0];
        $contentTypeTableSection->conditions[] = new JoinConditionSection($referenceableContentTypeKey, new TableColumnConditionSectionValue($tableAlias, $supportedField->column));
        // merging with 'main' statement
        $statement->merge($contentTypeStatement);
        $assembler->unregisterContentTypeFromStack($callcontext, $referenceableContentType);
    }
}
    public static function getExportColumnName ( $uiMetaDataName, MetaModel $metamodel ) {

        if ( trim($uiMetaDataName) == '' ) {
            $message = t('Empty columnName discovered');
            drupal_set_message($message, 'warning');
            LogHelper::log_warn($message);

            return $uiMetaDataName;
        }


        list($elementNameSpace, $name) = AbstractDatasetUIMetaDataGenerator::splitElementUIMetaDataName($uiMetaDataName);
        switch ( $elementNameSpace ) {

            case AbstractAttributeUIMetaData::NAME_SPACE:
                list($referencedDimensionName, $dimensionColumnName) = ParameterNameHelper::split($name);
                list($datasetName, $dimensionName) = ReferencePathHelper::splitReference($referencedDimensionName);
                if (isset($datasetName)) {
                    $adjustedReferencedDimensionName = ReferencePathHelper::assembleReference(self::getExportDatasetName($datasetName,$metamodel), $dimensionName);
                    $name = ParameterNameHelper::assemble($adjustedReferencedDimensionName, $dimensionColumnName);
                }
                break;

            case AbstractMeasureUIMetaData::NAME_SPACE:
                list($datasetName, $measureName) = ReferencePathHelper::splitReference($name);
                if (isset($datasetName)) {
                    $name = ReferencePathHelper::assembleReference(self::getExportDatasetName($datasetName,$metamodel), $measureName);
                }
                break;

            case FormulaUIMetaData::NAME_SPACE:
                list($datasetName, $formulaName) = ReferencePathHelper::splitReference($name);
                if (isset($datasetName)) {
                    $name = ReferencePathHelper::assembleReference(self::getExportDatasetName($datasetName,$metamodel), $formulaName);
                }
                break;

            default:
                $message = t('Unsupported UI Meta Data name space: @uiMetaDataName', array('@uiMetaDataName' => $uiMetaDataName));
                LogHelper::log_error($message);
                throw new UnsupportedOperationException($message);
        }

        return AbstractDatasetUIMetaDataGenerator::prepareElementUIMetaDataName($elementNameSpace, $name);
    }
    protected function processReferences(SystemTableMetaModelLoaderCallContext $callcontext, DataSourceMetaData $datasource) {
        $foreignKeyConstraintCount = 0;

        $constraintsProperties = $this->loadReferenceConstraintsProperties($callcontext, $datasource);
        if (isset($constraintsProperties)) {
            $constraintsColumnsPropertyFormatter = new QueryKeyResultFormatter(array(self::CN_TABLE_OWNER, self::CN_OBJECT_NAME), FALSE);
            $constraintsColumnsProperties = $constraintsColumnsPropertyFormatter->formatRecords(
                $this->loadConstraintColumnsProperties(
                    $callcontext, $datasource,
                    array(self::CONSTRAINT_TYPE__PRIMARY_KEY, self::CONSTRAINT_TYPE__REFERENCE)));

            foreach ($constraintsProperties as $constraintProperties) {
                $tableOwner = $this->adjustOwnerName($constraintProperties[self::CN_TABLE_OWNER]);

                // ---------- preparing referring constraint properties
                $constraintName = $constraintProperties[self::CN_OBJECT_NAME];
                $constraintAccessKey = ArrayHelper::prepareCompositeKey(array($tableOwner, $constraintName));
                // for some reason we do not have access to column configuration for referring constraint
                if (!isset($constraintsColumnsProperties[$constraintAccessKey])) {
                    continue;
                }
                $constraintColumnsProperties = $constraintsColumnsProperties[$constraintAccessKey];
                // we do not support composite references yet
                if (count($constraintColumnsProperties) > 1) {
                    continue;
                }

                // ----------- preparing referenced constraint properties
                $refConstraintName = $constraintProperties[self::CN_REFERENCED_OBJECT_NAME];
                $refConstraintAccessKey = ArrayHelper::prepareCompositeKey(array($tableOwner, $refConstraintName));
                // for some reason we do not have access to column configuration for referenced constraint
                if (!isset($constraintsColumnsProperties[$refConstraintAccessKey])) {
                    continue;
                }

                $constraintColumnProperties = $constraintColumnsProperties[0];
                $tableName = $this->adjustTableName($constraintColumnProperties[self::CN_TABLE_NAME]);
                $tableAccessKey = ArrayHelper::prepareCompositeKey(array($tableOwner, $tableName));
                if (!isset($callcontext->datasets[$tableAccessKey])) {
                    continue;
                }

                $refConstraintColumnProperties = $constraintsColumnsProperties[$refConstraintAccessKey][0];
                $refTableName = $this->adjustTableName($refConstraintColumnProperties[self::CN_TABLE_NAME]);
                $refTableAccessKey = ArrayHelper::prepareCompositeKey(array($tableOwner, $refTableName));
                if (!isset($callcontext->datasets[$refTableAccessKey])) {
                    continue;
                }

                $columnName = $this->adjustColumnName($constraintColumnProperties[self::CN_COLUMN_NAME]);
                $refColumnName = $this->adjustColumnName($refConstraintColumnProperties[self::CN_COLUMN_NAME]);

                if ($tableName == $refTableName) {
                    LogHelper::log_warn(t(
                        "Self-reference is not supported yet: @tableName(@columnName)",
                        array('@tableName' => $tableName, '@columnName' => $columnName)));
                    continue;
                }

                $dataset = $callcontext->datasets[$tableAccessKey];
                $column = $dataset->findColumn($columnName);
                if (!isset($column)) {
                    continue;
                }

                $refDataset = $callcontext->datasets[$refTableAccessKey];
                $refColumn = $refDataset->findColumn($refColumnName);
                if (!isset($refColumn)) {
                    continue;
                }

                $logicalApplicationType = ReferencePathHelper::assembleReference($refDataset->name, $refColumnName);
                if (isset($column->type->logicalApplicationType)) {
                    LogHelper::log_warn(t(
                        "Multi-reference is not supported yet for '@columnName' column from '@tableName' table: [@referenceExisting, @referenceNew]",
                        array(
                            '@tableName' => $tableName,
                            '@columnName' => $columnName,
                            '@referenceExisting' => $column->type->logicalApplicationType,
                            '@referenceNew' => $logicalApplicationType)));
                    continue;
                }

                $column->type->logicalApplicationType = $logicalApplicationType;
                $foreignKeyConstraintCount++;
            }
        }

        LogHelper::log_info(t(
            'Processed system meta data about @constraintCount foreign key constraint(s)',
            array('@constraintCount' => $foreignKeyConstraintCount)));
    }
    protected function processConfig ( $export ) {
        $metamodel = data_controller_get_metamodel();

        // replace report nid with report uuid
        foreach ( $export->config->items as $key => $item ) {
            if ( $item->type == 'report' ) {
                $reportNode = node_load($item->content);
                $export->config->items[$key]->content = get_node_field_value($reportNode,'field_report_uuid',0,'value',true);
            }
        }

        // array cast to deal with json decoder creating objects for arrays with missing keys
        $export->config->drilldowns = (array) $export->config->drilldowns;

        // replace report nid with report uuid
        // replace dashboard nid with dashboard uuid
        // replace dataset column reference with dataset uuid
        $updated_drilldowns = array();
        foreach ( $export->config->drilldowns as $drilldown ) {

            $reportNode = gd_report_get_by_nid($drilldown->report);
            $dashboardNode = gd_dashboard_get_by_nid($drilldown->dashboard);

            if ( !$reportNode || !$dashboardNode ) {
                $message = t('Skipping corrupt drilldown for node: @nodeId.',array('@nodeId' => $export->id));
                drupal_set_message($message, 'warning');
                LogHelper::log_warn($message);
            } else {
                $updated_drilldown = $drilldown;
                $updated_drilldown->report = get_node_field_value($reportNode,'field_report_uuid',0,'value',true);
                $updated_drilldown->column = DatasetExportHelper::getExportColumnName($drilldown->column,$metamodel);
                $updated_drilldown->dashboard = get_node_field_value($dashboardNode,'field_dashboard_uuid',0,'value',true);
                $updated_drilldown->id = count($updated_drilldowns);
                $updated_drilldowns[] = $updated_drilldown;
            }
        }

        $export->config->drilldowns = $updated_drilldowns;
    }
 public function load(AbstractMetaModelFactory $factory, AbstractMetaModel $metamodel, array $filters = NULL, $finalAttempt)
 {
     LogHelper::log_notice(t('Creating Meta Model using Drupal Content Types...'));
     $datasetCounter = 0;
     $contentTypes = content_types();
     if (isset($contentTypes)) {
         foreach ($contentTypes as $contentTypeName => $contentType) {
             // preparing list of tables which could be supported by our code
             $supportedTables = NULL;
             foreach ($contentType['fields'] as $field) {
                 $fieldName = $field['field_name'];
                 if ($field['multiple'] > 0) {
                     $message = t('Multiple values are not supported yet: @contentTypeName.@fieldName', array('@contentTypeName' => $contentTypeName, '@fieldName' => $fieldName));
                     LogHelper::log_warn($message);
                     continue;
                     // UnsupportedOperationException
                 }
                 // preparing table name where the field is stored
                 $fieldStorage = $field['db_storage'];
                 switch ($fieldStorage) {
                     case CONTENT_DB_STORAGE_PER_CONTENT_TYPE:
                         $tableName = _content_tablename($field['type_name'], $fieldStorage);
                         break;
                     case CONTENT_DB_STORAGE_PER_FIELD:
                         break;
                         $tableName = _content_tablename($fieldName, $fieldStorage);
                     default:
                         $message = t("Unsupported storage type - '@fieldStorage' for the field: @fieldName", array('@fieldStorage' => $fieldStorage, '@fieldName' => $fieldName));
                         LogHelper::log_warn($message);
                         continue;
                         // UnsupportedOperationException
                 }
                 // calculating number of 'visible' suffixes
                 $visibleSuffixCount = 0;
                 foreach ($field['columns'] as $columnAttributes) {
                     if (isset($columnAttributes['views'])) {
                         if ($columnAttributes['views'] === TRUE) {
                             $visibleSuffixCount++;
                         }
                     } else {
                         $visibleSuffixCount++;
                     }
                 }
                 // generating fields for all 'visible' suffixes
                 foreach ($field['columns'] as $columnSuffix => $columnAttributes) {
                     if (isset($columnAttributes['views']) && $columnAttributes['views'] === FALSE) {
                         continue;
                     }
                     $supportedField = new stdClass();
                     // required flag
                     $supportedField->required = $field->required == 1;
                     // original name of the field
                     $supportedField->original_name = $fieldName;
                     // calculating name of database column
                     $supportedField->column = $fieldName . '_' . $columnSuffix;
                     // field name
                     if ($visibleSuffixCount === 1) {
                         $supportedField->name = $fieldName;
                     } else {
                         $supportedField->name = $supportedField->column;
                     }
                     if (isset($supportedTables[$tableName]->storage)) {
                         $previousStorage = $supportedTables[$tableName]->storage;
                         if ($fieldStorage != $previousStorage) {
                             $message = t("Inconsistent storage for '@tableName' table([@fieldStorage1, @fieldStorage2]) for the field: @fieldName", array('@tableName' => $tableName, '@fieldName' => $fieldName, '@fieldStorage1' => $previousStorage, '@fieldStorage2' => $fieldStorage));
                             LogHelper::log_warn($message);
                             continue;
                             // IllegalStateException
                         }
                     } else {
                         $supportedTables[$tableName]->storage = $fieldStorage;
                     }
                     $supportedTables[$tableName]->supportedFields[$supportedField->name] = $supportedField;
                 }
             }
             // preparing dataset source
             $datasetSource = new stdClass();
             $datasetSource->assembler->type = ContentTypeDatasetSourceAssembler::$DATASET_SOURCE_ASSEMBLER__TYPE;
             $datasetSource->assembler->config->drupal = $contentType;
             if (isset($supportedTables)) {
                 $datasetSource->assembler->config->supportedTables = $supportedTables;
             }
             // preparing & registering dataset
             $dataset = new DatasetMetaData();
             $dataset->name = $this->getDatasetName($contentTypeName);
             $dataset->description = $contentType['description'];
             $dataset->datasourceName = AbstractDrupalDataSourceQueryProxy::$DATASOURCE_NAME__DEFAULT;
             $dataset->source = $datasetSource;
             // FIXME Populate list of columns and mark the dataset as complete
             $dataset->registerColumn('nid')->key = TRUE;
             $metamodel->registerDataset($dataset);
             $datasetCounter++;
         }
     }
     LogHelper::log_info(t('Processed @datasetCount datasets', array('@datasetCount' => $datasetCounter)));
     return self::LOAD_STATE__SUCCESSFUL;
 }
    public static function oci_free_statement($connection, $statement) {
        self::checkOCIExtension('oci_free_statement');

        $result = @oci_free_statement($statement);
        if ($result === FALSE) {
            $error = self::oci_error($statement);
            LogHelper::log_warn(t(
                'Could not free all resources associated with statement or cursor: @error',
                array('@error' => t($error['message']))));
        }
    }
    protected function applyPagination($url, AbstractQueryRequest $request) {
        if (isset($request->startWith) && ($request->startWith > 0)) {
            $url .= ((strpos($url, '?') === FALSE) ? '?' : '&') . "skip=$request->startWith";
        }

        $limit = $request->limit;
        // if keys and limit are not set it could be just a bug. We cannot load all data.
        // The database can be huge. We will load limited (preset) number of records
        if (!isset($limit)) {
            $keys = $this->prepareDocumentIdentifiers($request);
            if (!isset($keys)) {
                $limit = self::$MAX_LOADED_DOCUMENTS;
                LogHelper::log_warn(t(
                	'Loading maximum @limit records for the request: @datasetName',
                    array('@limit' => $limit, '@datasetName' => $request->getDatasetName())));
            }
        }
        if (isset($limit)) {
            $url .= ((strpos($url, '?') === FALSE) ? '?' : '&') . "limit=$limit";
        }

        return $url;
    }
    protected function getQueryFilters () {
        $query_filters = array();
        foreach ( $this->filters as $f ) {

            if ( empty($f->column) || empty($f->name) ) {
                LogHelper::log_warn('Missing filter name or column.');
                continue;
            }

            //  if a filter is pre-apply, generate an operator for it.
            if ( !$f->exposed ) {
                //  If there is a value, then format it otherwise leave it as null
                $value = isset($f->value) ? $this->formatFilterValue($f->value, $this->getColumn($f->column)) : null;
                $query_filters[$f->column][] = OperatorFactory::getInstance()->initiateHandler($f->operator,$value);
            }

            if ( $f->exposed ) {
                $requestFilter = FALSE;
                //  Check for query filters next
                if ( !empty($_REQUEST['t']) ) {
                    foreach ( $_REQUEST['t'] as $dashboardId => $requestFilters ) {
                        if ($dashboardId == $this->dashboard) {
                            foreach ($requestFilters as $filterName => $filterParams) {
                                if ( $f->name == $filterName && is_array($filterParams) ) {
                                    $requestFilter = TRUE;
                                    //  If there is a value, then format it otherwise leave it as null
                                    $value = isset($filterParams['v']) ? $this->formatFilterValue($filterParams['v'], $this->getColumn($f->column)) : null;
                                    $query_filters[$f->column][] = OperatorFactory::getInstance()->initiateHandler($filterParams['o'],$value);
                                }
                            }
                        }
                    }
                }

                if ( !empty($f->operator) && !$requestFilter) {
                    //  If a filter is exposed and has a default value for it, set it
                    $value = isset($f->value) ? $this->formatFilterValue($f->value, $this->getColumn($f->column)) : null;
                    $query_filters[$f->column][] = OperatorFactory::getInstance()->initiateHandler($f->operator,$value);
                }
            }
        }

        return $query_filters;
    }
 protected static function registerFactMeasure(CubeMetaData $cube, ColumnMetaData $column, $functionName, $additivity, $selectedApplicationType = NULL)
 {
     $measureName = StarSchemaNamingConvention::getFactRelatedMeasureName($column->name, $functionName);
     $measure = $cube->registerMeasure($measureName);
     $measure->publicName = t($functionName);
     $measure->description = t("System generated '@functionName' measure for '@columnName' column", array('@functionName' => $measure->publicName, '@columnName' => $column->publicName));
     $measure->used = FALSE;
     $expression = FALSE;
     if ($column->persistence == FormulaMetaData::PERSISTENCE__CALCULATED) {
         if ($column->isUsed()) {
             try {
                 $expressionAssembler = new FormulaExpressionAssembler($cube->factsDataset);
                 $expression = $expressionAssembler->assemble($column);
                 $measure->used = TRUE;
             } catch (Exception $e) {
                 $message = t("@functionName measure assembled with errors. @error", array('@functionName' => $functionName, '@error' => $e->getMessage()));
                 $measure->functionError = $message;
                 LogHelper::log_warn($message);
             }
         } else {
             $measure->functionError = t("@functionName measure was not assembled for the unused column", array('@functionName' => $functionName));
         }
     } else {
         $formulaExpressionParser = new FormulaExpressionParser(SQLFormulaExpressionHandler::LANGUAGE__SQL);
         $expression = $formulaExpressionParser->assemble($column->name);
         $measure->used = TRUE;
     }
     $measure->function = $expression === FALSE ? FALSE : $functionName . '(' . $expression . ')';
     $measure->additivity = $additivity;
     $measure->type->applicationType = isset($selectedApplicationType) ? $selectedApplicationType : $column->type->applicationType;
     $measure->type->scale = $column->type->scale;
 }
    protected function publishExceptions($abort) {
        $originalExceptionCount = $this->exceptionCount;

        if (isset($this->exceptionPool)) {
            foreach ($this->exceptionPool as $recordNumber => $columnsException) {
                foreach ($columnsException as $columnPublicName => $exceptionInfo) {
                    $message = $exceptionInfo['message'] . t(
                        ' [column: @columnName] [line: @lineNumber]',
                        array('@columnName' => $columnPublicName, '@lineNumber' => $recordNumber));

                    LogHelper::log_warn(t(
                        '@message at @file:@line',
                        array('@message' => $message, '@file' => $exceptionInfo['file'], '@line' => $exceptionInfo['line'])));

                    drupal_set_message($message, 'error');
                }
            }
        }
        $this->cleanInternalState();

        if ($abort && ($originalExceptionCount > 0)) {
            throw new DataParserException(t(
                'Found %exceptionCount issue(s) while parsing data',
                array('%exceptionCount' => $originalExceptionCount)));
        }
    }
    public function parse(AbstractDataProvider $dataProvider, array $dataSubmitters = NULL) {
        $skippedRecordCount = 0;
        $loadedRecordCount = 0;

        $timeStart = microtime(TRUE);
        if ($dataProvider->openResource()) {
            LogHelper::log_notice(t(
                'Parsing @limitRecordCount records. Skipping first @skipRecordCount records (memory usage: @memoryUsed) ...',
                array(
                    '@skipRecordCount' => $this->skipRecordCount,
                    '@limitRecordCount' => (isset($this->limitRecordCount) ? $this->limitRecordCount : t('all')),
                    '@memoryUsed' => memory_get_usage())));

            try {
                if ($this->initializeProcessing($dataSubmitters)) {
                    // preparing list of columns
                    $this->prepareMetaData($dataProvider, $dataSubmitters);

                    $metadataColumnCount = $this->metadata->getColumnCount(FALSE, TRUE);

                    if ((!isset($this->limitRecordCount) || ($this->limitRecordCount > 0))
                            && $this->executeBeforeProcessingRecords($dataSubmitters, $dataProvider)) {
                        // processing records
                        $fileProcessedCompletely = FALSE;
                        while (!isset($this->limitRecordCount) || ($loadedRecordCount < $this->limitRecordCount)) {
                            $dataProvider->startReading();
                            $record = $this->parseNextRecord($dataProvider, $dataSubmitters);

                            // number of loaded columns should match number of columns in meta data
                            if (isset($record)) {
                                $attempt = 1;
                                while (TRUE) {
                                    $recordColumnCount = count($record);
                                    if ($recordColumnCount == $metadataColumnCount) {
                                        break;
                                    }
                                    else {
                                        if ($attempt > self::$MAX_ATTEMPTS_TO_RESOLVE_PARSING_ISSUES) {
                                            $dataProvider->endReading();
                                            LogHelper::log_debug($this->metadata);
                                            LogHelper::log_debug($record);
                                            throw new DataParserException(t(
                                                'Expected to load values for %metadataColumnCount columns. Loaded %loadedColumnCount [line: %lineNumber]',
                                                array('%metadataColumnCount' => $metadataColumnCount, '%loadedColumnCount' => $recordColumnCount, '%lineNumber' => $dataProvider->getCurrentLineNumber())));
                                        }

                                        $dataProvider->rollbackReading();
                                        $dataProvider->startReading();
                                        $record = $this->parseNextRecord($dataProvider, $dataSubmitters, $attempt);

                                        $attempt++;
                                    }
                                }
                            }
                            $dataProvider->endReading();

                            // checking if we reached the end
                            if (!isset($record)) {
                                $fileProcessedCompletely  = TRUE;
                                break;
                            }

                            // skipping required number of records
                            if ($skippedRecordCount < $this->skipRecordCount) {
                                $skippedRecordCount++;
                                continue;
                            }

                            $this->postProcessColumnValues($record);

                            // checking if we need to skip processing the record
                            $recordNumber = $dataProvider->getCurrentLineNumber();
                            if ($this->executeBeforeRecordSubmitted($dataSubmitters, $recordNumber, $record)) {
                                $this->submitRecord($dataSubmitters, $recordNumber, $record);
                                $this->executeAfterRecordSubmitted($dataSubmitters, $recordNumber, $record);

                                $loadedRecordCount++;
                                if (($loadedRecordCount % 1000) == 0) {
                                    LogHelper::log_info(t(
                                        'Processed @recordCount records so far (memory usage: @memoryUsed)',
                                        array('@recordCount' => $loadedRecordCount, '@memoryUsed' => memory_get_usage())));
                                }
                            }
                        }

                        $this->executeAfterProcessingRecords($dataSubmitters, $fileProcessedCompletely);
                    }

                    $this->finishProcessing($dataSubmitters);
                }
            }
            catch (DataParserException $e) {
                LogHelper::log_warn(t('Place of original exception @file:@line', array('@file' => $e->getFile(), '@line' => $e->getLine())));

                try {
                    $this->abortProcessing($dataSubmitters);
                }
                catch (Exception $ne) {
                    // we do not need to rethrow this exception. We need to preserve and rethrow original exception
                    LogHelper::log_error($ne);
                }

                try {
                    $dataProvider->closeResource();
                }
                catch (Exception $ne) {
                    // we do not need to rethrow this exception. We need to preserve and rethrow original exception
                    LogHelper::log_error($ne);
                }

                throw new IllegalStateException($e->getMessage());
            }
            catch (Exception $e) {
                LogHelper::log_warn(t('Place of original exception @file:@line', array('@file' => $e->getFile(), '@line' => $e->getLine())));

                try {
                    $this->abortProcessing($dataSubmitters);
                }
                catch (Exception $ne) {
                    // we do not need to rethrow this exception. We need to preserve and rethrow original exception
                    LogHelper::log_error($ne);
                }

                $ise = new IllegalStateException(
                    ExceptionHelper::getExceptionMessage($e) . t(' [%lineNumber line(s) parsed so far]', array('%lineNumber' => $dataProvider->getCurrentLineNumber())),
                    0, $e);
                try {
                    $dataProvider->closeResource();
                }
                catch (Exception $ne) {
                    // we do not need to rethrow this exception. We need to preserve and rethrow original exception
                    LogHelper::log_error($ne);
                }

                throw $ise;
            }

            $dataProvider->closeResource();
        }

        LogHelper::log_notice(t(
            'Processing @recordCount record(s) took !executionTime',
            array('@recordCount' => $loadedRecordCount, '!executionTime' => LogHelper::formatExecutionTime($timeStart))));

        return $loadedRecordCount;
    }