When trying to run a custom module script triggered by the use of a 'one time login' sent by an email for users to reset their passwords I have to include 'user.pages.inc'
This is the URL (edited for anonymity, I hope)
MYSITE/user/THE-USERS-UID/edit?pass-reset-token=DR8wV7YGtmp5Ia8HQvU1YMs94IRBHsa7-lubQuaLTNs
I started off with this:
module_load_include('inc', 'user', 'user.pages');
but that leads to this error when I do finally get to the include in the script.
Fatal error: require_once(): Failed opening required '/var/www/html//user.pages.inc' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/includes/menu.inc on line 515
I imagine this /var/www/html//user.pages.inc
might well be where the problem lies as that location definitely doesn't exist, but 1) I'm not sure 2) I don't know how that would be occurring or how to fix it.
It was working fine on my development environment, then when it didn't run on the production environment I tried...
include_once DRUPAL_ROOT . 'modules/user/user.pages.inc';
//module_load_include('inc', 'user', 'user.pages');
which also lead to the same error
I got onto the thread of pear being important etc. (http://ubuntuforums.org/showthread.php?t=1025510)
I followed some guides on installation and set it up....
https://stackoverflow.com/questions/5428778/installing-pear
http://pear.php.net/manual/en/installation.checking.php
The original php.ini....
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; UNIX: "/path1:/path2"
;include_path = ".:/usr/share/php"
became this...
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; UNIX: "/path1:/path2"
include_path = ".:/usr/share/php:/usr/share/pear/PEAR"
;
I restarted apache service httpd restart
My error message is now...
Fatal error: require_once(): Failed opening required '/var/www/html//user.pages.inc' (include_path='.:/php/includes:/usr/share/pear') in /var/www/html/includes/menu.inc on line 515
I did some more checking...
# pear config-get php_dir
/usr/share/pear
# php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed: /etc/php.d/curl.ini,
/etc/php.d/dom.ini,
/etc/php.d/fileinfo.ini,
/etc/php.d/gd.ini,
/etc/php.d/json.ini,
/etc/php.d/mbstring.ini,
/etc/php.d/mcrypt.ini,
/etc/php.d/mysql.ini,
/etc/php.d/mysqli.ini,
/etc/php.d/pdo.ini,
/etc/php.d/pdo_mysql.ini,
/etc/php.d/pdo_sqlite.ini,
/etc/php.d/phar.ini,
/etc/php.d/sqlite3.ini,
/etc/php.d/wddx.ini,
/etc/php.d/xmlreader.ini,
/etc/php.d/xmlwriter.ini,
/etc/php.d/xsl.ini,
/etc/php.d/zip.ini
I've since written a php info file which tells me this...
include_path .:/php/includes:/usr/share/pear .:/php/includes:/usr/share/pear
I've confirmed that /modules/user/user.pages.inc
DOES exist (it's core anyway, right?)
and my other scripts are working (at least they seem to be?!)
By the way - I'm having to include the user.pages.inc
because 'user_profile_form' isn't included for some reason.
I lost the drupal.org link to a topic that was set as closed because it's 'working as intended' but here's a token stackoverflow post that might help explain what I mean: https://stackoverflow.com/questions/6572882/drupal-7-insert-user-profile-form-into-a-page
I've just started looking into the idea that it's a permissions problem, but the rest of the codebase seems to have the same 644 permissions and that's running fine.
EDIT: I'm also using Domain Access, but a colleague set that up and is away so I'm not sure if that's relevant at all but I thought I'd point it out.
I've also cleared Drupal's caches
I didn't emphasise it originally but it's important to note that the trigger for this fatal error comes when I use the one-time-only password reset URL that leads to the error. When a user requests a password reset, it is the link from the email sent out that I've been pasting in which has lead to the error. However this is integral, so removing it is not an option (plus it worked on my development environment...)
It leads the user to the hook_menu()
in user.module which I've hijacked with hook_admin_menu_alter()
in my custom module (MYMODULE) for a bespoke area of the site that required dynamic redirection after.
$items['user/reset/%/%/%'] = array(
'title' => 'Reset password',
'page callback' => 'drupal_get_form',
'page arguments' => array('MYMODULE_user_pass_reset', 2, 3, 4),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
Because as you'll see below, the original user_pass_reset
callback uses a drupal_goto() and therefore I can't redirect as I would by hooking the form and using redirect (or by adding another submit handler)
if ($account->login && $current - $timestamp > $timeout) {
drupal_set_message(t('You have tried to use a one-time login link that has
expired. Please request a new one using the form below.'));
drupal_goto('user/password');
}
So I created an almost duplicate version of it, except for the edit to the above which now retrieves the last place the user tried to go, before resetting their password, from the db and supplying that in the drupal_goto() parameters.