You are here

function optimizely_install in Optimizely 7.2

Same name and namespace in other branches
  1. 8.3 optimizely.install \optimizely_install()
  2. 8 optimizely.install \optimizely_install()
  3. 8.0 optimizely.install \optimizely_install()
  4. 7.3 optimizely.install \optimizely_install()

Implements hook_install().

Included in the process of adding a optimizely database table is the creation of a default project entry in the table. The default entry is used to add an initial javascript file (snippit) on a site wide basis. The Optimizely account ID will need to be entered in the account setup page to complete the default entry. The Optimizely site uses the account ID to generate the basic javascipt file to be included on the site. Once additional projects / experiments are created on the Optimizely site additional project entries can be added to load the additional javascript files on specific site paths. Selective loading of the Optimizely javascipt file helps in page load times and the amount of custom Optimizely javascript in each Javascript include file.

File

./optimizely.install, line 93
Install, update and uninstall functions for the Optimizely module

Code

function optimizely_install() {
  drupal_set_message(st('Optimizely database table has been created.'), 'status');

  // Add default entry - check to see if entry already exsists
  $default_entry_exists = (bool) db_query("\n\t  SELECT\n\t\t  project_title\n\t\tFROM\n\t\t  {optimizely}\n\t\tWHERE\n\t\t  oid = 1\n\t\t")
    ->fetchField();
  if ($default_entry_exists == TRUE) {
    drupal_set_message(st("A default entry found in the optimizely database table. Something funky is going on but it's not the end of the world."), 'warning');
  }
  else {

    // Create default entry
    $default_entry_created = (bool) db_insert('optimizely')
      ->fields(array(
      'project_title' => 'Default',
      'include' => 1,
      'enabled' => 0,
      'path' => serialize(array(
        '*',
      )),
      'project_code' => 0,
    ))
      ->execute();

    // Inform the administrator that a default snippet entry has been made.
    // Acount ID and access permisisons need to be configured
    if ($default_entry_created == TRUE) {
      drupal_set_message(st('A default project / experiment entry has been created. Next, enter your' . ' ' . l(st('Optimizely account ID'), 'admin/config/system/optimizely/settings') . '. There\'s also an ' . l(st('optimizely permission'), 'admin/people/permissions', array(
        'fragment' => 'module-optimizely',
      )) . ' ' . st('that can be set for specific roles to access the administration functionality.')), 'status');
    }
    else {
      drupal_set_message(st('An error was encountred added the default project entry for the Optimizely module.'), 'error');
    }
  }
}