/** * Configure a new import. */ public function indexAction() { $form = $this->_getMainForm(); $this->view->form = $form; if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { $this->_helper->flashMessenger(__('Invalid form input. Please see errors below and try again.'), 'error'); return; } if (!$form->csv_file->receive()) { $this->_helper->flashMessenger(__('Error uploading file. Please try again.'), 'error'); return; } $filePath = $form->csv_file->getFileName(); $columnDelimiter = $form->getValue('column_delimiter'); $file = new CsvImport_File($filePath, $columnDelimiter); if (!$file->parse()) { $this->_helper->flashMessenger(__('Your file is incorrectly formatted.') . ' ' . $file->getErrorString(), 'error'); return; } $this->session->setExpirationHops(2); $this->session->originalFilename = $_FILES['csv_file']['name']; $this->session->filePath = $filePath; $this->session->columnDelimiter = $columnDelimiter; $this->session->columnNames = $file->getColumnNames(); $this->session->columnExamples = $file->getColumnExamples(); $this->session->fileDelimiter = $form->getValue('file_delimiter'); $this->session->tagDelimiter = $form->getValue('tag_delimiter'); $this->session->elementDelimiter = $form->getValue('element_delimiter'); $this->session->itemTypeId = $form->getValue('item_type_id'); $this->session->itemsArePublic = $form->getValue('items_are_public'); $this->session->itemsAreFeatured = $form->getValue('items_are_featured'); $this->session->collectionId = $form->getValue('collection_id'); $this->session->automapColumnNamesToElements = $form->getValue('automap_columns_names_to_elements'); $this->session->ownerId = $this->getInvokeArg('bootstrap')->currentuser->id; // All is valid, so we save settings. set_option(CsvImport_RowIterator::COLUMN_DELIMITER_OPTION_NAME, $this->session->columnDelimiter); set_option(CsvImport_ColumnMap_Element::ELEMENT_DELIMITER_OPTION_NAME, $this->session->elementDelimiter); set_option(CsvImport_ColumnMap_Tag::TAG_DELIMITER_OPTION_NAME, $this->session->tagDelimiter); set_option(CsvImport_ColumnMap_File::FILE_DELIMITER_OPTION_NAME, $this->session->fileDelimiter); if ($form->getValue('omeka_csv_export')) { $this->_helper->redirector->goto('check-omeka-csv'); } $this->_helper->redirector->goto('map-columns'); }
/** * Configure a new import (first step). */ public function indexAction() { $form = $this->_getMainForm(); $this->view->form = $form; if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { $this->_helper->flashMessenger(__('Invalid form input. Please see errors below and try again.'), 'error'); return; } if (!$form->csv_file->receive()) { $this->_helper->flashMessenger(__('Error uploading file. Please try again.'), 'error'); return; } $filePath = $form->csv_file->getFileName(); $delimitersList = self::getDelimitersList(); $columnDelimiterName = $form->getValue('column_delimiter_name'); $columnDelimiter = isset($delimitersList[$columnDelimiterName]) ? $delimitersList[$columnDelimiterName] : $form->getValue('column_delimiter'); $enclosuresList = self::getEnclosuresList(); $enclosureName = $form->getValue('enclosure_name'); $enclosure = isset($enclosuresList[$enclosureName]) ? $enclosuresList[$enclosureName] : $form->getValue('enclosure'); $file = new CsvImport_File($filePath, $columnDelimiter, $enclosure); if (!$file->parse()) { $this->_helper->flashMessenger(__('Your file is incorrectly formatted.') . ' ' . $file->getErrorString(), 'error'); return; } $identifierField = $this->_elementNameFromPost($form->getValue('identifier_field')); $this->session->setExpirationHops(2); $this->session->originalFilename = $_FILES['csv_file']['name']; $this->session->filePath = $filePath; $this->session->action = $form->getValue('action'); $this->session->identifierField = $identifierField; $this->session->itemTypeId = $form->getValue('item_type_id'); $this->session->collectionId = $form->getValue('collection_id'); $this->session->recordsArePublic = $form->getValue('records_are_public'); $this->session->recordsAreFeatured = $form->getValue('records_are_featured'); $this->session->elementsAreHtml = $form->getValue('elements_are_html'); $this->session->containsExtraData = $form->getValue('contains_extra_data'); $this->session->columnDelimiter = $columnDelimiter; $this->session->enclosure = $enclosure; $this->session->columnNames = $file->getColumnNames(); $this->session->columnExamples = $file->getColumnExamples(); // A bug appears when examples contain UTF-8 characters like 'ГЧ„чŁ'. // The bug is only here, not during import of characters into database. foreach ($this->session->columnExamples as &$value) { $value = iconv('ISO-8859-15', 'UTF-8', @iconv('UTF-8', 'ISO-8859-15' . '//IGNORE', $value)); } $elementDelimiterName = $form->getValue('element_delimiter_name'); $this->session->elementDelimiter = isset($delimitersList[$elementDelimiterName]) ? $delimitersList[$elementDelimiterName] : $form->getValue('element_delimiter'); $tagDelimiterName = $form->getValue('tag_delimiter_name'); $this->session->tagDelimiter = isset($delimitersList[$tagDelimiterName]) ? $delimitersList[$tagDelimiterName] : $form->getValue('tag_delimiter'); $fileDelimiterName = $form->getValue('file_delimiter_name'); $this->session->fileDelimiter = isset($delimitersList[$fileDelimiterName]) ? $delimitersList[$fileDelimiterName] : $form->getValue('file_delimiter'); $this->session->ownerId = $this->getInvokeArg('bootstrap')->currentuser->id; // All is valid, so we save settings. set_option(CsvImport_ColumnMap_IdentifierField::IDENTIFIER_FIELD_OPTION_NAME, $this->session->identifierField); set_option(CsvImport_RowIterator::COLUMN_DELIMITER_OPTION_NAME, $this->session->columnDelimiter); set_option(CsvImport_RowIterator::ENCLOSURE_OPTION_NAME, $this->session->enclosure); set_option(CsvImport_ColumnMap_Element::ELEMENT_DELIMITER_OPTION_NAME, $this->session->elementDelimiter); set_option(CsvImport_ColumnMap_Tag::TAG_DELIMITER_OPTION_NAME, $this->session->tagDelimiter); set_option(CsvImport_ColumnMap_File::FILE_DELIMITER_OPTION_NAME, $this->session->fileDelimiter); set_option('csv_import_html_elements', $this->session->elementsAreHtml); set_option('csv_import_extra_data', $this->session->containsExtraData); if ($this->session->containsExtraData == 'manual') { $this->_helper->redirector->goto('map-columns'); } $this->_helper->redirector->goto('check-manage-csv'); }