7

Within a CiviCRM extension, what's the best way to determine the current CiviCRM version in versions 4.6.x and above?

2 Answers 2

8

Agree with Chris that System.get is a great API for inspecting the system -- with a trade-off of breadth vs speed.

If you need something more performant, use CRM_Utils_System::version(), e.g.

$ cv ev 'return CRM_Utils_System::version();'
"4.7.16"
0
7

I'd use System.get API call. (source)

In the return values, there's a value for version which corresponds to the value in civicrm-version.php

$ cv api System.get name=version
{
    "is_error": 0,
    "version": 3,
    "count": 1,
    "id": 0,
    "values": [
        {
            "version": "4.6.20.0",
            "uf": "Drupal",
            "php": {
            // lots more info ...

Only worry about this might be how heavy that API call is - since I see data there from OS etc, it might not be suitable for calling frequently if rebuilding the data each time. There seems to be a bit of overhead to this API call (~0.07s per call in a randomly picked test environment), so for frequent use you'd want something lighter.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.