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

CRM-20904 : joomla cron run - load all daos defined in extensions #10692

Merged
merged 1 commit into from
Jan 16, 2018

Conversation

jitendrapurohit
Copy link
Contributor

@jitendrapurohit jitendrapurohit commented Jul 18, 2017

Joomla doesn't invoke any hooks until J_EXEC is set.

And when cron job is executed via URL - Config run loads all core DAO's in $self::entityTypes before joomla is actually bootstraped, this value is unchanged and only keeps core value defined in it.

Fix here does a fresh load of all the DAO's defined in extensions, custom modules, etc soon after the bootstrap is done successfully.


@jitendrapurohit
Copy link
Contributor Author

jenkins, retest this please

@@ -342,6 +342,8 @@ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realP
}
CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, FALSE);
}
//CRM-20904 Load all DAOs defined in hooks/extensions.
CRM_Core_DAO_AllCoreTables::reinitializeCache(TRUE);
Copy link
Member

@totten totten Jul 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting.

If you said there was a bug with Joomla extensions where the cache in AllCoreTables got stale, that would make sense. (IIRC, hook_civicrm_entityTypes is actually a boot-critical hook -- the first hook fired. This would mean it fires before Civi has a chance to bootstrap Joomla, so it would initialize without the benefit of any CMS modules.)

Gonna see if I can replicate...

@totten
Copy link
Member

totten commented Jul 21, 2017

I've tried to reproduce the original issue (before patch). The steps taken were:

  1. Go to my local Joomla build. (This was running v4.7.21; created via civihydra. On PHP 5.6.30, mysql 5.7.18, and Ubuntu 16.10.)
  2. Clone https://github.com/eileenmcnaughton/nz.co.fuzion.accountsync into build/hydra-joomla/administrator/components/com_civicrm/civicrm/ext/nz.co.fuzion.accountsync
  3. Install. (This failed at first, but I hacked sql/auto_install.mysql to work-around.)
  4. Add a print statement to one of the jobs (api/v3/Job.php -- civicrm_api3_job_update_greeting) so that we'd be able to see if it runs. ( printf("<pre>%s %s %s</pre>", __FILE__, __LINE__, var_export(CRM_Core_DAO_AllCoreTables::get(), 1));)
  5. In a browser, open http://hydra-joomla.l/administrator/components/com_civicrm/civicrm/bin/cron.php?name=admin&pass=topsecret&key=abcdabcdabcdabcd&job=update_greeting&ct=Individual&gt=email_greeting
  6. Observe that the job executes and runs the print statement.
  7. Observe that the output does not include AccountContact

But I haven't been able to reproduce. :( I have reproduced.

(Edit: using var_dump() to inspect seems problematic because it truncates output. Changed to use var_export().)

@jitendrapurohit
Copy link
Contributor Author

Thanks @totten

Worth seeing if we get all entityTypes defined by hooks of accountsync extension? Or if we just keep a print statement in this hook and see if it fires from cron.php (when it loads all entityTypes from AllCoreTables.php)?

@totten
Copy link
Member

totten commented Jul 21, 2017

OK, I get it now. IMHO, the problem is really with CRM_Utils_Hook_Joomla bailing out. It makes sense to skip stuff like $app->triggerEvent(), but we should fire the extension hooks (commonInvoke).

Why? The issue affects all "boot-critical" hooks fired by Civi extensions -- i.e. hook_civicrm_entityTypes, hook_civicrm_container, hook_civicrm_config. The current patch in 10692 is narrowly tailored to clear cache for entityTypes, but there's no cache you can clear that will retroactively fixup the container. (Even if we put aside performance concerns and tried... the container is written to CachedCiviContainer.*.php, and the class-definition becomes immutable within the page-request.)

I think this patch would have the effect of aligning Joomla behavior with Drupal/WordPress behavior:

diff --git a/CRM/Utils/Hook/Joomla.php b/CRM/Utils/Hook/Joomla.php
index fd1793c..4e24264 100644
--- a/CRM/Utils/Hook/Joomla.php
+++ b/CRM/Utils/Hook/Joomla.php
@@ -123,6 +123,12 @@ class CRM_Utils_Hook_Joomla extends CRM_Utils_Hook {
       }
       return $result;
     }
+    else {
+      // CRM-20904: We should still call Civi extension hooks even if Joomla isn't online yet.
+      return $this->commonInvoke($numParams,
+        $arg1, $arg2, $arg3, $arg4, $arg5, $arg6,
+        $fnSuffix, 'joomla');
+    }
   }
 
 }

@jitendrapurohit
Copy link
Contributor Author

yes, thought about this but proceeded with the simple/safe approach of updating the static variable self::$entityTypes which was not filled with extension DAOs. I'll test this on the affected site and update here. Thanks @totten

@jitendrapurohit
Copy link
Contributor Author

Tested the above diff on the affected site and it worked well in calling the extension hooks. I've updated the PR with the same. Thanks!

@eileenmcnaughton
Copy link
Contributor

@totten have your issues on this been addressed?

@totten
Copy link
Member

totten commented Aug 30, 2017

Thanks for reviving!

I'd prefer to merge with just 3c27459 (not 88d3c0d). To my reading, 88d3c0d became unnecessary and makes the semantics less consistent across UF's.

@jitendrapurohit
Copy link
Contributor Author

whoops, second commit was a partial update of this PR - thought I removed the original changes. I've updated it now.

Thanks @eileenmcnaughton @totten

@eileenmcnaughton
Copy link
Contributor

@totten looks like this has ben adjusted to meet your requirements - can you recheck & hopefully merge

@eileenmcnaughton
Copy link
Contributor

I'm merging this as it seems fairly clear that the eventual patch was suggested by @totten (the reviewer) and tested by @jitendrapurohit & used to replace the original. I think Jitendra becomes the tester & - it's too confusing - but I think the final result represents a code collaboration & has been tested

@eileenmcnaughton eileenmcnaughton merged commit ec75179 into civicrm:master Jan 16, 2018
@jitendrapurohit jitendrapurohit deleted the CRM-20904 branch January 16, 2018 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants