CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Detecting CiviCRM version in code
Pages: [1]

Author Topic: Detecting CiviCRM version in code  (Read 2151 times)

torenware

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 4
Detecting CiviCRM version in code
May 22, 2008, 06:29:06 pm
I'm updating some Drupal libraries that were written for CiviCRM 1.x, and would like to update them so that they behave correctly under both CiviCRM 1.x and CiviCRM 2.x, so I'm not in the business of creating multiple versions.

To do this, it would help if I knew which version of CiviCRM I was running.  Then, I can wrap missing function calls when I'm calling 2.x or do any additional initialization (like require needed files).

What's the best way to do this?  Also, if there's some sample code posted for this on the wiki, could someone please point me to it?

 

barrylb

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
Re: Detecting CiviCRM version in code
May 22, 2008, 09:43:11 pm
The only place the version number seems to appear is in a file version.tpl - in the templates/CRM/common folder. You could retrieve it from there.

torenware

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 4
Re: Detecting CiviCRM version in code
May 22, 2008, 11:01:17 pm
No, that you definitely can't use -- the build process creates that file, so it can contain practically anything, depending upon what you put in your config files.

I'm looking either for an API function, or a test (say, function_exists('only_in_v2') kind of thing.

dharmatech

  • I post frequently
  • ***
  • Posts: 280
  • Karma: 53
    • dharmatech.org
Re: Detecting CiviCRM version in code
May 23, 2008, 10:53:51 am
In uc_civicrm, I did this:

  // Find out whether this version of CiviCRM keeps activity history
  // in the civicrm_activity_history table
  $activity_history = @include_once 'CRM/Core/BAO/History.php';
  if ( $activity_history ) {

    // Add this purchase to the civicrm_activity_history table
    $params = array('entity_table' => 'civicrm_contact',
                    'entity_id' => $cid,
                    'activity_type' => t('Purchase'),
                    'module' => 'Ubercart',
                    'activity_id' => $order_id,
                    'activity_summary' => t('Purchase'),
                    'activity_date' => date('YmdHis'));
    $ids = array();
    CRM_Core_BAO_History::create($params, $ids);
  } else {

    // Add this purchase to the civicrm_activity table
    require_once 'CRM/Activity/BAO/Activity.php';
    $params = array('subject'           => 'Purchase',
                    'source_contact_id' => $cid,
                    'duration_hours'    => 0,
                    'duration_minutes'  => 0,
                    'activity_type_id'  => $option_value,
                    'status_id'         => 2, // Completed
                    'details'           => 'order details here',
                    'activity_date_time'=> date('YmdHis') );
    CRM_Activity_BAO_Activity::create($params);
  }
http://dharmatech.org
oss@dharmatech.org
801.541.8671

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Detecting CiviCRM version in code
May 23, 2008, 05:40:51 pm
A version column has been added to civicrm_domain as of v2.0 which should give you the major version (2.0, 2.1 etc.). This column does not exist prior to 2.0 - so a test for that should be reliable. HTH
Protect your investment in CiviCRM by  becoming a Member!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Detecting CiviCRM version in code
May 24, 2008, 09:52:13 pm

There is also a function from 2.0 onwards: CRM_Utils_System::version( );

which gives you the version of the code that is being run

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Detecting CiviCRM version in code

This forum was archived on 2017-11-26.