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

Include database.php only if it exists #543

Closed
wants to merge 1 commit into from
Closed

Include database.php only if it exists #543

wants to merge 1 commit into from

Conversation

xemle
Copy link

@xemle xemle commented Mar 4, 2012

Adds an file check for the database configuration and includes
the file only if it exists.

The datasource configuration might not be always available e.g. for
application bootstrapping via a webfront. The patch inits an empty
configuration if no database.php file is present.

Adds an file check for the database configuration and includes
the file only if it exists.

The datasource configuration might not be always available e.g. for
application bootstrapping via an webfront. The patch inits an empty
configuration if no database.php file is present.
@xemle xemle mentioned this pull request Mar 4, 2012
@xemle
Copy link
Author

xemle commented Mar 4, 2012

Here a more detailed description of my pull request: My web gallery phtagr.org has an installation setup procedure to create the database configuration file via the web interface. The user inserts the database config details in a form and than the file is written by the application. However, the Form helper checks the model data which initializes the ConnectionManager. Since the database.php file does not exists yet CakePHP gives a warning on opening an invalid file.

I propose to add the given check to ConnectionManager. But if there is another way to bypass this issue, I'm happy, too.

@markstory
Copy link
Member

I'm onboard with this change. Any objections? It doesn't change the 2.1 API, and helps apps with installers out.

@rchavik
Copy link
Member

rchavik commented Mar 6, 2012

You could turn off debugging in your view to workaround this issue, eg: croogo/croogo@4b71a05

@lorenzo
Copy link
Member

lorenzo commented Mar 6, 2012

I object, increasing IO in every request just for ease the task of writing installers is IMO not a good idea. Installers could do the checking before and not use models in the form helper.

@ADmad
Copy link
Member

ADmad commented Mar 6, 2012

One can do $this->Form->create(false); and tell the helper not a use a model isn't it?

@ceeram
Copy link
Contributor

ceeram commented Mar 6, 2012

I agree with ADmad and lorenzo. One other thing to take into consideration: calling ConnectionManager::create() to test provided credentials would always error out if the file isnt present.

@markstory
Copy link
Member

Closing then, seems there isn't a ton of interest in merging this in and several alternatives have been provided.

@markstory markstory closed this Mar 6, 2012
@xemle
Copy link
Author

xemle commented Mar 6, 2012

thank you very much for this great response.

@ADmad: I've tried $this->Form->create(false); and $this->Form->create(null); but did not help.

@rchavik: Thanks for this great idea to suppressing debug warnings with Configure::write('debug', 0) at this point! That will do the job!

So closing is fine.

Best regards, Xemle

PS: @lorenzo: I agree to avoid increasing IO. Another proposal is suppressing the warning by prefixing '@' of include_once statement, if this issue is still hot.
PPS: Just for completeness here my code snippets:

<?php 
  echo $this->Form->create(false, array('action' => 'config')); 
  echo $this->Form->input('db.login', array('label' => __('Username')));
  echo $this->Form->input('db.password', array('label' => __('Password'), 'type' => 'password'));
  echo $this->Form->end(__('Continue')); 
?>

Warnings:

Warning (2): include_once(/var/www/phtagr/Config/database.php): failed to open stream: No such file or directory [APP/cakephp/lib/Cake/Model/ConnectionManager.php, line 68]
Warning (2): include_once() [http://php.net/function.include]: Failed opening '/var/www/phtagr/Config/database.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') [APP/cakephp/lib/Cake/Model/ConnectionManager.php, line 68]

Stacktrace:

ConnectionManager::_init() - APP/cakephp/lib/Cake/Model/ConnectionManager.php, line 68
ConnectionManager::enumConnectionObjects() - APP/cakephp/lib/Cake/Model/ConnectionManager.php, line 190
ClassRegistry::init() - APP/cakephp/lib/Cake/Utility/ClassRegistry.php, line 110
FormHelper::_getModel() - APP/cakephp/lib/Cake/View/Helper/FormHelper.php, line 147
FormHelper::_introspectModel() - APP/cakephp/lib/Cake/View/Helper/FormHelper.php, line 180
FormHelper::tagIsInvalid() - APP/cakephp/lib/Cake/View/Helper/FormHelper.php, line 281
FormHelper::_initInputField() - APP/cakephp/lib/Cake/View/Helper/FormHelper.php, line 2571
FormHelper::__call() - APP/cakephp/lib/Cake/View/Helper/FormHelper.php, line 1444
FormHelper::text() - APP/cakephp/lib/Cake/View/Helper/FormHelper.php, line 1141
FormHelper::input() - APP/cakephp/lib/Cake/View/Helper/FormHelper.php, line 1141
include - APP/View/Setup/config.ctp, line 11
View::_evaluate() - APP/cakephp/lib/Cake/View/View.php, line 908
View::_render() - APP/cakephp/lib/Cake/View/View.php, line 872
View::render() - APP/cakephp/lib/Cake/View/View.php, line 463
Controller::render() - APP/cakephp/lib/Cake/Controller/Controller.php, line 962
Dispatcher::_invoke() - APP/cakephp/lib/Cake/Routing/Dispatcher.php, line 110
Dispatcher::dispatch() - APP/cakephp/lib/Cake/Routing/Dispatcher.php, line 85

@ADmad
Copy link
Member

ADmad commented Mar 6, 2012

@xemle Have you tried using field name like 'login' instead of 'db.login'?

@xemle
Copy link
Author

xemle commented Mar 6, 2012

Yes, makes no changes.

Is there a way to suppress the field validation check in form helper which does not introspect the model? Might be useful for inputs which do not belong to a model.

@lorenzo
Copy link
Member

lorenzo commented Mar 6, 2012

Use something that is not a model such as $this->Form->create(false); $this->Form->input('my_field'); That will be tied to no model

@ADmad
Copy link
Member

ADmad commented Mar 6, 2012

That's what i had suggested, perhaps I was not clear enough.

@xemle
Copy link
Author

xemle commented Mar 6, 2012

OK, my fault. I did not replace all form field prefixes. It works without the dot notation. Thank you!

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

Successfully merging this pull request may close these issues.

None yet

6 participants