localgovdrupal / localgov_geo

Entity for storing Geographic information, addresses, and areas; extensible types and plugable backends with defaults to start.
2 stars 1 forks source link

Update fails on microsite installations #125

Open dedavidson opened 4 months ago

dedavidson commented 4 months ago

The hook_update added in #121 fails on microsite installs as the localgov_roles module is (rightly) not enabled.

finnlewis commented 4 months ago

I wonder if we can wrap the update hook and use statements in a conditional to check if localgov_roles is enabled.

finnlewis commented 4 months ago

Nope!

The use keyword must be declared in the outermost scope of a file (the global scope) or inside namespace declarations.

https://www.php.net/manual/en/language.namespaces.importing.php#language.namespaces.importing.scope

I can replicate the error though.

finnlewis commented 4 months ago

Any suggestions @dedavidson @ekes @MariosORION ?

finnlewis commented 4 months ago

Maybe we don't need the use statement, if the rest is conditional.

dedavidson commented 4 months ago

Could turn your idea round and put the update in localgov_roles and check if localgov_geo is enabled?

finnlewis commented 4 months ago

Could turn your idea round and put the update in localgov_roles and check if localgov_geo is enabled?

Could turn your idea round and put the update in localgov_roles and check if localgov_geo is enabled?

Could turn your idea round and put the update in localgov_roles and check if localgov_geo is enabled?

Yeah, starting to think that's the best (only?) way.

We can't wrap the use statement in a conditional.

We can't access the RolesHelper::CONTRIBUTOR_ROLE without the use statement. (or can we? )

Kind of run out of time on this for today, but keen to fix this quickly.

Anyone else got any bandwidth to try other things?

Also, if we move it, what do we do with the update hook? Leave it in place but empty?

dedavidson commented 4 months ago

Can we use a FQN without use e.g. \Drupal\localgov_roles\RolesHelper::CONTRIBUTOR_ROLE?

finnlewis commented 4 months ago

Can we use a FQN without use e.g. \Drupal\localgov_roles\RolesHelper::CONTRIBUTOR_ROLE?

Good shout, trying that now https://github.com/localgovdrupal/localgov_geo/pull/126/files

Seems to work fine for me locally, and if the roles don't exist, they don't get loaded, so no harm done.