Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions CsvImportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ public function hookInstall()
`skipped_item_count` int(10) unsigned NOT NULL,
`is_public` tinyint(1) default '0',
`is_featured` tinyint(1) default '0',
`remove_local_files` tinyint(1) default '0',
`serialized_column_maps` text collate utf8_unicode_ci NOT NULL,
`serialized_identifier_element_ids` TEXT,
`added` timestamp NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;");
Expand All @@ -133,6 +135,19 @@ public function hookInstall()
UNIQUE (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;");

$db->query("
CREATE TABLE IF NOT EXISTS `{$db->CsvImport_Log}` (
`id` int(10) unsigned NOT NULL auto_increment,
`import_id` int(10) unsigned NOT NULL,
`priority` tinyint unsigned NOT NULL,
`created` timestamp DEFAULT CURRENT_TIMESTAMP,
`message` text NOT NULL,
`params` text DEFAULT NULL,
PRIMARY KEY (`id`),
KEY (`import_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
");

$this->_installOptions();
}

Expand Down Expand Up @@ -171,14 +186,51 @@ public function hookUpgrade($args)
set_option(CsvImport_ColumnMap_Element::ELEMENT_DELIMITER_OPTION_NAME, CsvImport_ColumnMap_Element::DEFAULT_ELEMENT_DELIMITER);
set_option(CsvImport_ColumnMap_Tag::TAG_DELIMITER_OPTION_NAME, CsvImport_ColumnMap_Tag::DEFAULT_TAG_DELIMITER);
set_option(CsvImport_ColumnMap_File::FILE_DELIMITER_OPTION_NAME, CsvImport_ColumnMap_File::DEFAULT_FILE_DELIMITER);
}
}

if(version_compare($oldVersion, '2.0.1', '<=')) {
$sql = "ALTER TABLE `{$db->prefix}csv_import_imports` CHANGE `item_type_id` `item_type_id` INT( 10 ) UNSIGNED NULL ,
CHANGE `collection_id` `collection_id` INT( 10 ) UNSIGNED NULL
";
$db->query($sql);
}

if(version_compare($oldVersion, '2.0.3', '<=')) {
$sql = "ALTER TABLE `{$db->prefix}csv_import_imports` ADD `remove_local_files` TINYINT( 1 ) DEFAULT 0 AFTER is_featured";
$db->query($sql);
}

if(version_compare($oldVersion, '2.0.4', '<=')) {
$sql = "
ALTER TABLE `{$db->prefix}csv_import_imports`
ADD `serialized_identifier_element_ids` TEXT
AFTER serialized_column_maps
";
$db->query($sql);
}

if (version_compare($oldVersion, '2.0.5', '<=')) {
$sql = "
CREATE TABLE IF NOT EXISTS `{$db->CsvImport_Log}` (
`id` int(10) unsigned NOT NULL auto_increment,
`import_id` int(10) unsigned NOT NULL,
`priority` tinyint unsigned NOT NULL,
`created` timestamp DEFAULT CURRENT_TIMESTAMP,
`message` text NOT NULL,
PRIMARY KEY (`id`),
KEY (`import_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
";
$db->query($sql);
}

if (version_compare($oldVersion, '2.0.6', '<=')) {
$sql = "
ALTER TABLE `{$db->CsvImport_Log}`
ADD COLUMN `params` text DEFAULT NULL
";
$db->query($sql);
}
}

/**
Expand Down
17 changes: 17 additions & 0 deletions controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public function indexAction()
$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->removeLocalFiles = $form->getValue('remove_local_files');
$this->session->identifierElementIds = $form->getValue('identifier_element_ids');
if (!isset($this->session->identifierElementIds)) {
$this->session->identifierElementIds = array();
}
$this->session->collectionId = $form->getValue('collection_id');

$this->session->automapColumnNamesToElements = $form->getValue('automap_columns_names_to_elements');
Expand Down Expand Up @@ -287,6 +292,16 @@ public function undoImportAction()
$this->_helper->redirector->goto('browse');
}

public function logsAction()
{
$db = $this->_helper->db;
$csvImport = $db->findById();
$logs = $db->getTable('CsvImport_Log')->findByImportId($csvImport->id);

$this->view->csvImport = $csvImport;
$this->view->logs = $logs;
}

/**
* Clear the import history.
*/
Expand Down Expand Up @@ -349,6 +364,8 @@ protected function _sessionIsValid()
{
$requiredKeys = array('itemsArePublic',
'itemsAreFeatured',
'removeLocalFiles',
'identifierElementIds',
'collectionId',
'itemTypeId',
'ownerId');
Expand Down
42 changes: 42 additions & 0 deletions forms/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public function init()
$this->addElement('checkbox', 'items_are_featured', array(
'label' => __('Feature All Items?'),
));
$this->addElement('checkbox', 'remove_local_files', array(
'label' => __('Remove local files after successful import?'),
));

$this->_addIdentifierElementIdsElement();
$this->_addColumnDelimiterElement();
$this->_addTagDelimiterElement();
$this->_addFileDelimiterElement();
Expand All @@ -86,6 +90,44 @@ public function init()
$this->addElement($submit);
}

protected function _getElementsOptions()
{
$db = get_db();
$sql = "
SELECT
es.name AS element_set_name,
e.id AS element_id,
e.name AS element_name,
it.name AS item_type_name
FROM {$db->ElementSet} es
JOIN {$db->Element} e ON es.id = e.element_set_id
LEFT JOIN {$db->ItemTypesElements} ite ON e.id = ite.element_id
LEFT JOIN {$db->ItemType} it ON ite.item_type_id = it.id
WHERE es.record_type IS NULL
OR (es.record_type = 'Item' AND it.name IS NOT NULL)
ORDER BY es.name, it.name, e.name
";
$elements = $db->fetchAll($sql);
$result = array();
foreach ($elements as $element) {
$group = $element['item_type_name']
? __('Item Type') . ': ' . __($element['item_type_name'])
: __($element['element_set_name']);
$result[$group][$element['element_id']] = $element['element_name'];
}
return $result;
}

protected function _addIdentifierElementIdsElement()
{
$this->addElement('multiselect', 'identifier_element_ids', array(
'label' => __('Choose Identifier Elements'),
'description' => __('Those elements will be compared to detect if an item already exists in database. If an item already exists, it will be skipped.'),
'size' => '6',
'multioptions' => $this->_getElementsOptions(),
));
}

/**
* Return the human readable word for a delimiter
*
Expand Down
Binary file added languages/fr.mo
Binary file not shown.
Loading