acquia_lift_profiles.install in Acquia Lift Connector 7
Same filename and directory in other branches
Acquia Lift Profiles - Installation file.
File
acquia_lift_profiles/acquia_lift_profiles.installView source
<?php
/**
* @file Acquia Lift Profiles - Installation file.
*/
/**
* Implements hook_install().
*/
function acquia_lift_profiles_install() {
$menu_name = 'acquia-lift-controls';
// Create a link for accessing the Profiles web admin.
$item = array(
'link_title' => 'Acquia Lift Web Admin',
'link_path' => 'http://lift.acquia.com',
'menu_name' => $menu_name,
'options' => array(
'attributes' => array(
'class' => array(
'visitor-actions-ui-ignore',
'acquia-lift-menu-link',
'acquia-lift-web-admin',
),
'target' => '_blank',
),
'alter' => TRUE,
'html' => FALSE,
),
'expanded' => 1,
'weight' => 99,
);
menu_link_save($item);
menu_rebuild();
}
/**
* Implements hook_enable().
*/
function acquia_lift_profiles_enable() {
// Clear the action subscriber cache.
visitor_actions_clear_subscribers();
// Unhide the menu link if it's hidden.
$item = _acquia_lift_profiles_get_menu_link();
if (!empty($item) && $item['hidden'] == 1) {
$item['hidden'] = 0;
menu_link_save($item);
// Update the menu router information.
menu_rebuild();
}
}
/**
* Implements hook_disable().
*/
function acquia_lift_profiles_disable() {
// Clear the action subscriber cache.
visitor_actions_clear_subscribers();
// Disable the Profiles web admin link.
$item = _acquia_lift_profiles_get_menu_link();
if (!empty($item) && $item['hidden'] == 0) {
$item['hidden'] = 1;
menu_link_save($item);
menu_rebuild();
}
}
/**
* Implements hook_uninstall().
*/
function acquia_lift_profiles_uninstall() {
variable_del('acquia_lift_profiles_account_name');
variable_del('acquia_lift_profiles_site_name');
variable_del('acquia_lift_profiles_api_url');
variable_del('acquia_lift_profiles_access_key');
variable_del('acquia_lift_profiles_secret_key');
variable_del('acquia_lift_profiles_capture_identity');
variable_del('acquia_lift_profiles_js_path');
variable_del('acquia_lift_profiles_field_mappings');
variable_del('acquia_lift_profiles_tracked_actions');
variable_del('acquia_lift_profiles_udf_mappings');
variable_del('acquia_lift_profiles_identity_param');
variable_del('acquia_lift_profiles_identity_type_param');
variable_del('acquia_lift_profiles_default_identity_type');
// Delete the menu link
$item = _acquia_lift_profiles_get_menu_link();
if (!empty($item)) {
menu_link_delete($item['mlid']);
}
}
/**
* Retrieves the row corresponding to the menu link item for the web admin.
*/
function _acquia_lift_profiles_get_menu_link() {
$item = db_select('menu_links', 'ml')
->fields('ml')
->condition('module', 'menu')
->condition('menu_name', 'acquia-lift-controls')
->condition('link_path', 'http://lift.acquia.com')
->execute()
->fetchAssoc();
if (!empty($item['options'])) {
$item['options'] = unserialize($item['options']);
}
return $item;
}
/**
* Allow Acquia Lift Web Admin link to be altered.
*/
function acquia_lift_profiles_update_7001() {
$item = _acquia_lift_profiles_get_menu_link();
if (!empty($item)) {
$item['options']['alter'] = TRUE;
menu_link_save($item);
// Update the menu router information.
menu_rebuild();
}
}
/**
* Ensure all defined visitor actions are sync'd to Lift Web.
*/
function acquia_lift_profiles_update_7002(&$sandbox) {
drupal_load('module', 'acquia_lift_profiles');
// Nothing to be done if the module hasn't been configured yet.
if (!acquia_lift_profiles_is_configured(TRUE)) {
return;
}
// We need actions defined in code as well as those in the db.
$actions = module_invoke_all('visitor_actions_info');
$result = db_query('SELECT machine_name, label FROM {visitor_actions_actions}');
foreach ($result as $row) {
$actions[$row->machine_name] = array(
'machine_name' => $row->machine_name,
'label' => $row->label,
);
}
if (empty($actions)) {
return;
}
// This update hook could get run when this module and all its dependencies
// are disabled, so we need to explicitly load all the files we need.
module_load_include('inc', 'personalize', 'includes/personalize.classes');
module_load_include('inc', 'acquia_lift', 'includes/acquia_lift.classes');
module_load_include('inc', 'acquia_lift_profiles', 'includes/acquia_lift_profiles.classes');
$action_names = array_keys($actions);
if (!isset($sandbox['progress'])) {
// The count of actions processed so far.
$sandbox['progress'] = 0;
// Total actions that must be sync'd.
$sandbox['max'] = count($actions);
// Last action processed.
$sandbox['current_action'] = 0;
}
// Process each action separately
$action_name = $action_names[$sandbox['current_action']];
$action = $actions[$action_name];
$errors = array();
acquia_lift_profiles_put_action($action['action_name'], $action['label'], $errors);
// Update our progress information.
$sandbox['progress']++;
$sandbox['current_action']++;
// Set the "finished" status, to tell batch engine whether this function
// needs to run again. If you set a float, this will indicate the progress
// of the batch so the progress bar will update.
$sandbox['#finished'] = $sandbox['progress'] >= $sandbox['max'] ? TRUE : $sandbox['progress'] / $sandbox['max'];
if ($sandbox['#finished']) {
return t('All actions were synchronized to Lift Web');
}
}
/**
* Convert existing vocabulary mappings to use taxonomy context module.
*/
function acquia_lift_profiles_update_7003() {
// 1) Enable the personalize taxonomy context module.
$result = module_enable(array(
'personalize_taxonomy_context',
));
if (empty($result)) {
throw new DrupalUpdateException('There was a problem enabling "personalize_taxonomy_context" module. Please ensure you have "personalize" module version 7.x-1.0-rc11 or higher, and then try updating again.');
}
// 2) Convert existing mappings (if not already). Example:
//
// * Before migration:
// $acquia_lift_profiles_vocabulary_mappings = array (
// 'content_section' => '2',
// 'content_keywords' => '',
// 'persona' => '4',
// )
// * After migration:
// $acquia_lift_profiles_field_mappings = array (
// 'content_section' => 'taxonomy_context__people',
// 'persona' => 'taxonomy_context__country',
// )
$vocabulary_mappings = variable_get('acquia_lift_profiles_vocabulary_mappings', array());
$field_mappings = array();
foreach ($vocabulary_mappings as $type => $vocabulary_mapping) {
if (empty($vocabulary_mapping) || !is_numeric($vocabulary_mapping)) {
continue;
}
$vocabulary = taxonomy_vocabulary_load($vocabulary_mapping);
$field_mappings[$type] = 'taxonomy_context' . PERSONALIZE_TARGETING_ADMIN_SEPARATOR . $vocabulary->machine_name;
}
if (!empty($field_mappings)) {
variable_set('acquia_lift_profiles_field_mappings', $field_mappings);
}
variable_del('acquia_lift_profiles_vocabulary_mappings');
}
Functions
Name | Description |
---|---|
acquia_lift_profiles_disable | Implements hook_disable(). |
acquia_lift_profiles_enable | Implements hook_enable(). |
acquia_lift_profiles_install | Implements hook_install(). |
acquia_lift_profiles_uninstall | Implements hook_uninstall(). |
acquia_lift_profiles_update_7001 | Allow Acquia Lift Web Admin link to be altered. |
acquia_lift_profiles_update_7002 | Ensure all defined visitor actions are sync'd to Lift Web. |
acquia_lift_profiles_update_7003 | Convert existing vocabulary mappings to use taxonomy context module. |
_acquia_lift_profiles_get_menu_link | Retrieves the row corresponding to the menu link item for the web admin. |