diff --git a/CsvImportPlugin.php b/CsvImportPlugin.php index 790f8d7..60fe0c4 100644 --- a/CsvImportPlugin.php +++ b/CsvImportPlugin.php @@ -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;"); @@ -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(); } @@ -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); + } } /** diff --git a/controllers/IndexController.php b/controllers/IndexController.php index 4b0bd05..7fa43ea 100644 --- a/controllers/IndexController.php +++ b/controllers/IndexController.php @@ -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'); @@ -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. */ @@ -349,6 +364,8 @@ protected function _sessionIsValid() { $requiredKeys = array('itemsArePublic', 'itemsAreFeatured', + 'removeLocalFiles', + 'identifierElementIds', 'collectionId', 'itemTypeId', 'ownerId'); diff --git a/forms/Main.php b/forms/Main.php index c07ee01..55828e6 100644 --- a/forms/Main.php +++ b/forms/Main.php @@ -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(); @@ -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 * diff --git a/languages/fr.mo b/languages/fr.mo new file mode 100644 index 0000000..f0a60e4 Binary files /dev/null and b/languages/fr.mo differ diff --git a/languages/fr.po b/languages/fr.po new file mode 100644 index 0000000..cf6e7d6 --- /dev/null +++ b/languages/fr.po @@ -0,0 +1,575 @@ +# Translation for the Csv Import plugin for Omeka. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the Omeka package. +# +# Translators: +# fiuzzy , 2015 +# Isabelle Gilles , 2015 +# Stéphane Loret Sdj , 2015 +# symac , 2014 +msgid "" +msgstr "" +"Project-Id-Version: Omeka\n" +"Report-Msgid-Bugs-To: https://github.com/omeka/plugin-CsvImport/issues\n" +"POT-Creation-Date: 2013-03-06 00:06+0900\n" +"PO-Revision-Date: 2015-04-14 19:40+0000\n" +"Last-Translator: Isabelle Gilles \n" +"Language-Team: French (http://www.transifex.com/omeka/omeka/language/fr/)\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +msgid "Import Items" +msgstr "Importer les contenus" + +#: views/admin/index/browse.php:6 views/admin/index/browse.php:19 +msgid "Status" +msgstr "Statut" + +msgid "Queued" +msgstr "En attente" + +msgid "In Progress" +msgstr "En cours" + +msgid "Completed" +msgstr "Terminé" + +msgid "Queued Undo" +msgstr "Annulations en attente" + +msgid "Undo In Progress" +msgstr "Annulations en cours" + +msgid "Completed Undo" +msgstr "Annulations terminées" + +msgid "Import Error" +msgstr "Erreur d'importation" + +msgid "Undo Import Error" +msgstr "Erreur d'annulation" + +msgid "Other Error" +msgstr "Autres erreurs" + +msgid "Stopped" +msgstr "Arrêté" + +msgid "Paused" +msgstr "En pause" + +msgid "Started import." +msgstr "Import démarré." + +msgid "Cannot complete an import that is already completed." +msgstr "Impossible de terminer un import déjà terminé." + +#, php-format +msgid "Completed importing %1$s items (skipped %2$s items, %3$s rows)." +msgstr "" +"Import terminé: %1$s contenus importés (ignorés: %2$s contenus et %3$s lignes)." + +msgid "Cannot complete an undo import that is already undone." +msgstr "Impossible de terminer l'annulation d'un import déjà annulé." + +msgid "Completed undoing the import." +msgstr "Annulations de l'import terminées" + +msgid "Cannot resume an import or undo import that has not been queued." +msgstr "" +"Impossible de reprendre ou d'annuler un import qui n'a pas été mis en " +"file d'attente." + +msgid "Resumed import." +msgstr "Import repris." + +msgid "Resumed undo import." +msgstr "Annulation d'import reprise." + +msgid "Stopped import or undo import due to error." +msgstr "Import ou annulation d'import arrêté pour cause d'erreur." + +#, php-format +msgid "Stopped import or undo import due to error: %s" +msgstr "Import ou annulation d'import arrêté pour cause d'erreur: %s" + +msgid "Cannot queue an import that has an error." +msgstr "" +"Impossible de mettre en file d'attente un import qui a une erreur." + +msgid "Cannot queue an import that has been stopped." +msgstr "" +"Impossible de mettre en file d'attente un import qui a été arrêté." + +msgid "Cannot queue an import that has been completed." +msgstr "" +"Impossible de mettre en file d'attente un import qui a été terminé." + +msgid "Cannot queue an import that has been undone." +msgstr "" +"Impossible de mettre en file d'attente un import qui a été annulé." + +msgid "Queued import." +msgstr "Import mis en file d'attente." + +msgid "Cannot queue an undo import that has an undo import error." +msgstr "" +"Impossible de mettre en file d'attente un import qui a une erreur " +"d'annulation." + +msgid "Cannot queue an undo import that has an error." +msgstr "" +"Impossible de mettre en file d'attente une annulation d'import qui " +"a une erreur" + +msgid "Cannot queue an undo import that has been stopped." +msgstr "" +"Impossible de mettre en file d'attente une annulation d'import qui " +"a été arrêtée." + +msgid "Cannot queue an undo import that has been undone." +msgstr "" +"Impossible de mettre en file d'attente une annulation d'import qui " +"a été annulée." + +msgid "Queued undo import." +msgstr "Annulations en file d'attente" + +msgid "Started undo import." +msgstr "Annulation d'import démarrée." + +#, php-format +msgid "Running item import loop. Memory usage: %s" +msgstr "Lancement de la boucle d'import. Utilisation de la mémoire: %s" + +#, php-format +msgid "Skipped item on row #%s" +msgstr "Contenus ignorés à la ligne #%s" + +#, php-format +msgid "Completed importing batch of %1$s items. Memory usage %2$s" +msgstr "" +"Import d'un lot de %1$s contenus terminé. Utilisation de la mémoire: %2$s" + +#, php-format +msgid "" +"Completed undoing the import of a batch of %1$s items. Memory usage: %2$s" +msgstr "" +"Annulation de l'import d'un lot de %1$s contenus terminée. " +"Utilisation de la mémoire! %2$s" + +#, php-format +msgid "Found similar items: %s" +msgstr "" + +#, php-format +msgid "" +"Identifier Element Texts:\n" +"%s" +msgstr "" +"Textes des éléments identifiants\n" +"%s" + +#, php-format +msgid "Invalid file URL \"%1$s\": %2$s" +msgstr "URL du fichier invalide \"%1$s\": %2$s" + +#, php-format +msgid "Could not import file \"%1$s\": %2$s" +msgstr "Impossible d'importer le fichier \"%1$s\": %2$s" + +#, php-format +msgid "Failed to remove file %s" +msgstr "Suppression du fichier %s echouée" + +#: models/CsvImport/File.php:99 +msgid "Please ensure that all column names are unique." +msgstr "Veuillez vous assurer que chaque nom de colonne est unique. " + +#: models/CsvImport/File.php:103 +msgid "" +"Please ensure that the CSV file is formatted correctly and contains the " +"expected number of columns for each row." +msgstr "" +"Veuillez vous assurer que le fichier CSV est correctement formé et qu'il " +"contient le nombre de colonnes attendues pour chaque contenu." + +#: CsvImportPlugin.php:282 views/admin/index/index.php:2 +#: views/admin/index/map-columns.php:2 views/admin/index/logs.php:1 +#: views/admin/index/browse.php:2 +msgid "CSV Import" +msgstr "CSV Import" + +#: controllers/IndexController.php:36 +msgid "Invalid form input. Please see errors below and try again." +msgstr "" +"Formulaire non valide. Prenez connaissance des erreurs et essayez à nouveau." + +#: controllers/IndexController.php:41 +msgid "Error uploading file. Please try again." +msgstr "Chargement du fichier impossible. Merci d'essayer à nouveau." + +#: controllers/IndexController.php:51 +msgid "Your file is incorrectly formatted." +msgstr "Votre fichier n'est pas formaté correctement." + +#: controllers/IndexController.php:100 +msgid "Import settings expired. Please try again." +msgstr "Les paramètres d'importation ont expiré. Merci de réessayer." + +#: controllers/IndexController.php:121 +msgid "Invalid form input. Please try again." +msgstr "Formulaire non valide. Merci d'essayer à nouveau." + +#: controllers/IndexController.php:127 +msgid "Please map at least one column to an element, file, or tag." +msgstr "" +"Veuillez créer l'équivalence pour une colonne au moins vers un élément, " +"fichier ou mot-clé." + +#: controllers/IndexController.php:141 controllers/IndexController.php:259 +msgid "Import started. Reload this page for status updates." +msgstr "Import démarré. Recharger cette page pour une mise à jour du statut." + +#: controllers/IndexController.php:143 controllers/IndexController.php:261 +msgid "Import could not be started. Please check error logs for more details." +msgstr "" +"L'import n'a pas démarré. Consultez les logs d'import pour plus de détails." + +#: controllers/IndexController.php:179 +#, php-format +msgid "" +"Invalid column names. Column names must either be one of the following %s, " +"or have the following format: {ElementSetName}:{ElementName}" +msgstr "" +"Nom de colonne non valide. Les noms de colonne doivent être parmi : %s, ou " +"avoir le format suivant : {ElementSetName}:{ElementName}" + +#: controllers/IndexController.php:195 +#, php-format +msgid "Element \"%s\" is not found in element set \"%s\"" +msgstr "L'élément \"%s\" n'appartient pas au jeu d'éléments \"%s\"" + +#: controllers/IndexController.php:287 +msgid "Undo import started. Reload this page for status updates." +msgstr "" +"Annulation d'import démarrée. Recharger cette page pour une mise à jour du " +"statut." + +#: controllers/IndexController.php:289 +msgid "" +"Undo import could not be started. Please check error logs for more details." +msgstr "" +"L'annulation d'import n'a pas démarré. Consultez les logs d'import pour plus " +"de détails." + +#: controllers/IndexController.php:318 +msgid "Cleared import from the history." +msgstr "Historique effacé" + +#: controllers/IndexController.php:320 +msgid "Cannot clear import history." +msgstr "Impossible d'effacer l'historique." + +#: forms/Mapping.php:56 +msgid "Import CSV File" +msgstr "Importer un fichier CSV" + +#: forms/Main.php:36 forms/Main.php:50 +msgid "Select Item Type" +msgstr "Choisir le type de contenu" + +#: forms/Main.php:39 +msgid "Use an export from Omeka CSV Report" +msgstr "Utiliser un export de CSV Report." + +#: forms/Main.php:40 +msgid "Selecting this will override the options below." +msgstr "Sélectionner ceci remplacera les options ci-dessous." + +#: forms/Main.php:44 +msgid "Automap Column Names to Elements" +msgstr "Aligner automatiquement les noms de colonnes avec les éléments." + +#: forms/Main.php:45 +msgid "" +"Automatically maps columns to elements based on their column names. The " +"column name must be in the form:
{ElementSetName}:{ElementName}" +msgstr "" +"Aligner automatiquement les noms de colonnes avec les éléments en fonction " +"des titres de colonnes. Les noms de colonne doivent être de la forme :
" +"{ElementSetName}:{ElementName}" + +#: forms/Main.php:54 forms/Main.php:57 +msgid "Select Collection" +msgstr "Choisir la collection" + +#: forms/Main.php:61 +msgid "Make All Items Public?" +msgstr "Rendre tous les contenus publics ?" + +#: forms/Main.php:64 +msgid "Feature All Items?" +msgstr "Mettre en avant tous les contenus ?" + +#: forms/Main.php:67 +msgid "Remove local files after successful import?" +msgstr "Supprimer les fichiers locaux après un import réussi?" + +#: forms/Main.php:81 +msgid "Next" +msgstr "Suivant" + +#: forms/Main.php:124 +msgid "Choose Identifier Elements" +msgstr "Sélectionnez les éléments identifiants" + +#: forms/Main.php:125 +msgid "" +"Those elements will be compared to detect if an item already exists in " +"database. If an item already exists, it will be skipped." +msgstr "" +"Ces éléments seront comparés pour détecter is un contenu existe déjà dans la " +"base de données. Si un contenu existe déjà, il sera sauté." + +#: forms/Main.php:142 +msgid "comma" +msgstr "virgule" + +#: forms/Main.php:145 +msgid "semi-colon" +msgstr "point-virgule" + +#: forms/Main.php:148 +msgid "empty" +msgstr "vide" + +#: forms/Main.php:162 +msgid "Choose Column Delimiter" +msgstr "Choisir le délimiteur de colonne" + +#: forms/Main.php:163 +#, php-format +msgid "" +"A single character that will be used to separate columns in the file (%s by " +"default). Note that spaces, tabs, and other whitespace are not accepted." +msgstr "" +"Un caractère unique sera utilisé comme séparateur de colonnes dans le " +"fichier (%s par défaut). Veuillez noter que les espaces, tabulations et " +"caractères vides ne sont pas acceptés." + +#: forms/Main.php:174 forms/Main.php:182 forms/Main.php:184 +msgid "Column delimiter cannot be whitespace and must be one character long." +msgstr "" +"Le délimiteur de colonnes ne peut être vide et doit contenir un caractère." + +#: forms/Main.php:199 +msgid "Choose File Delimiter" +msgstr "Choisir le délimiteur de fichier." + +#: forms/Main.php:200 +#, php-format +msgid "" +"A single character that will be used to separate file paths or URLs within a " +"cell (%s by default). If the delimiter is empty, then the whole text will be " +"used as the file path or URL. Note that spaces, tabs, and other whitespace " +"are not accepted." +msgstr "" +"Un caractère unique sera utilisé pour séparer les chemins vers les fichiers " +"ou leurs URLs à l'intérieur d'une cellule (%s par défaut). Si le délimiteur " +"est vide, la cellule entière sera utilisée comme chemin de fichier ou URL. " +"Veuillez noter que les espaces, tabulations et caractères vides ne sont pas " +"acceptés." + +#: forms/Main.php:212 forms/Main.php:221 forms/Main.php:223 +msgid "" +"File delimiter cannot be whitespace, and must be empty or one character long." +msgstr "" +"Le délimiteur de fichier ne peut être vide et doit contenir un caractère." + +#: forms/Main.php:238 +msgid "Choose Tag Delimiter" +msgstr "Choisir un délimiteur pour les mots clé" + +#: forms/Main.php:239 +#, php-format +msgid "" +"A single character that will be used to separate tags within a cell (%s by " +"default). Note that spaces, tabs, and other whitespace are not accepted." +msgstr "" +"Un caractère unique sera utilisé pour séparer les mots clé à l'intérieur " +"d'une cellule (%s par défaut). Veuillez noter que les espaces, tabulations " +"et caractères vides ne sont pas acceptés." + +#: forms/Main.php:250 forms/Main.php:258 forms/Main.php:260 +msgid "Tag delimiter cannot be whitespace and must be one character long." +msgstr "" +"Le délimiteur de mot clé ne peut être vide et doit contenir un caractère." + +#: forms/Main.php:275 +msgid "Choose Element Delimiter" +msgstr "Choisir un délimiteur pour les contenus." + +#: forms/Main.php:276 +#, php-format +msgid "" +"A single character that will be used to separate metadata elements within a " +"cell (%s by default). If the delimiter is empty, then the whole text will be " +"used as the element text. Note that spaces, tabs, and other whitespace are " +"not accepted." +msgstr "" +"Un caractère unique sera utilisé pour séparer les métadonnées à l'intérieur " +"d'une cellule (%s par défaut). Si le délimiteur est vide, la cellule entière " +"sera utilisée comme texte pour l'enregistrement. Veuillez noter que les " +"espaces, tabulations et caractères vides ne sont pas acceptés." + +#: forms/Main.php:288 forms/Main.php:297 forms/Main.php:299 +msgid "" +"Element delimiter cannot be whitespace, and must be empty or one character " +"long." +msgstr "" +"Le délimiteur de contenus ne peut être vide et doit contenir un caractère." + +#: forms/Main.php:333 +msgid "Upload CSV File" +msgstr "Charger un fichier CSV" + +#: forms/Main.php:337 +#, php-format +msgid "Maximum file size is %s." +msgstr "La taille maximale du fichier est de %s." + +#: forms/Main.php:351 +#, php-format +msgid "" +"The file you have uploaded exceeds the maximum post size allowed by the " +"server. Please upload a file smaller than %s." +msgstr "" +"Le fichier téléchargé dépasse la limite imposée par le serveur. Veuillez " +"charger un fichier de moins de %s." + +#: views/admin/index/check-omeka-csv.php:2 +msgid "CSV Import Errors" +msgstr "Erreur d'importation CSV" + +#: views/admin/index/check-omeka-csv.php:7 +msgid "" +"The following problems were found with your CSV file and Omeka installation." +msgstr "" +"Les problèmes suivants ont été détectés dans votre fichier CSV et votre " +"instance d'Omeka." + +#: views/admin/index/check-omeka-csv.php:10 +msgid "" +"Usually, these are the result of the elements in your Omeka.net site not " +"having \n" +" corresponding elements in this installation of Omeka. Either the Dublin " +"Core Extended plugin is not \n" +" installed, or you created custom item type elements in Omeka.net, but " +"have not yet created them here." +msgstr "" +"D'habitude, l'erreur est causée par des contenus sur votre site hébergé sur " +"Omeka.net qui n'ont pas d'équivalent sur cette instance d'Omeka. Soit " +"l'extension Dublin Core Extended n'est pas installée, soit vous avez défini " +"des types de contenus personnalisés sur votre site Omeka.net qui n'existent " +"pas encore sur cette instance." + +#: views/admin/index/check-omeka-csv.php:14 +msgid "Please correct the errors, then try your import again." +msgstr "Veuillez retenter l'import après avoir corrigé les erreurs." + +#: views/admin/index/index.php:7 +msgid "Step 1: Select File and Item Settings" +msgstr "Étape 1 : Choix du fichier et Paramètres des enregistrements" + +#: views/admin/index/map-columns.php:6 +msgid "Step 2: Map Columns To Elements, Tags, or Files" +msgstr "Étape 2 : Relier les colonnes aux éléments, mots clé ou fichiers" + +#: views/admin/index/logs.php:6 +#, php-format +msgid "Logs for import #%s" +msgstr "Logs pour l'import #%s" + +#: views/admin/index/logs.php:14 +msgid "Time" +msgstr "Temps" + +#: views/admin/index/logs.php:15 +msgid "Priority" +msgstr "Priorité" + +#: views/admin/index/logs.php:16 +msgid "Message" +msgstr "Message" + +#: views/admin/index/logs.php:82 +msgid "You have no logs yet." +msgstr "Vous n'avez encore aucun log." + +#: views/admin/index/map-columns-form.php:9 +msgid "Column" +msgstr "Colonne" + +#: views/admin/index/map-columns-form.php:10 +msgid "Example from CSV File" +msgstr "Exemple depuis un fichier CSV" + +#: views/admin/index/map-columns-form.php:11 +msgid "Map To Element" +msgstr "Relier à l'élément" + +#: views/admin/index/map-columns-form.php:12 +msgid "Use HTML?" +msgstr "Utiliser HTML ?" + +#: views/admin/index/map-columns-form.php:13 +msgid "Tags?" +msgstr "Mots clé ?" + +#: views/admin/index/map-columns-form.php:14 +msgid "Files?" +msgstr "Fichiers ?" + +#: views/admin/index/browse.php:14 +msgid "Import Date" +msgstr "Date de l'import" + +#: views/admin/index/browse.php:15 +msgid "CSV File" +msgstr "Fichier CSV" + +#: views/admin/index/browse.php:16 +msgid "Imported Items" +msgstr "Contenus importés" + +#: views/admin/index/browse.php:17 +msgid "Skipped Items" +msgstr "Contenus ignorés" + +#: views/admin/index/browse.php:18 +msgid "Skipped Rows" +msgstr "Lignes ignorées" + +#: views/admin/index/browse.php:20 +msgid "Action" +msgstr "Action" + +#: views/admin/index/browse.php:53 +msgid "Undo Import" +msgstr "Annuler l'import" + +#: views/admin/index/browse.php:55 +msgid "Logs" +msgstr "Logs" + +#: views/admin/index/browse.php:67 +msgid "Clear History" +msgstr "Effacer l'historique" + +#: views/admin/index/browse.php:77 +msgid "You have no imports yet." +msgstr "Vous n'avez encore aucun import." diff --git a/languages/template.base.pot b/languages/template.base.pot index 4da6436..f89f1d5 100644 --- a/languages/template.base.pot +++ b/languages/template.base.pot @@ -54,3 +54,104 @@ msgstr "" msgid "Paused" msgstr "" + +msgid "Started import." +msgstr "" + +msgid "Cannot complete an import that is already completed." +msgstr "" + +#, php-format +msgid "Completed importing %1$s items (skipped %2$s items, %3$s rows)." +msgstr "" + +msgid "Cannot complete an undo import that is already undone." +msgstr "" + +msgid "Completed undoing the import." +msgstr "" + +msgid "Cannot resume an import or undo import that has not been queued." +msgstr "" + +msgid "Resumed import." +msgstr "" + +msgid "Resumed undo import." +msgstr "" + +msgid "Stopped import or undo import due to error." +msgstr "" + +#, php-format +msgid "Stopped import or undo import due to error: %s" +msgstr "" + +msgid "Cannot queue an import that has an error." +msgstr "" + +msgid "Cannot queue an import that has been stopped." +msgstr "" + +msgid "Cannot queue an import that has been completed." +msgstr "" + +msgid "Cannot queue an import that has been undone." +msgstr "" + +msgid "Queued import." +msgstr "" + +msgid "Cannot queue an undo import that has an undo import error." +msgstr "" + +msgid "Cannot queue an undo import that has an error." +msgstr "" + +msgid "Cannot queue an undo import that has been stopped." +msgstr "" + +msgid "Cannot queue an undo import that has been undone." +msgstr "" + +msgid "Queued undo import." +msgstr "" + +msgid "Started undo import." +msgstr "" + +#, php-format +msgid "Running item import loop. Memory usage: %s" +msgstr "" + +#, php-format +msgid "Skipped item on row #%s" +msgstr "" + +#, php-format +msgid "Completed importing batch of %1$s items. Memory usage %2$s" +msgstr "" + +#, php-format +msgid "Completed undoing the import of a batch of %1$s items. Memory usage: %2$s" +msgstr "" + +#, php-format +msgid "Found similar items: %s" +msgstr "" + +#, php-format +msgid "Identifier Element Texts:\n%s" +msgstr "" + +#, php-format +msgid "Invalid file URL \"%1$s\": %2$s" +msgstr "" + +#, php-format +msgid "Could not import file \"%1$s\": %2$s" +msgstr "" + +#, php-format +msgid "Failed to remove file %s" +msgstr "" diff --git a/languages/template.pot b/languages/template.pot index e707b9a..b310ee3 100644 --- a/languages/template.pot +++ b/languages/template.pot @@ -56,8 +56,123 @@ msgstr "" msgid "Paused" msgstr "" -#: CsvImportPlugin.php:231 views/admin/index/browse.php:2 -#: views/admin/index/index.php:2 views/admin/index/map-columns.php:2 +msgid "Started import." +msgstr "" + +msgid "Cannot complete an import that is already completed." +msgstr "" + +#, php-format +msgid "Completed importing %1$s items (skipped %2$s items, %3$s rows)." +msgstr "" + +msgid "Cannot complete an undo import that is already undone." +msgstr "" + +msgid "Completed undoing the import." +msgstr "" + +msgid "Cannot resume an import or undo import that has not been queued." +msgstr "" + +msgid "Resumed import." +msgstr "" + +msgid "Resumed undo import." +msgstr "" + +msgid "Stopped import or undo import due to error." +msgstr "" + +#, php-format +msgid "Stopped import or undo import due to error: %s" +msgstr "" + +msgid "Cannot queue an import that has an error." +msgstr "" + +msgid "Cannot queue an import that has been stopped." +msgstr "" + +msgid "Cannot queue an import that has been completed." +msgstr "" + +msgid "Cannot queue an import that has been undone." +msgstr "" + +msgid "Queued import." +msgstr "" + +msgid "Cannot queue an undo import that has an undo import error." +msgstr "" + +msgid "Cannot queue an undo import that has an error." +msgstr "" + +msgid "Cannot queue an undo import that has been stopped." +msgstr "" + +msgid "Cannot queue an undo import that has been undone." +msgstr "" + +msgid "Queued undo import." +msgstr "" + +msgid "Started undo import." +msgstr "" + +#, php-format +msgid "Running item import loop. Memory usage: %s" +msgstr "" + +#, php-format +msgid "Skipped item on row #%s" +msgstr "" + +#, php-format +msgid "Completed importing batch of %1$s items. Memory usage %2$s" +msgstr "" + +#, php-format +msgid "" +"Completed undoing the import of a batch of %1$s items. Memory usage: %2$s" +msgstr "" + +#, php-format +msgid "Found similar items: %s" +msgstr "" + +#, php-format +msgid "" +"Identifier Element Texts:\n" +"%s" +msgstr "" + +#, php-format +msgid "Invalid file URL \"%1$s\": %2$s" +msgstr "" + +#, php-format +msgid "Could not import file \"%1$s\": %2$s" +msgstr "" + +#, php-format +msgid "Failed to remove file %s" +msgstr "" + +#: models/CsvImport/File.php:99 +msgid "Please ensure that all column names are unique." +msgstr "" + +#: models/CsvImport/File.php:103 +msgid "" +"Please ensure that the CSV file is formatted correctly and contains the " +"expected number of columns for each row." +msgstr "" + +#: CsvImportPlugin.php:282 views/admin/index/index.php:2 +#: views/admin/index/map-columns.php:2 views/admin/index/logs.php:1 +#: views/admin/index/browse.php:2 msgid "CSV Import" msgstr "" @@ -73,55 +188,59 @@ msgstr "" msgid "Your file is incorrectly formatted." msgstr "" -#: controllers/IndexController.php:95 +#: controllers/IndexController.php:100 msgid "Import settings expired. Please try again." msgstr "" -#: controllers/IndexController.php:116 +#: controllers/IndexController.php:121 msgid "Invalid form input. Please try again." msgstr "" -#: controllers/IndexController.php:122 +#: controllers/IndexController.php:127 msgid "Please map at least one column to an element, file, or tag." msgstr "" -#: controllers/IndexController.php:136 controllers/IndexController.php:254 +#: controllers/IndexController.php:141 controllers/IndexController.php:259 msgid "Import started. Reload this page for status updates." msgstr "" -#: controllers/IndexController.php:138 controllers/IndexController.php:256 +#: controllers/IndexController.php:143 controllers/IndexController.php:261 msgid "Import could not be started. Please check error logs for more details." msgstr "" -#: controllers/IndexController.php:174 +#: controllers/IndexController.php:179 #, php-format msgid "" "Invalid column names. Column names must either be one of the following %s, " "or have the following format: {ElementSetName}:{ElementName}" msgstr "" -#: controllers/IndexController.php:190 +#: controllers/IndexController.php:195 #, php-format msgid "Element \"%s\" is not found in element set \"%s\"" msgstr "" -#: controllers/IndexController.php:282 +#: controllers/IndexController.php:287 msgid "Undo import started. Reload this page for status updates." msgstr "" -#: controllers/IndexController.php:284 +#: controllers/IndexController.php:289 msgid "" "Undo import could not be started. Please check error logs for more details." msgstr "" -#: controllers/IndexController.php:303 +#: controllers/IndexController.php:318 msgid "Cleared import from the history." msgstr "" -#: controllers/IndexController.php:305 +#: controllers/IndexController.php:320 msgid "Cannot clear import history." msgstr "" +#: forms/Mapping.php:56 +msgid "Import CSV File" +msgstr "" + #: forms/Main.php:36 forms/Main.php:50 msgid "Select Item Type" msgstr "" @@ -156,42 +275,56 @@ msgstr "" msgid "Feature All Items?" msgstr "" -#: forms/Main.php:77 +#: forms/Main.php:67 +msgid "Remove local files after successful import?" +msgstr "" + +#: forms/Main.php:81 msgid "Next" msgstr "" -#: forms/Main.php:100 +#: forms/Main.php:124 +msgid "Choose Identifier Elements" +msgstr "" + +#: forms/Main.php:125 +msgid "" +"Those elements will be compared to detect if an item already exists in " +"database. If an item already exists, it will be skipped." +msgstr "" + +#: forms/Main.php:142 msgid "comma" msgstr "" -#: forms/Main.php:103 +#: forms/Main.php:145 msgid "semi-colon" msgstr "" -#: forms/Main.php:106 +#: forms/Main.php:148 msgid "empty" msgstr "" -#: forms/Main.php:120 +#: forms/Main.php:162 msgid "Choose Column Delimiter" msgstr "" -#: forms/Main.php:121 +#: forms/Main.php:163 #, php-format msgid "" "A single character that will be used to separate columns in the file (%s by " "default). Note that spaces, tabs, and other whitespace are not accepted." msgstr "" -#: forms/Main.php:132 forms/Main.php:140 forms/Main.php:142 +#: forms/Main.php:174 forms/Main.php:182 forms/Main.php:184 msgid "Column delimiter cannot be whitespace and must be one character long." msgstr "" -#: forms/Main.php:157 +#: forms/Main.php:199 msgid "Choose File Delimiter" msgstr "" -#: forms/Main.php:158 +#: forms/Main.php:200 #, php-format msgid "" "A single character that will be used to separate file paths or URLs within a " @@ -200,31 +333,31 @@ msgid "" "are not accepted." msgstr "" -#: forms/Main.php:170 forms/Main.php:179 forms/Main.php:181 +#: forms/Main.php:212 forms/Main.php:221 forms/Main.php:223 msgid "" "File delimiter cannot be whitespace, and must be empty or one character long." msgstr "" -#: forms/Main.php:196 +#: forms/Main.php:238 msgid "Choose Tag Delimiter" msgstr "" -#: forms/Main.php:197 +#: forms/Main.php:239 #, php-format msgid "" "A single character that will be used to separate tags within a cell (%s by " "default). Note that spaces, tabs, and other whitespace are not accepted." msgstr "" -#: forms/Main.php:208 forms/Main.php:216 forms/Main.php:218 +#: forms/Main.php:250 forms/Main.php:258 forms/Main.php:260 msgid "Tag delimiter cannot be whitespace and must be one character long." msgstr "" -#: forms/Main.php:233 +#: forms/Main.php:275 msgid "Choose Element Delimiter" msgstr "" -#: forms/Main.php:234 +#: forms/Main.php:276 #, php-format msgid "" "A single character that will be used to separate metadata elements within a " @@ -233,78 +366,28 @@ msgid "" "not accepted." msgstr "" -#: forms/Main.php:246 forms/Main.php:255 forms/Main.php:257 +#: forms/Main.php:288 forms/Main.php:297 forms/Main.php:299 msgid "" "Element delimiter cannot be whitespace, and must be empty or one character " "long." msgstr "" -#: forms/Main.php:291 +#: forms/Main.php:333 msgid "Upload CSV File" msgstr "" -#: forms/Main.php:295 +#: forms/Main.php:337 #, php-format msgid "Maximum file size is %s." msgstr "" -#: forms/Main.php:309 +#: forms/Main.php:351 #, php-format msgid "" "The file you have uploaded exceeds the maximum post size allowed by the " "server. Please upload a file smaller than %s." msgstr "" -#: forms/Mapping.php:56 -msgid "Import CSV File" -msgstr "" - -#: models/CsvImport/File.php:99 -msgid "Please ensure that all column names are unique." -msgstr "" - -#: models/CsvImport/File.php:103 -msgid "" -"Please ensure that the CSV file is formatted correctly and contains the " -"expected number of columns for each row." -msgstr "" - -#: views/admin/index/browse.php:14 -msgid "Import Date" -msgstr "" - -#: views/admin/index/browse.php:15 -msgid "CSV File" -msgstr "" - -#: views/admin/index/browse.php:16 -msgid "Imported Items" -msgstr "" - -#: views/admin/index/browse.php:17 -msgid "Skipped Items" -msgstr "" - -#: views/admin/index/browse.php:18 -msgid "Skipped Rows" -msgstr "" - -#: views/admin/index/browse.php:20 -msgid "Action" -msgstr "" - -#: views/admin/index/browse.php:49 -msgid "Undo Import" -msgstr "" - -#: views/admin/index/browse.php:61 -msgid "Clear History" -msgstr "" - -#: views/admin/index/browse.php:71 -msgid "You have no imports yet." -msgstr "" - #: views/admin/index/check-omeka-csv.php:2 msgid "CSV Import Errors" msgstr "" @@ -332,6 +415,31 @@ msgstr "" msgid "Step 1: Select File and Item Settings" msgstr "" +#: views/admin/index/map-columns.php:6 +msgid "Step 2: Map Columns To Elements, Tags, or Files" +msgstr "" + +#: views/admin/index/logs.php:6 +#, php-format +msgid "Logs for import #%s" +msgstr "" + +#: views/admin/index/logs.php:14 +msgid "Time" +msgstr "" + +#: views/admin/index/logs.php:15 +msgid "Priority" +msgstr "" + +#: views/admin/index/logs.php:16 +msgid "Message" +msgstr "" + +#: views/admin/index/logs.php:82 +msgid "You have no logs yet." +msgstr "" + #: views/admin/index/map-columns-form.php:9 msgid "Column" msgstr "" @@ -356,6 +464,42 @@ msgstr "" msgid "Files?" msgstr "" -#: views/admin/index/map-columns.php:6 -msgid "Step 2: Map Columns To Elements, Tags, or Files" +#: views/admin/index/browse.php:14 +msgid "Import Date" +msgstr "" + +#: views/admin/index/browse.php:15 +msgid "CSV File" +msgstr "" + +#: views/admin/index/browse.php:16 +msgid "Imported Items" +msgstr "" + +#: views/admin/index/browse.php:17 +msgid "Skipped Items" +msgstr "" + +#: views/admin/index/browse.php:18 +msgid "Skipped Rows" +msgstr "" + +#: views/admin/index/browse.php:20 +msgid "Action" +msgstr "" + +#: views/admin/index/browse.php:53 +msgid "Undo Import" +msgstr "" + +#: views/admin/index/browse.php:55 +msgid "Logs" +msgstr "" + +#: views/admin/index/browse.php:67 +msgid "Clear History" +msgstr "" + +#: views/admin/index/browse.php:77 +msgid "You have no imports yet." msgstr "" diff --git a/models/CsvImport/ColumnMap/Element.php b/models/CsvImport/ColumnMap/Element.php index 6a2a468..2f4a07a 100644 --- a/models/CsvImport/ColumnMap/Element.php +++ b/models/CsvImport/ColumnMap/Element.php @@ -52,11 +52,20 @@ public function map($row, $result) $texts = explode($this->_elementDelimiter, $text); } foreach($texts as $text) { - $result[] = array( - 'element_id' => $this->_elementId, - 'html' => $this->_isHtml ? 1 : 0, - 'text' => $text, - ); + if (is_callable('element_types_format')) { + $formattedText = element_types_format($this->_elementId, $text); + if (!$formattedText) { + _log("Cannot format '$text' for element {$this->_elementId}", Zend_Log::WARN); + } + $text = $formattedText; + } + if ($text) { + $result[] = array( + 'element_id' => $this->_elementId, + 'html' => $this->_isHtml ? 1 : 0, + 'text' => $text, + ); + } } return $result; } @@ -116,4 +125,4 @@ static public function getDefaultElementDelimiter() } return $delimiter; } -} \ No newline at end of file +} diff --git a/models/CsvImport/Import.php b/models/CsvImport/Import.php index 2b6797f..a4aeaf2 100644 --- a/models/CsvImport/Import.php +++ b/models/CsvImport/Import.php @@ -36,6 +36,8 @@ class CsvImport_Import extends Omeka_Record_AbstractRecord public $delimiter; // the column delimiter public $is_public; public $is_featured; + public $remove_local_files; + public $serialized_identifier_element_ids; public $skipped_row_count = 0; public $skipped_item_count = 0; public $status; @@ -44,6 +46,7 @@ class CsvImport_Import extends Omeka_Record_AbstractRecord private $_csvFile; private $_isOmekaExport; private $_importedCount = 0; + private $_identifier_element_ids; /** * Batch importing is not enabled by default. @@ -85,6 +88,22 @@ public function setItemsAreFeatured($flag) $this->is_featured = $booleanFilter->filter($flag); } + public function setIdentifierElementIds($element_ids) + { + $this->_identifier_element_ids = $element_ids; + } + + /** + * Sets whether the local files should be removed or not + * + * @param mixed $flag A boolean representation + */ + public function setRemoveLocalFiles($flag) + { + $booleanFilter = new Omeka_Filter_Boolean; + $this->remove_local_files = $booleanFilter->filter($flag); + } + /** * Sets the collection id of the collection to which the imported items belong * @@ -216,6 +235,7 @@ public function setBatchSize($size) protected function beforeSave($args) { $this->serialized_column_maps = serialize($this->getColumnMaps()); + $this->serialized_identifier_element_ids = serialize($this->getIdentifierElementIds()); } /** @@ -351,8 +371,8 @@ public function complete() } $this->status = self::COMPLETED; $this->save(); - $this->_log("Completed importing $this->_importedCount items (skipped " - . "$this->skipped_row_count rows)."); + $this->_log('Completed importing %1$s items (skipped %2$s items, %3$s rows).', + array($this->_importedCount, $this->skipped_item_count, $this->skipped_row_count)); return true; } @@ -422,14 +442,16 @@ public function stop() // The import or undo import loop was prematurely stopped $logMsg = "Stopped import or undo import due to error"; + $logParams = array(); if ($error = error_get_last()) { - $logMsg .= ": " . $error['message']; + $logMsg .= ": %s"; + $logParams[] = $error['message']; } else { $logMsg .= '.'; } $this->status = self::STOPPED; $this->save(); - $this->_log($logMsg, Zend_Log::ERR); + $this->_log($logMsg, $logParams, Zend_Log::ERR); return true; // stopped with an error } @@ -549,6 +571,15 @@ public function getColumnMaps() return $this->_columnMaps; } + public function getIdentifierElementIds() + { + if ($this->_identifier_element_ids === null) { + $this->_identifier_element_ids + = unserialize($this->serialized_identifier_element_ids); + } + return $this->_identifier_element_ids; + } + /** * Returns the number of items currently imported. If a user undoes an import, * this number decreases to the number of items left to remove. @@ -580,7 +611,8 @@ protected function _importLoop($startAt = null) $rows->seek($startAt); } $rows->skipInvalidRows(true); - $this->_log("Running item import loop. Memory usage: %memory%"); + $this->_log("Running item import loop. Memory usage: %s", + array(memory_get_usage())); while ($rows->valid()) { $row = $rows->current(); $index = $rows->key(); @@ -589,12 +621,11 @@ protected function _importLoop($startAt = null) release_object($item); } else { $this->skipped_item_count++; - $this->_log("Skipped item on row #{$index}.", Zend_Log::WARN); + $this->_log("Skipped item on row #%s", array($index), Zend_Log::WARN); } $this->file_position = $this->getCsvFile()->getIterator()->tell(); if ($this->_batchSize && ($index % $this->_batchSize == 0)) { - $this->_log("Completed importing batch of $this->_batchSize " - . "items. Memory usage: %memory%"); + $this->_log('Completed importing batch of %1$s items. Memory usage %2$s', array($this->_batchSize, memory_get_usage())); return $this->queue(); } $rows->next(); @@ -608,7 +639,7 @@ protected function _importLoop($startAt = null) } catch (Exception $e) { $this->status = self::IMPORT_ERROR; $this->save(); - $this->_log($e, Zend_Log::ERR); + $this->_log($e, array(), Zend_Log::ERR); throw $e; } } @@ -648,8 +679,7 @@ protected function _undoImportLoop() if ($batchSize > 0 && $deletedItemCount == $batchSize) { $inClause = 'IN (' . join(', ', $deletedItemIds) . ')'; $db->delete($db->CsvImport_ImportedItem, "`item_id` $inClause"); - $this->_log("Completed undoing the import of a batch of $batchSize " - . "items. Memory usage: %memory%"); + $this->_log('Completed undoing the import of a batch of %1$s items. Memory usage: %2$s', array($batchSize, memory_get_usage())); return $this->queueUndo(); } } @@ -665,11 +695,29 @@ protected function _undoImportLoop() } catch (Exception $e) { $this->status = self::UNDO_IMPORT_ERROR; $this->save(); - $this->_log($e, Zend_Log::ERR); + $this->_log($e, array(), Zend_Log::ERR); throw $e; } } + protected function _findItemsByElementTexts($elementTexts) + { + if (!$elementTexts) { + return array(); + } + + $db = $this->getDb(); + $select = $db->select()->from(array('i' => $db->Item), array('item_id' => 'id')); + foreach ($elementTexts as $elementText) { + $element_id = $elementText['element_id']; + $select->joinLeft(array("et_$element_id" => $db->ElementText), + "i.id = et_{$element_id}.record_id AND et_{$element_id}.record_type = 'Item' AND et_{$element_id}.element_id = {$element_id}"); + $select->where("et_{$element_id}.text = ?", $elementText['text']); + } + $items = $db->fetchCol($select); + return $items; + } + /** * Adds a new item based on a row string in the CSV file and returns it. * @@ -703,37 +751,68 @@ protected function _addItemFromRow($row) } $elementTexts = $result[CsvImport_ColumnMap::TYPE_ELEMENT]; + + $identifier_element_ids = $this->getIdentifierElementIds(); + $identifierElementTexts = array_filter($elementTexts, function ($e) use ($identifier_element_ids) { + return in_array($e['element_id'], $identifier_element_ids); + }); + $existing_items = $this->_findItemsByElementTexts($identifierElementTexts); + if ($existing_items) { + $this->_log("Found similar items: %s", array(implode(", ", $existing_items)), Zend_Log::WARN); + $this->_log("Identifier Element Texts:\n%s", array(var_export($identifierElementTexts, true)), Zend_Log::WARN); + return false; + } + try { $item = insert_item($itemMetadata, $elementTexts); } catch (Omeka_Validator_Exception $e) { - $this->_log($e, Zend_Log::ERR); + $this->_log($e, array(), Zend_Log::ERR); return false; } catch (Omeka_Record_Builder_Exception $e) { - $this->_log($e, Zend_Log::ERR); + $this->_log($e, array(), Zend_Log::ERR); return false; } $fileUrls = $result[CsvImport_ColumnMap::TYPE_FILE]; foreach ($fileUrls as $url) { - try { - $file = insert_files_for_item($item, 'Url', $url, - array('ignore_invalid_files' => false)); - } catch (Omeka_File_Ingest_InvalidException $e) { - $msg = "Invalid file URL '$url': " - . $e->getMessage(); - $this->_log($msg, Zend_Log::ERR); - $item->delete(); - release_object($item); - return false; - } catch (Omeka_File_Ingest_Exception $e) { - $msg = "Could not import file '$url': " - . $e->getMessage(); - $this->_log($msg, Zend_Log::ERR); + $successfulTransferStrategy = null; + $logMsg = null; + $logParams = array(); + foreach (array('Url', 'Filesystem') as $transferStrategy) { + try { + $file = insert_files_for_item($item, $transferStrategy, $url, + array('ignore_invalid_files' => false)); + } catch (Omeka_File_Ingest_InvalidException $e) { + $logMsg = 'Invalid file URL "%1$s": %2$s'; + $logParams = array($url, $e->getMessage()); + continue; + } catch (Omeka_File_Ingest_Exception $e) { + $logMsg = 'Could not import file "%1$s": %2$s'; + $logParams = array($url, $e->getMessage()); + continue; + } + $successfulTransferStrategy = $transferStrategy; + break; + } + if (!isset($file)) { + $this->_log($logMsg, $logParams, Zend_Log::ERR); $item->delete(); release_object($item); return false; } release_object($file); + + if ($successfulTransferStrategy === 'Filesystem') { + $localFiles []= $url; + } + } + + if ($this->remove_local_files) { + foreach ($localFiles as $localFile) { + if(!unlink($localFile)) { + $this->_log("Failed to remove file %s", array($localFile), Zend_Log::ERR); + } + } } // Makes it easy to unimport the item later. @@ -760,15 +839,23 @@ protected function _recordImportedItemId($itemId) /** * Log an import message * Every message will log the import ID. - * Messages that have %memory% will include memory usage information. * * @param string $msg The message to log + * @param array $params Params to pass the translation function __() * @param int $priority The priority of the message */ - protected function _log($msg, $priority = Zend_Log::DEBUG) + protected function _log($msg, $params = array(), $priority = Zend_Log::DEBUG) { $prefix = "[CsvImport][#{$this->id}]"; - $msg = str_replace('%memory%', memory_get_usage(), $msg); _log("$prefix $msg", $priority); + + $csvImportLog = new CsvImport_Log(); + $csvImportLog->setArray(array( + 'import_id' => $this->id, + 'priority' => $priority, + 'message' => $msg, + 'params' => serialize($params), + )); + $csvImportLog->save(); } } diff --git a/models/CsvImport/Log.php b/models/CsvImport/Log.php new file mode 100644 index 0000000..34972f7 --- /dev/null +++ b/models/CsvImport/Log.php @@ -0,0 +1,11 @@ +getSelect() + ->where('import_id = ?', $importId) + ->order(array('created ASC')); + return $this->fetchObjects($select); + } +} diff --git a/plugin.ini b/plugin.ini index 031fd49..f0efa8a 100644 --- a/plugin.ini +++ b/plugin.ini @@ -3,7 +3,7 @@ name="CSV Import" author="Roy Rosenzweig Center for History and New Media" description="Imports items, tags, and files from CSV files." link="http://omeka.org/codex/Plugins/CSV_Import_2.0" -version="2.0.3" +version="2.0.7" support_link="http://omeka.org/forums/forum/plugins" license="GPL" omeka_minimum_version="2.0" diff --git a/views/admin/index/browse.php b/views/admin/index/browse.php index b0698d3..cf026dc 100644 --- a/views/admin/index/browse.php +++ b/views/admin/index/browse.php @@ -11,7 +11,7 @@ - - - added, Zend_Date::DATETIME_SHORT)); ?> + + + added, Zend_Date::DATETIME_SHORT)); + $logs = get_db()->getTable('CsvImport_Log')->findByImportId($csvImport->id); + if (empty($logs)): + echo $importDate; + else: + $logsUrl = $this->url(array( + 'action' => 'logs', + 'id' => $csvImport->id + ), 'default'); + ?> + + + original_filename); ?> getImportedItemCount(); ?> @@ -43,10 +56,10 @@ url(array('action' => 'undo-import', 'id' => $csvImport->id), - 'default'); + 'default'); ?> - + isUndone() || $csvImport->isUndoImportError() || diff --git a/views/admin/index/logs.php b/views/admin/index/logs.php new file mode 100644 index 0000000..e807206 --- /dev/null +++ b/views/admin/index/logs.php @@ -0,0 +1,88 @@ + __('CSV Import'))); ?> + + + +
+

id); ?>

+ + + + + + + + + + + + + + + + + + + + + +
+ created, Zend_Date::DATE_SHORT)); ?> + created, Zend_Date::TIME_MEDIUM)); ?> + + priority) { + case Zend_Log::EMERG: + $priority = 'EMERGENCY'; + break; + + case Zend_Log::ALERT: + $priority = 'ALERT'; + break; + + case Zend_Log::CRIT: + $priority = 'CRITICAL'; + break; + + case Zend_Log::ERR: + $priority = 'ERROR'; + break; + + case Zend_Log::WARN: + $priority = 'WARNING'; + break; + + case Zend_Log::NOTICE: + $priority = 'NOTICE'; + break; + + case Zend_Log::INFO: + $priority = 'INFO'; + break; + + case Zend_Log::DEBUG: + $priority = 'DEBUG'; + break; + + default: + $priority = ''; + } + echo $priority; + ?> + + message); + $params = unserialize($log->params); + if (is_array($params)) { + $param_arr = array_merge($param_arr, $params); + } + echo html_escape(call_user_func_array('__', $param_arr)); + ?> +
+ +

+ +
+ + diff --git a/views/admin/javascripts/csv-import.js b/views/admin/javascripts/csv-import.js index 7965af1..9766f06 100644 --- a/views/admin/javascripts/csv-import.js +++ b/views/admin/javascripts/csv-import.js @@ -40,7 +40,7 @@ Omeka.CsvImport = {}; Omeka.CsvImport.updateImportOptions = function () { // we need to test whether the checkbox is checked // because fields will all be displayed if the form fails validation - var fields = $('div.field').has('#automap_columns_names_to_elements, #item_type_id, #collection_id, #items_are_public, #items_are_featured, #column_delimiter, #element_delimiter, #tag_delimiter, #file_delimiter'); + var fields = $('div.field').has('#automap_columns_names_to_elements, #item_type_id, #collection_id, #items_are_public, #items_are_featured, #identifier_elements, #column_delimiter, #element_delimiter, #tag_delimiter, #file_delimiter'); if ($('#omeka_csv_export').is(':checked')) { fields.slideUp(); } else {