Using a php code working with 6.x, and with errors in 7.0
Notice: Use of undefined constant DRUPAL_ROOT - assumed 'DRUPAL_ROOT' in /home/empresa/public_html/includes/bootstrap.inc on line 2094
Warning: require_once(DRUPAL_ROOT/includes/errors.inc) [function.require-once]: failed to open stream: No such file or directory in /home/empresa/public_html/includes/bootstrap.inc on line 2094
Fatal error: require_once() [function.require]: Failed opening required 'DRUPAL_ROOT/includes/errors.inc' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/empresa/public_html/includes/bootstrap.inc on line 2094
the code afected is at the start of my php program (a program that writes nodes).
function init_script() {
global $adminuser;
global $adminpass;
include_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
bootstrap_invoke_all('init');
ini_set('memory_limit', '512M');
if( ! function_exists("node_object_prepare")) {
include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
} else {
require_once 'modules/node/node.pages.inc';
}
//Authenticate as user 1
user_authenticate($adminuser, $adminpass);
}
if i try to include DRUPAL_ROOT and change the code to
function init_script() {
global $adminuser;
global $adminpass;
define('DRUPAL_ROOT', getcwd());
//require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
include_once(DRUPAL_ROOT . '/includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
bootstrap_invoke_all('init');
ini_set('memory_limit', '512M');
if( ! function_exists("node_object_prepare")) {
include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
} else {
require_once DRUPAL_ROOT . '/modules/node/node.pages.inc';
}
//Authenticate as user 1
user_authenticate($adminuser, $adminpass);
}
i get the following error
Fatal error: Cannot redeclare comment_page_title_alter() (previously declared in /home/empresa/public_html/sites/all/modules/page_title/modules/comment.page_title.inc:13) in /home/empresa/public_html/sites/all/modules/page_title/modules/comment.page_title.inc on line 27
This is already posted in http://drupal.org/node/1009966 but under code questions. I think maybe this should be treated as bug or error? i imagine it should be some people using node_save() in their php custom programs that fall in the same error?
Comment | File | Size | Author |
---|---|---|---|
#12 | page_title-7.x-2.7-fix-error-bootstrap-1024624.patch | 4.01 KB | bpresles |
#11 | 1024624-11-include_once.patch | 626 bytes | stella |
Comments
Comment #1
Damien Tournoud CreditAttribution: Damien Tournoud commentedSounds like you are on the right track.
That looks like a bug in that particular module, don't you think?
Comment #2
egarias CreditAttribution: egarias commentedYou are right Damien so i understand:
in my php custom programs.
And I keep waiting for page title team for indications regarding the issue
Comment #3
nicholasThompsonI've added a fix for this in the latest dev - it has a static variable to protect the includes from running more than once.
Comment #4
egarias CreditAttribution: egarias commentedOk fixed
Comment #5
Everett Zufelt CreditAttribution: Everett Zufelt commentedI wouldn't usually open an old issue, but I am getting the same error in 7.x-2.7, installed on a fresh build of a site today.
Any thoughts?
Comment #6
nicholasThompsonCould you please describe your system setup and the steps we need to follow to reproduce?
If it is happening again, it's likely due to this section:
http://drupalcode.org/project/page_title.git/blob/ce49055682b59b77b15fdf...
Comment #7
Everett Zufelt CreditAttribution: Everett Zufelt commenteddownload drupal 7.15
install drupal
drush dl page_title
drush en page_title
drush cc all
Should reproduce the error
Comment #8
Everett Zufelt CreditAttribution: Everett Zufelt commentedTo be clear, the error is similiar to:
Fatal error: Cannot redeclare comment_page_title_alter() (previously declared in /home/empresa/public_html/sites/all/modules/page_title/modules/comment.page_title.inc:13)
in /home/empresa/public_html/sites/all/modules/page_title/modules/comment.page_title.inc on line 27
Comment #9
Everett Zufelt CreditAttribution: Everett Zufelt commentedClosing again, it is clear that this should work, it must be another part of the code that is resetting the static.
Comment #10
Everett Zufelt CreditAttribution: Everett Zufelt commentedComment #11
stella CreditAttribution: stella commentedSorry to reopen this but I still encounter this issue when I enable the 'page_title' module as part of the setUp() function in a simpletest.
The error received is the same:
I've changed it so it calls an "include_once" rather than an "include", in line with Drupal core modules, etc, though I know you're worried about a performance hit, but at least this way it works. Patch attached.
Comment #12
bpresles CreditAttribution: bpresles commentedI got this issue when running a SimpleTest test from command line (Drush), that uses an installation profile in which there is page_title module as a dependency.
The include_once proposed patch does solve this issue. But I provide another patch that doesn't use include_once, and instead use a constant defined in each sub modules respecting a unique naming convention (PAGE_TITLE_<MODULE_NAME>_SUB_MODULE (e.g: PAGE_TITLE_COMMENT_SUB_MODULE)), and added a check to avoid to perform the include if the constant for the required module is defined (see attached patch).
I think it's a better solution to solve this issue regarding performances.
Comment #13
Ctrl-E CreditAttribution: Ctrl-E commented+1 for this. include_once solved issue running commands via drush for me, thanks. But now I have a patched module. Any possibility of a permanent fix in future updates?
Comment #16
torotil CreditAttribution: torotil commentedThis seems to me a lot like premature optimization. include_once / require_once are surely one of the most optimized operations in PHP. Is there any profiling / performance problem that justifies the use of a non-standard / complicated workaround for not using include_once?