function mailchimp_lists_install in Mailchimp 7.2
Implements hook_install().
File
- modules/
mailchimp_lists/ mailchimp_lists.install, line 84 - Install, update and uninstall functions for the mailchimp_lists module.
Code
function mailchimp_lists_install() {
// Convert old lists if they exist:
$old_lists = variable_get('mailchimp_lists', array());
if (!empty($old_lists)) {
$cron = variable_get('mailchimp_cron', FALSE);
$register = variable_get('mailchimp_user_register', FALSE);
$user = variable_get('mailchimp_user_edit', FALSE);
$intgroups = variable_get('mailchimp_interest_groups_user_forms', FALSE);
foreach ($old_lists as $id => $old_list) {
$list = new stdClass();
$list->mc_list_id = $id;
$list->label = substr($old_list->label, 0, 32);
$list->name = substr($old_list->name, 0, 32);
$list->description = $old_list->description;
$list->list_type = $old_list->list_type == 'required' ? MAILCHIMP_LISTTYPE_REQUIRED : MAILCHIMP_LISTTYPE_OPTIONAL;
$list->settings = array(
'roles' => $old_list->roles,
'mergefields' => isset($old_list->mergevars) ? $old_list->mergevars : NULL,
'show_register_form' => $register,
'show_account_form' => $user,
'include_interest_groups' => $intgroups,
'cron' => $cron,
'webhooks' => FALSE,
);
$t = get_t();
if ($ret = mailchimp_lists_save($list)) {
drupal_set_message($t('List @name has been converted.', array(
'@name' => $list->label,
)));
}
else {
drupal_set_message($t('There has been an error converting list @name.', array(
'@name' => $list->label,
)), 'error');
}
}
}
// Now delete old variables:
variable_del('mailchimp_cron');
variable_del('mailchimp_interest_groups_user_forms');
variable_del('mailchimp_lists');
variable_del('mailchimp_user_edit');
variable_del('mailchimp_user_register');
}