If you have forget to configure a private directory or somewhy you can't write in it or somewhy the file doesn't created, you will get this exception:

Error: Call to a member function id() on boolean in gdpr_tasks_entity_presave() (line 161 of D:\phptest\gdpr-test\modules\gdpr\modules\gdpr_tasks\gdpr_tasks.module) #0 [internal function]: gdpr_tasks_entity_presave(Object(Drupal\gdpr_tasks\Entity\Task))
#1 D:\phptest\gdpr-test\core\lib\Drupal\Core\Extension\ModuleHandler.php(402): call_user_func_array('gdpr_tasks_enti...', Array)
#2 D:\phptest\gdpr-test\core\lib\Drupal\Core\Entity\EntityStorageBase.php(169): Drupal\Core\Extension\ModuleHandler->invokeAll('entity_presave', Array)
#3 D:\phptest\gdpr-test\core\lib\Drupal\Core\Entity\ContentEntityStorageBase.php(730): Drupal\Core\Entity\EntityStorageBase->invokeHook('presave', Object(Drupal\gdpr_tasks\Entity\Task))
....

Reproduce:
1. Install new site and do not set private directory.
2. Install GDPR module.
3. Create (i.e.) a user export.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

golddragon007 created an issue. See original summary.

golddragon007’s picture

Status: Active » Needs review
FileSize
584 bytes

This patch will fix it.

mhavelant’s picture

Status: Needs review » Needs work

This is not the correct way. The exception is thrown because of that, yes, but there are warnings generated a lot sooner, at the first file_prepare_directory call.

We should check the private files folder:

  1. even before the module is installed and error out if it's not set.
  2. before we try to save to it and throw an error
pedrop’s picture

Assigned: Unassigned » golddragon007

  • mhavelant committed bfd1b69 on 8.x-1.x
    Issue #2975467 by golddragon007, mhavelant: Exception if no private dir...
mhavelant’s picture

Status: Needs work » Fixed

I added the check to the requirements hook, it should now prevent install, update and throw an error on reports, as well, if the private files are not set, don't exist or is not writable.

This should be enough for now, if there are any more errors, let's implement the second one (check during tasks entity presave), too. But for now, that part is postponed.

Status: Fixed » Closed (fixed)

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