Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Right after creating a new CiviHR site (with any of the build methods available), CiviCRM would tell us that there were some extension updates available. We run all of an extension upgraders during the installation, so it's not possible for any of them to have any pending updates.
After some investigation, it turns out that this was caused by the extension schema version not being saved to the database after the installation is complete. Without that, Civi doesn't know that the extension is already in the latest version and tells the user that they should update it.
Before
Users would be informed about pending extension updates right after a CiviHR installation.
After
Users will not informed about pending extension updates right after a CiviHR installation.
Technical Details
When developing a CiviCRM extension, it's common to use the
civix
tool to automatically generated some skeleton code for us. Among this, is the default implementation of some hooks, which is kept in a file named<extension>.civix.php
and the Base Upgrader class, which is kept inCRM/<ExtensionNamespace>/Upgrader/Base.php
.This tool is constantly updated and some of these updates change the contents and format of these files. Unfortunately, the files need to be updated manually once a new version of
civix
is out (by calling the generate command again) and for this reason, it is easy for files to get outdated.Outdated files are what caused the issue this PR fixes. On totten/civix#79, they changed the way the schema version is saved to the database after an extension is installed. This is how the installation cycle would work before that PR:
hook_civicrm_install()
1.1 The implementation of that hook in
<extenstion>.php
would call the implementation inside the<extension>.civix.php
file1.2 The implementation in
<extension>.civix.php
would call theonInstall()
method in the Base Upgrader class1.3 The
onInstall()
method would call theinstall()
method1.4 After the
install()
finishes the installation,onInstall()
would save the max revision number (the schema version) to the databasehook_civicrm_postInstall()
2.1 Nothing would happen, as the extension didn't implement the
postInstall()
hookAnd this is how it works after that PR:
hook_civicrm_install()
1.1 The implementation of that hook in
<extenstion>.php
would call the implementation inside the<extension>.civix.php
file1.2 The implementation in
<extension>.civix.php
would call theonInstall()
method in the Base Upgrader class1.3 The
onInstall()
method would call theinstall()
methodhook_civicrm_postInstall()
2.1 The implementation of that hook in
<extenstion>.php
would call the implementation inside the<extension>.civix.php
file2.2 The implementation in
<extension>.civix.php
would call theonPostInstall()
method in the Base Upgrader class2.3 The
onPostInstall()
saves the schema version to the databaseNote that now the responsibility of saving the schema version to the database belongs to the
onPostInstall()
method. Also, note that in order for this to work, it is expected that extensions implement thehook_civicrm_postInstall()
hook. Part of the changes introduced in totten/civix#79 is exactly about making sure that new extensions created with it would implement that by default. Unfortunately, some CiviHR extension were created before that and the automatically generated files have not been updated ever since. This PR updates these files and make sure that they implementhook_civicrm_postInstall()
and call theonPostInstall()
method in the Base Upgrader.Comments
Because of this problem, running
drush cvapi Extension.upgrade
on a CiviHR site for the first time after an installation, would run all the upgraders again and result in some duplicated data. A separate PR will be created later to remove this duplicated data from existing sites.Only these 3 extension have been updated because they were in a unique scenario where the Base Upgrader was created after totten/civix#79, but the
<extension>.php
file was created before that. So the Base Upgrader already contained the change where the schema was saved in theonPostInstall()
method, but there was no hook calling it. The other extensions still have the old Upgrader which saves the schema version in theonInstall()
method. So, other than having some outdated files, everything is good there. In order to reduce the number of changes in this PR (and the risk of breaking something with these changes) I decided to keep them as is.