Comments

fago’s picture

Title: Entity Export UI » Entity Import/Export UI
Status: Needs review » Needs work

Looks good. However, what's the purpose of having export without an "import" page? I guess we should only add all at once, as the UI is already used by modules. Probably we should do it like views in d7, provide another action link for creating new entities by import.

klausi’s picture

Status: Needs work » Needs review
StatusFileSize
new6.95 KB

Right, here is a new patch with an import action link included.

Open issue: ID or machine name clashes when an entity with same ID/name already exists in the DB.

klausi’s picture

StatusFileSize
new7.95 KB

Improved patch that validates imported entities before saving. Fixed a WSOD in entity_id() on the way when it is called with an invalid non-object entity.

klausi’s picture

StatusFileSize
new7.96 KB

Even better: in entity_id() we just check for the identifier() method in the actual $entity object, that works for invalid $entity variables and for subclasses of the specified entity class as well.

Status: Needs review » Needs work

The last submitted patch, 975758-entity-import-export.patch, failed testing.

klausi’s picture

Status: Needs work » Needs review

#4: 975758-entity-import-export.patch queued for re-testing.

klausi’s picture

StatusFileSize
new8.06 KB

Minor change, added a description for the export text area.

fago’s picture

Status: Needs review » Needs work
+            '#rows' => count(explode("\n", $export)),

Let's set this to a fixed, but high value.

+      @eval('$import = ' . $form_state['values']['import'] . ';');

This won't work generically, e.g. Rules implements an export using JSON. I guess the entity API misses an entity_import() function + a respective entity controller method.

fago’s picture

hm, also eval() is problematic as we need to implement a new "eval php" permission for that. Perhaps we should just stick to the json export by default? The entity API has already an API function to print beautified JSON.

An option like views has in 7.x would be nice too. "checkbox: Allow overwriting existing configurations" or such.

fago’s picture

Results of discussion: We really need something like entity_import($entity_type, $export_code) - which takes the export and returns an entity as expected by the default hook. For security, we go with JSON by default.

fago’s picture

klausi’s picture

Status: Needs work » Needs review
StatusFileSize
new12.5 KB

I agree, we avoid implementing complicated PHP execution permissions and we avoid a huge security risk by using JSON. New patch that addresses all that concerns.

klausi’s picture

Oh, I forgot: this patch contains a tiny API change for the create() functions so that $values always has to be an array (again saving as from nasty WSODs)

klausi’s picture

StatusFileSize
new13.47 KB

And i forgot to change the Features export rendering, here is an updated patch that uses PHP heredoc syntax to store the JSON export. entity_import() is used to create entity objects from that strings.

klausi’s picture

StatusFileSize
new13.37 KB

Small improvement: avoid using a foreach loop in the Features rendered export.

fago’s picture

Status: Needs review » Needs work
+          '#description' => t('If checked, any existing %entity with the same ID will be replaced by the import.', array('%entity' => $this->entityInfo['label'])),

Let's use "identifier" instead of ID.

+            '#description' => t('Copy these data and paste them into the import page, to import.'),

These or this data is the question.. ;)

+            form_set_error('import', t('Import of %entity %label failed, a %entity with the same machine name already exists. Check the overwrite option to replace it.', $vars));

I think it should be @entity, as it makes not much sense to me to mark entity as a placeholder. For the label though it does. It is already that way in the existing code though, so this should be probably another issue.

The logic in operationFormValidate()looks a bit complex to me, perhaps it can be simplified? Not sure.

reset(entity_load($this->entityType, array($id)));
This will produce warnings or notices on some platforms as reset() takes the argument by reference.

-    return "entity_create('$this->entityType', " . entity_var_export($vars, $prefix) . ")";
+    return entity_var_json_export($vars, $prefix);
+  }

Previously the return was valid PHP but that changed now. We need to document what entity_export() is supposed to return.

+    // Menu item for importing an entity.
+    $items[$this->path . '/import'] = array(
+      'title callback' => 'entity_ui_import_title',
...

We may only add this menu item if the entity is exportable.

klausi’s picture

Status: Needs work » Needs review
StatusFileSize
new15.15 KB

Good points, I addressed nearly all of them. Only '%' vs. '@' is still open, but should probably be a separate issue.

Status: Needs review » Needs work

The last submitted patch, 975758-entity-import-export.patch, failed testing.

klausi’s picture

Status: Needs work » Needs review
StatusFileSize
new16.17 KB

Right, the test case needs a minor fix to deal with JSON.

fago’s picture

Status: Needs review » Needs work

Looks good, I gave it a test with profile2.

When export the default profile + importing it with overwrite enabled I got:

Error message
Notice: Undefined property: ProfileType::$id in EntityDefaultUIController->applyOperation() (line 398 of /var/www/drupal-7/sites/all/modules/entity/entity/entity.ui.inc).

Then I got the message:
>Imported Profile type Profile.
-> but profile type should start lower case there - that applies to any sentence where it is not in the beginning. I wonder though how that is supposed to work for translations?

>entity_ui_import_title()
This seems to somehow duplicate entity_ui_get_page_title() ?

>applyOperation() + others
It's getting increasingly confusing which operation is handled by what, in particular with import+export being sometimes handled by the same functions, but in sometimes not (applyOperation). I guess we should document that better.

klausi’s picture

Status: Needs work » Needs review
StatusFileSize
new17.63 KB

* Fixed the notice when overwriting default entities with an import.
* Unified the duplicate page/menu title functions.
* Improved documentation on applyOperation() and operationForm() with hints for the export operation.

I'm not sure regarding the lower casing of entity type labels, I left that open as it affects other status messages as well and should probably handled in a separate issue (not import/export specific)

fago’s picture

Status: Needs review » Fixed

great! Committed it, thanks!

See #981786: UI: bad casing of translation replacements for the text follow-ups.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.