Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config.php will not be written if it does not exist #29

Open
sebsel opened this issue Aug 11, 2017 · 1 comment
Open

config.php will not be written if it does not exist #29

sebsel opened this issue Aug 11, 2017 · 1 comment

Comments

@sebsel
Copy link
Collaborator

sebsel commented Aug 11, 2017

So, we write the config.php file if it's writeable, and if not, we show the user what to copy to the file by hand.

Since we don't ship with a config.php file, and since is_writeable() returns false when file does not exist, people will always have to copy it manually.

Maybe we should do a @touch($configfile); right before it? Suppressing any errors, because we check for writability next thing?

if (is_writeable($configfile) && !$configured) {

Mentioning PR #27 here, because it's about cleaning up setup.php

@Zegnat
Copy link
Collaborator

Zegnat commented Aug 11, 2017

I’d rather not first try and force the creation of a file.

If you want to keep all the separate logic we have now, the solution would be to extend the if-statement to check if the directory is writeable when the file doesn’t exist:

    if (!$configured && (
        is_writeable($configfile) ||
        !file_exists($configfile) && is_writeable(dirname($configfile))
    )) { 

But I would prefer dumbing down our code and swapping the entire file-write section with just one line:

$file_written = file_put_contents($configfile, $config_file_contents);

file_put_contents will (over)write or create the file, does exactly what we currently do (it “is identical to calling fopen(), fwrite() and fclose() successively”), and will set $file_written to false if something went wrong so we can tell people to manually copy the file contents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants