Hi,
I have installed the module but if I try to uninstall it immediately it's not possible. The message is : There are origname field data for the type of file entity.

Can you explain to me how I can unistall it ?

Thank

Comments

stevensf created an issue. See original summary.

stevensf’s picture

Issue summary: View changes
Deciphered’s picture

Priority: Normal » Major

I'm escalating this issue to Major as it's a pretty big issue.

It's also quite a complicated issue.

Essentially, File (Field) Paths is, both in the past and currently, adding a new field to the File entity; origname. This field contains what the original name of the file was at the point it was uploaded (or when the module was installed), allowing modified files to be reverted back to their original name at a later stage, and various other usages.

Drupal 8 allows for this behaviour, but what it doesn't allow for is the ability to purge this data, therefore making it impossible to uninstall a module that has taken this path without implementing a custom storage solution... unless you are the Field module, in which case you get an exception from this rule.

It's likely I will either have to implement a workaround, or re-architect this particular piece of functionality so that this issue can be resolved, but both will take some time and though to ensure that the correct solution is implemented.

Dom.’s picture

Priority: Major » Critical

Updating to critical since their no way to workaround except direct SQL.
Run this : UPDATE file_managed SET origname = null
to empty the whole column before you can then delete the module.

Macronomicus’s picture

Ive a slightly different error along these same lines, for me the module didn't install properly and then wasn't able to uninstall.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'origname' in 'where clause': SELECT 1 AS expression FROM {file_managed} t WHERE ( (origname IS NOT NULL ) ) LIMIT 1 OFFSET 0; Array ( ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->countFieldData() (line 1658 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

So in this case the solution is the following mysql for the missing column...

mysql>alter table file_managed add column origname varchar (20);
Then i was able to uninstall, I still had to manually delete the origname column as uninstall didnt remove that, everything is back to normal now, best of luck on the planned fix :)

frob’s picture

Sounds like the best solution would be to move this data over to its own table.

Has a core issue been opened on this? It sounds like a core issue.

MartinMa’s picture

Just had this problem too. Thanks to #4 I could remove it! It seem, that another problem removing file entity module was also solved for me :-)

SKAUGHT’s picture

alter table file_managed add column origname varchar (20);
worked...

this issue needs to be addressed. still critical.

SKAUGHT’s picture

Assigned: stevensf » Unassigned

removing assigned person.

Rewted’s picture

Issue still remains. Cannot uninstall even though it wasn't even used.

rooby’s picture

Priority: Critical » Major

Not critical because it doesn't break anything or render the site unusable and there is a work around.

sassafrass’s picture

Having this issue too. #4 is a temporary fix, but it worked for me.

joelpittet’s picture

@Deciphered Could you just put in a hook_uninstall to purge the values in that column and delete the field?

https://www.drupal.org/docs/8/api/entity-api/defining-and-using-content-...

/**
 * Implements hook_uninstall().
 */
function filefield_paths_uninstall() {
  $definition = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions('file')['origname'];
  \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionDelete($definition);
}
joelpittet’s picture

jonathanshaw’s picture

According to #2905944: Uninstall modules which define base fields you can uninstall a module that provides a base field on a 3rd party entity, if you first set it to NULL.

For an entity_test_extra module providing a _test_base_field on an entity_test entity, this works:

$entity_definition = $this->entityManager->getDefinition('entity_test');
   \Drupal::database()->update($entity_definition->getBaseTable())
     ->fields(['test_base_field' => NULL])
     ->execute();

$this->uninstallModule('entity_test_extra');
\Drupal::entityDefinitionUpdateManager()->applyUpdates();

So perhaps this module could set it's base field to NULL in hook_uninstall

leopinzon’s picture

I had the same issue, even after just installed but never used it. Anyway thanks to comment #4 I was able to uninstall it.

jonathanshaw’s picture

#2282119: Make the Entity Field API handle field purging will enable base field deletion in core.

SKAUGHT’s picture

although, won't help anyone running less than 8.5 once it lands.. this issue against module would still stand.

AdamPS’s picture

I came across this thread when hitting the same problem for a module I am developing.

@jonathanshaw I don't think #15 works. In my testing hook_uninstall did not even get called if the checks failed.

I did manage to create a function like this

function MODULE_NAME_force_install() {
  $base_table = \Drupal::entityTypeManager()->getDefinition('node')->getDataTable();
  \Drupal::database()->update($base_table)->fields(['FIELD_NAME' => NULL])->execute();
  \Drupal::service('module_installer')->uninstall(['MODULE_NAME']);
}

Which can then be called from drush eval.

ChuChuNaKu’s picture

#4 worked for me as a temporary workaround too. Here are the steps I took using drush

drush sql-query "UPDATE file_managed SET origname = null"
drush cr && drush pmu -y filefield_paths
drush php-eval "db_drop_field('file_managed', 'origname');"