You are here

function apps_app_enable in Apps 7

Callback for the enable action

Enables the app and got to config page if it exists

1 string reference to 'apps_app_enable'
apps_menu in ./apps.module
Implements hook_menu().

File

./apps.pages.inc, line 320
The page callbacks for the Apps module.

Code

function apps_app_enable($app) {
  $token_name = 'enable-' . $app['machine_name'];
  if ($confirm_form = apps_display_confirm_form(t('Are you sure you want to enable @name?', array(
    '@name' => $app['name'],
  )), $token_name)) {
    return $confirm_form;
  }
  $next = apps_app_page_path($app);
  if ($app['status'] === APPS_DISABLED) {
    $success = module_enable(array(
      $app['machine_name'],
    ), TRUE);
    if ($success) {
      drupal_flush_all_caches();
      drupal_set_message(t("Enabled @name app", array(
        '@name' => $app['name'],
      )));
      if (!$app['disabled'] && ($cb = apps_app_callback($app, "post install callback"))) {
        $cb($app);
      }
      if (apps_app_access('administer apps', $app, 'configure')) {
        $next = apps_app_page_path($app, 'configure');
      }
    }
    else {
      drupal_set_message(t("@name App Not Enabled", array(
        '@name' => $app['name'],
      )));
    }
  }
  elseif ($app['status'] === APPS_ENABLED) {
    drupal_set_message(t("@name App already Enabled", array(
      '@name' => $app['name'],
    )), 'warning');
  }
  elseif ($app['status'] === APPS_INCOMPATIBLE) {
    $incompatible = array();
    foreach ($app['dependencies'] as $depedency_name => $depedency) {
      if ($depedency['incompatible']) {
        $incompatible[] = $depedency_name;
      }
    }
    drupal_set_message(t("@name App not compatible (incompatible dependencies: @dependencies)", array(
      '@name' => $app['name'],
      '@dependencies' => implode(', ', $incompatible),
    )), 'error');
  }
  elseif ($app['status'] === APPS_INSTALLABLE) {
    $missing = array();
    foreach ($app['dependencies'] as $depedency_name => $depedency) {
      if (empty($depedency['installed'])) {
        $missing[] = $depedency_name;
      }
    }
    drupal_set_message(t("@name App has missing depedencies (missing depedencies: @dependencies)", array(
      '@name' => $app['name'],
      '@dependencies' => implode(', ', $missing),
    )), 'error');
  }
  unset($_SESSION['apps_install_next']);
  drupal_goto($next);
}