[drupal-devel] [bug] Do not execute functions in include files

chx drupal-devel at drupal.org
Mon May 16 21:12:40 UTC 2005


Issue status update for http://drupal.org/node/18213

 Project:      Drupal
 Version:      cvs
 Component:    base system
 Category:     bug reports
 Priority:     normal
 Assigned to:  chx
 Reported by:  killes at www.drop.org
 Updated by:   chx
 Status:       patch
 Attachment:   http://drupal.org/files/issues/bootstrap_3.patch (12.36 KB)




chx



Previous comments:
------------------------------------------------------------------------

March 2, 2005 - 00:09 : killes at www.drop.org

Drupal currently executes functions in include files. This is very
annoying if you want to include files from external scripts such as
update scripts or other scripts that want to use Drupal as a framework.


Offending files are:


database.inc:
db_set_active();


session.inc:
session_set_save_handler("sess_open", "sess_close", "sess_read",
"sess_write", "sess_destroy", "sess_gc");
session_start();


common.inc:
A bunch of stuff at the bottom.


All this should be moved into a start.inc file.




------------------------------------------------------------------------

March 27, 2005 - 08:44 : adrian

I haven't done this recently, but back in 4.4 era I attempted something
similar to this for the install api.


A _lot_ of modifications were required to be able to use (for instance)
the theme api without needing to have a database connection active.




------------------------------------------------------------------------

March 27, 2005 - 08:55 : adrian

It's definately not a simple problem.


For instance.. the db connection needs to be started during bootstrap,
and during normal execution.


I think the better idea is to include a DRUPAL_INIT constant we can
check before executing the function. (or a DRUPAL_NO_INIT .. i'm not
picky).




------------------------------------------------------------------------

April 28, 2005 - 23:53 : killes at www.drop.org

Here's an old patch by me that illustrates what I want to do.
http://lists.drupal.org/archives/drupal-devel/2005-03/txtq23pAcHATw.txt


Instead of putting the stuff into index.php, alternative file names
need to be found.




------------------------------------------------------------------------

May 4, 2005 - 19:36 : chx

Attachment: http://drupal.org/files/issues/boot.patch (6.83 KB)

Well, I have written something to address the issue.


Now you can include everything to your hearts content just include
init.inc as well and do an appropriate drupal_bootstrap.


Alas, ATM database and bootstrap is very interwined. This
interdependency could be obliterated if we'd not use
variable_get('dev_query') in database.*.inc.


cvs diff -u -N -F^f against cvs.drupal.org as CVSROOT failed to include
to include the two new files, so I'll include them as followups.




------------------------------------------------------------------------

May 4, 2005 - 19:37 : chx

Attachment: http://drupal.org/files/issues/boot_0.patch (10.31 KB)

Hm, settings.php changes were ommited.




------------------------------------------------------------------------

May 4, 2005 - 19:37 : chx

Attachment: http://drupal.org/files/issues/init.inc (3.46 KB)




------------------------------------------------------------------------

May 4, 2005 - 19:38 : chx

Attachment: http://drupal.org/files/issues/settings_ini_set.php (850 bytes)




------------------------------------------------------------------------

May 4, 2005 - 19:44 : chx

Attachment: http://drupal.org/files/issues/boot_1.patch (14.49 KB)

Following advice from darix I have now created one patch. Still, I'd
like to know how could I do this with cvs.




------------------------------------------------------------------------

May 4, 2005 - 20:01 : chx

Attachment: http://drupal.org/files/issues/boot_2.patch (14.48 KB)

Steef found that I had $$ in settings.php.


He also asked what's this good for. Several things, but most advantages
come when you use only parts of Drupal. If you want use, say, only our
forms functions then now you can include('common.inc'); without side
effects. If you need the database layer, you do a include('init.inc')
and call drupal_bootstrap('database')




------------------------------------------------------------------------

May 5, 2005 - 23:03 : chx

Attachment: http://drupal.org/files/issues/boot_3.patch (17.98 KB)

The database layer is now totally independent of other parts of Drupal.




------------------------------------------------------------------------

May 15, 2005 - 21:37 : chx

A very stupid bug related to variable init is fixed and I am sync'd to
HEAD, so timer_init('page') is called.







More information about the drupal-devel mailing list