Problem/Motivation
AlreadyInstalledException is thrown from four different places and produces the same output on each, so you can't know precisely why the installation process (perhaps mistakenly) believes Drupal is already installed. See https://github.com/drush-ops/drush/issues/511 for one false positive scenario.
Proposed resolution
Add a $detail string argument to AlreadyInstalledException::__construct() and incorporate it into the output. Provide useful info when throwing the exception.
Remaining tasks
Bikeshed the info to provide.
User interface changes
@todo -- new exception messages in various specific already-installed scenarios.
API changes
@todo
- New InstallerException child classes for specific error conditions.
- Additional argument to AlreadyInstalledException.
Comment | File | Size | Author |
---|---|---|---|
#51 | 2459671-51.do-not-test.patch | 8.05 KB | dww |
#44 | 2459671-44.9_1_x.patch | 8.33 KB | dww |
#39 | 2459671-39.patch | 8.04 KB | yogeshmpawar |
Comments
Comment #1
mikeryanPatch attached - running through the testbot, but should go back to "Needs work" regardless, need to refine the messages.
Comment #2
dawehnerAdding more details to exceptions is always a good idea!
I think the point is that we should not verify tasks again, once we have completed the test. Maybe throw something like: 'Installation already finished'?
If we really want to translate those messages, we have to translate them directly in the beginning so that potx can scan them.
Comment #3
mikeryanWith the requested changes (resisting the technically out-of-scope temptation to remove the null-op $task = NULL line)...
Comment #4
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe patch looks good to me and it also helps with debugging random failures for Postgres/SQLite on DrupalCI.
Comment #5
alexpottLet's just use different exceptions here and change AlreadyInstalledException into something abstract.
Comment #6
bzrudi71 CreditAttribution: bzrudi71 commentedJust re-uploading patch to enable PG-bot testing. Setting to NW again later!
Comment #7
bzrudi71 CreditAttribution: bzrudi71 commentedBack to NW...
Comment #8
xjm#4 seems like a reason for this to be major even.
Comment #9
borisson_Changed the AlreadyInstalledException to be a abstract class, added 4 implementations of that class and throw those instead.
Added a screenshot of what this looks like when Implemented.
Comment #10
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedDon't we need the Exception suffix for these two as well?
Comment #11
borisson_@amateescu, you're right, fixed in the attached patch.
Comment #12
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedAh, I should've caught this sooner:
Dynamic strings won't get picked up by the translatable strings extractor so we need to translate the message in the constructor of each exception class. See https://www.drupal.org/developing/api/8/localization ("Variables in user interface text").
Comment #13
borisson_Comment #14
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedMissing a space at the beginning and maybe we should shorten the comment to just "A specific exception message.", mostly because subclasses are extending this class, they don't implement it.
No need to pass $specific_message through
$this->t()
anymore, but we still need the wrapping<li>
s :PComment #15
borisson_#14.1: Fixed.
#14.2: I had moved the wrapping
<li>
's to the subclasses, but this makes more sense, fixed.Comment #16
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThanks, this looks ready to me.
Comment #17
alexpottThis will call $this->t() before the $string_translation is set thereby ignoring the passed in service and just reacing into \Drupal as a service locator.
Comment #18
borisson_The attached patch moves setting stringTranslation to the implementing exceptions.
Comment #19
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented#17: good point!
Comment #20
alexpottThe more I look at this code the more I get weirded out by the use of translated string in exceptions. The installer is the only place this happens in core. And the exception statndards says not to do this. I think we should fix this here.
Comment #21
PieterJanPut CreditAttribution: PieterJanPut at iO commentedComment #22
PieterJanPut CreditAttribution: PieterJanPut at iO commentedAdding interdiff
Comment #23
PieterJanPut CreditAttribution: PieterJanPut at iO commentedForget to remove some, fixed.
Comment #25
alexpott@PieterJanPut we still need the translated message but we should NOT use exceptions to pass translated string around.
What we need to do is continue to introduce the new exceptions here. Add a new class to the installer classes called ConvertInstallerExceptionToMessage() which has the logic for converting an exception to a translated message. And then where the exception is caught use this new utility class to get the translated message for the particular exception.
[edit: corrected incorrect first sentence]
Comment #26
dawehnerDoesn't that break any kind of translatability?
Comment #27
alexpott@dawehner yes it does that's what I was trying to say in #25.
Comment #34
hansfn CreditAttribution: hansfn commentedI think getting this patch in is worthwhile[1] and will be happy to update it (and make translation work properly).
@alexpott: You wrote 3 years ago (!): "What we need to do is continue to introduce the new exceptions here. Add a new class to the installer classes called ConvertInstallerExceptionToMessage() which has the logic for converting an exception to a translated message."
Looking at the current implementation of AlreadyInstalledException, do you still think ConvertInstallerExceptionToMessage is needed? Isn't it just to introduce the new more specific exceptions (following the current AlreadyInstalledException)?
[1] When helping users struggling with a failed install, a ,more specific exception is very helpful for us doing support. Just spent 10 minutes helping a user on Slack. A frustrating experience for both of us.
Comment #35
grahlAttached is a reroll for 8.7 with the translation issue not addressed.
Comment #36
grahlPatch was incomplete
Comment #37
grahl...and fixing the patch level.
Comment #38
yogeshmpawarComment #39
yogeshmpawarResolved some coding standard issue & added an interdiff.
Comment #41
tvb CreditAttribution: tvb commentedThis would be a useful improvement.
The patch applies cleanly to 8.9.x-dev.
I could create the conditions to throw the various exceptions but adding translations seems not to work.
Status unchanged 'Needs Review'.
1) InstallationTasksCompletedException
After a fresh install revisit install.php.
Result:
Drupal already installed.
Installation tasks have already been completed.
To start over, you must empty your existing database and copy default.settings.php over settings.php.
To upgrade an existing installation, proceed to the update script.
View your existing site.
2) DatabaseAlreadyPopulatedException
Comment out $databases array in settings.php and revisit install.php.
Result:
Drupal already installed.
Database is already populated.
To start over, you must empty your existing database and copy default.settings.php over settings.php.
To upgrade an existing installation, proceed to the update script.
View your existing site.
3) ActiveConfigurationExistsException
Drop table sessions (do not drop config table) and revisit install.php.
Result:
Drupal already installed.
Active configuration already exists.
To start over, you must empty your existing database and copy default.settings.php over settings.php.
To upgrade an existing installation, proceed to the update script.
View your existing site.
Note Drupal Core doesn't create an active config directory anymore and The sync directory is defined in $settings and not $config_directories.
4) SettingsAlreadyExistsException
After a fresh install, change database name to a non-existant database in settings.php and revisit install.php.
Result:
Drupal already installed.
Configured settings.php already exists.
To start over, you must empty your existing database and copy default.settings.php over settings.php.
To upgrade an existing installation, proceed to the update script.
View your existing site.
5) Translation
Enabled module Interface translation, added a language (nl) and added a language path prefix for English.
Cleared cache.
But the new strings never show up at admin/config/regional/translate to add translations.
Is this code or configuration (or both) related? Needs further review.
Comment #43
grahlPatch no longer applies to 8.9.2 or newer.
Comment #44
dwwIncomplete re-roll. Something is funky here. The hunk that was to be replaced with throwing
SettingsAlreadyExistsException
doesn't exist in 9.1.x branch anymore. Nor 9.0.x or 8.9.x. Looks like it was removed in #3120731: Incorrect "Drupal already installed" if any database settings are wrong or unsatisfactory.So I believe all of core/lib/Drupal/Core/Installer/Exception/SettingsAlreadyExistsException.php is dead code, since we're not throwing it anywhere.
But I don't want to leave it out of the patch (yet), since I haven't taken the time to fully understand this issue and all the gory details. So leaving at NW for sorting this out and cleaning it up.
Interdiff isn't working, so here's a raw diff of #39 vs. this.
Also note that I fixed the @throws annotation on install_verify_database_ready() and the comment where it's called.
There's some other stuff I'd fix in here, but I want to start with as close to a "pure" reroll as possible, before making other changes.
Also, tagging for 'Needs tests', since there's no test coverage of the new exceptions in here, and we certainly want that. ;)
Thanks,
-Derek
p.s. I named this "9_1_x" but I just checked and it applies to 8.9.x and 9.0.x, too... sorry for any potential confusion. Although I doubt this would be backported, so it probably doesn't matter.
Comment #45
dwwHere ares some of the other things we should change before this is NR:
Don't understand this pattern with the new
$translator
local variables. Why not:basically as before?
All of these comments should be more specific for the separate exception types.
s/@var/@param
This message needs message help (message). 😉
Maybe:
(Optional) A specific message to include when the exception is thrown.
?
Guess it should also mention that this custom message is prepended to the main text that's always printed...
Don't we still need this line?
Although, why are we passing the
TranslationInterface
at all? Doesn't look like it's used. Maybe the better fix is to remove it everywhere?Per #44, I believe this is all dead code now. TBD.
Patch ends before any tests are added. ;) #NeedsTests.
Thanks,
-Derek
Comment #46
dwwRe: #45.5b: Looks like we should have a follow-up to remove (deprecate?)
StringTranslationTrait
fromInstallerException
since we don't want to translate exception titles or messages anymore. Quick search doesn't turn up anything, but maybe someone else knows if it already exists.Comment #47
andypostI think we have sniffer now to prevent translation of exceptions starting from 8.9 #2055851: Remove translation of exception messages
Comment #48
dwwRight. So is this the issue to deprecate
StringTranslationTrait
fromInstallerException
, or should we do that separately (probably first), and then this patch will be smaller and simpler?Comment #49
andypost++ file blocker for the issue and postpone that one
Comment #50
dww#3161140: Remove the StringTranslationTrait from InstallerException
Comment #51
dwwAssuming that lands, something like this.