Should be loaded only when needed.

CommentFileSizeAuthor
#1 password_policy-constraint-inc.patch3.73 KBjohn.money

Comments

john.money’s picture

Status: Active » Needs review
StatusFileSize
new3.73 KB

Attached is patch which moves the global variable from hook_init into a static variable in function _password_policy_contraints().

deekayen’s picture

Status: Needs review » Needs work

Declaring a variable to be static does not also make it global. When you call your new function in validate, description, js, etc, it doesn't look like it would actually do anything, so it looks like the only time your new function does anything is when you call it in password_policy.admin.inc.

john.money’s picture

The static var gets set just once per page load.

If validate, description, js etc is the first to call the function _password_policy_contraints(), the static var is by definition not yet set and therefore loads in the contraint inc files. If however the function has already been called once on the page load, the static var is already set and is returned without loading in the constrain inc files. Using global var is overkill especially since we're loading in inc files on 99% of pages that have no need for them.

deekayen’s picture

I'm with you on getting it out of hook_init(), you don't have to justify that part.

What I'm saying is that if you're only using the return value of your new function in admin.inc, then it can load the constraint files then. They don't need to be pre-loaded and set in a static var.

john.money’s picture

There is a negligible performance hit for the array of drupal_substr($file->name, 11) which as you rightly point out is effectively discarded for all but the admin.inc. The benefit is that the file load logic is consistent throughout. And of course net-net, its a huge performance improvement over loading them for every page.

Function with static var seems a pretty common approach anywhere file io is used.

deekayen’s picture

Assigned: Unassigned » deekayen

I'm still not sure why you have all the extra calls. If that function doesn't include the relevant constraint files at the time you called it there, will stuff break?

deekayen’s picture

Status: Needs work » Fixed
tacituseu’s picture

Status: Fixed » Needs work

there's some leftover in password_policy.admin.inc:
global $_password_policy;

deekayen’s picture

Status: Needs work » Fixed

Good catch. As you probably noticed, your patch didn't apply anymore, so I tried to apply it the hard way...

afreeman’s picture

Priority: Normal » Critical
Status: Fixed » Needs work

Fatal error: Call to undefined function _password_policy_constraints() in modules/password_policy/password_policy.admin.inc on line 256

deekayen’s picture

Patch reverted.

tacituseu’s picture

Seems OP spelled it as 'contraints' (no s).

deekayen’s picture

Status: Needs work » Fixed

spelling fixed. hope this thing is finally dead.

roball’s picture

Does this mean the critical bug went into alpha4?

deekayen’s picture

Yes. Download the latest nightly snapshot for the fix.

roball’s picture

Version: 6.x-1.0-alpha3 » 6.x-1.0-alpha4

So correcting the latest affected version. I'll wait for the next release instead.

john.money’s picture

Sorry for function name misspelling... my bad. :(

ryanscottdavis’s picture

Status: Fixed » Patch (to be ported)

Bug is still active.

When I (admin) navigate to admin/settings/password_policy/add, I get the following error:
Fatal error: Call to undefined function _password_policy_constraints() in sites\all\modules\password_policy\password_policy.admin.inc on line 257

I understand the misspelling issue. Can we push this patch to the latest downloadable version? A recent download still gets "foreach (_password_policy_constraints() as $constraint) {" on line 257.

deekayen’s picture

Status: Patch (to be ported) » Fixed

You guys are persistent... see 6.x-1.0-beta1

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.