Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation - Support "activate first" w/setup UI #606

Merged
merged 5 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 21 additions & 24 deletions civicrm.install
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ function civicrm_enable() {
menu_link_save($options);

if (!civicrm_initialize()) {
$installLink = url('civicrm/setup');
$message = t('<p class="error"><strong>CiviCRM is almost ready.</strong> You must <a href="@url">configure CiviCRM</a> for it to work.</p>', [
'@url' => $installLink,
]);
drupal_set_message($message);
return;
}

Expand Down Expand Up @@ -66,32 +71,24 @@ function civicrm_uninstall() {
}

function civicrm_requirements($phase) {
global $base_url;
$civicrm_path = drupal_get_path('module', 'civicrm');

//remove the last occurrence of 'drupal' from path
$pos = strrpos($civicrm_path, 'drupal');

if ($pos !== FALSE) {
$civicrm_path = substr_replace($civicrm_path, '', $pos, strlen($civicrm_path));
}

$url = $base_url . '/' . $civicrm_path . 'install/index.php';

$settings = glob('sites/*/civicrm.settings.php');
$problems = array();
$requirements = array();
$t = get_t();
if (empty($settings) && $phase == 'install') {
$problems[] = array(
'title' => $t('CiviCRM settings does not exist'),
'value' =>
$t('CiviCRM settings file does not exist. It should be created by CiviCRM <a href="!link">install</a>',
array('!link' => $url)),
'severity' => REQUIREMENT_ERROR,
);
switch ($phase) {
case 'runtime':
if (!civicrm_initialize()) {
$installLink = url('civicrm/setup');
$requirements['civicrm'] = array(
'title' => $t("CiviCRM"),
'severity' => REQUIREMENT_ERROR,
'value' => $t('<p class="error"><strong>CiviCRM is almost ready.</strong> You must <a href="@url">configure CiviCRM</a> for it to work.</p>', [
'@url' => $installLink,
]),
);
return $requirements;
}
break;
}

return $problems;
return $requirements;
}

/**
Expand Down
58 changes: 40 additions & 18 deletions civicrm.module
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function civicrm_permission() {
*/
function civicrm_block_info() {
if (!civicrm_initialize()) {
return;
return [];
}
$block = CRM_Core_Block::getInfo();
return $block;
Expand All @@ -111,10 +111,6 @@ function civicrm_block_view($delta = '0') {
* Implements hook_menu().
*/
function civicrm_menu() {
if (!civicrm_initialize()) {
return;
}

return array(
'civicrm' => array(
'title' => 'CiviCRM',
Expand All @@ -123,6 +119,14 @@ function civicrm_menu() {
'type' => 4,
'weight' => 0,
),
'civicrm/setup' => array(
'title' => 'CiviCRM Setup',
'access callback' => TRUE,
'page callback' => 'civicrm_setup_page',
'file' => 'civicrm.setup.inc',
'type' => 4,
'weight' => 0,
),
// administration section for civicrm integration modules.
'admin/config/civicrm' => array(
'title' => 'CiviCRM',
Expand Down Expand Up @@ -197,13 +201,12 @@ function civicrm_initialize() {
)
);

if (!include_once $settingsFile) {
$loadedSettings = (bool) @include_once $settingsFile;
if (!$loadedSettings) {
$failure = TRUE;
$message = t("<strong><p class='error'> Oops! - The CiviCRM settings file (civicrm.settings.php) was not found in the expected location (!1) </p><p class='error'> !2 </p></strong>", array(
'!1' => $settingsFile,
'!2' => $errorMsgAdd,
));
drupal_set_message($message);
if (user_access('administer modules')) {

}
return FALSE;
}

Expand Down Expand Up @@ -386,7 +389,9 @@ function civicrm_invoke() {

// make sure the system is initialized
if (!civicrm_initialize()) {
return drupal_not_found();
require_once __DIR__ . '/civicrm.setup.inc';
// NOTE: The setup page has a built-in authorization check.
return civicrm_setup_page();
}

civicrm_cache_disable();
Expand Down Expand Up @@ -487,6 +492,10 @@ function _civicrm_categories_access($profile_id) {
* Translating profile menu title dynamicaly to overide caching
*/
function civicrm_menu_alter(&$items) {
if (!civicrm_initialize()) {
return;
}

$categories = civicrm_user_categories();
foreach ($categories as $cat) {
$path = 'user/%user_category/edit/' . $cat['name'];
Expand Down Expand Up @@ -887,7 +896,9 @@ function civicrm_user_admin_permissions_submit($form, &$form_state) {
if ($rid === FALSE) {
return;
}
civicrm_initialize();
if (!civicrm_initialize()) {
return;
}
$roles = user_roles();
$permissions = array_filter($form_state['values'][$rid]);
$warning_permissions = CRM_Core_Permission::validateForPermissionWarnings($permissions);
Expand Down Expand Up @@ -1025,7 +1036,10 @@ function _civicrm_filter_tips($filter, $format, $long = FALSE) {
* @return bool|mixed|string
*/
function _civicrm_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) {
civicrm_initialize();
if (!civicrm_initialize()) {
return t('(Content unavailable. CiviCRM is not installed.)');
}

$config = CRM_Core_Config::singleton();
$smarty = CRM_Core_Smarty::singleton();
// as this file is not a class (not sure why) we need the require once
Expand Down Expand Up @@ -1218,31 +1232,39 @@ function civicrm_reviews() {
* Implements hook_modules_installed().
*/
function civicrm_modules_installed($modules) {
civicrm_initialize();
if (!civicrm_initialize()) {
return;
}
CRM_Core_Invoke::rebuildMenuAndCaches(TRUE);
}

/**
* Implements hook_modules_enabled().
*/
function civicrm_modules_enabled($modules) {
civicrm_initialize();
if (!civicrm_initialize()) {
return;
}
CRM_Core_Invoke::rebuildMenuAndCaches(TRUE);
}

/**
* Implements hook_modules_disabled().
*/
function civicrm_modules_disabled($modules) {
civicrm_initialize();
if (!civicrm_initialize()) {
return;
}
CRM_Core_Invoke::rebuildMenuAndCaches(TRUE);
}

/**
* Implements hook_modules_uninstalled().
*/
function civicrm_modules_uninstalled($modules) {
civicrm_initialize();
if (!civicrm_initialize()) {
return;
}
CRM_Core_Invoke::rebuildMenuAndCaches(TRUE);
}

Expand Down
56 changes: 56 additions & 0 deletions civicrm.setup.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* (Page callback)
*
* @return string
*/
function civicrm_setup_page() {
$coreUrl = dirname(file_create_url(drupal_get_path('module', 'civicrm')));
$corePath = dirname(__DIR__);
$classLoader = implode(DIRECTORY_SEPARATOR, [$corePath, 'CRM', 'Core', 'ClassLoader.php']);

if (file_exists($classLoader)) {
require_once $classLoader;
CRM_Core_ClassLoader::singleton()->register();
\Civi\Setup::assertProtocolCompatibility(1.0);
\Civi\Setup::init([
// This is just enough information to get going. Drupal.civi-setup.php does more scanning.
'cms' => 'Drupal',
'srcPath' => $corePath,
]);
$ctrl = \Civi\Setup::instance()->createController()->getCtrl();
$ctrl->setUrls(array(
'ctrl' => url('civicrm'),
'res' => $coreUrl . '/setup/res/',
'jquery.js' => $coreUrl . '/bower_components/jquery/dist/jquery.min.js',
'font-awesome.css' => $coreUrl . '/bower_components/font-awesome/css/font-awesome.min.css',
// Not used? 'finished' => url('civicrm/dashboard', ['query' => ['reset' => 1],]),
));
\Civi\Setup\BasicRunner::run($ctrl);
exit();
}
else {
drupal_set_message(t('Cannot perform setup for CiviCRM. The file "@file" is missing.', [
'@file' => $classLoader,
]), 'error');
return '';
}
}

///**
// * This is a draft alternative to BasicRunner. It would theoretically enable
// * Drupal's chrome. However, the styling is a little wonky, and you wind up
// * with two <HTML>s. Maybe worth fixing someday - but not now.
// *
// * @param \Civi\Setup\UI\SetupControllerInterface $ctrl
// * @return mixed
// */
//function _civicrm_setup_runCtrl($ctrl) {
// $method = $_SERVER['REQUEST_METHOD'];
// list ($headers, $body) = $ctrl->run($method, ($method === 'GET' ? $_GET : $_POST));
// foreach ($headers as $k => $v) {
// drupal_add_http_header($k, $v, TRUE);
// }
// return $body;
//}
2 changes: 1 addition & 1 deletion civicrm_user.inc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function civicrm_user_delete($account) {
*/
function civicrm_user_categories() {
if (!civicrm_initialize()) {
return;
return [];
}
$urlParts = explode('/', CRM_Utils_Array::value('q', $_GET, array()));

Expand Down
35 changes: 28 additions & 7 deletions drush/civicrm.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,10 @@ function civicrm_drush_help($section) {
* Implementation of command 'civicrm-ext-list'
*/
function drush_civicrm_ext_list() {
civicrm_initialize();
if (!civicrm_initialize()) {
drush_print(dt("CiviCRM is not setup."));
return;
}
try {
$result = civicrm_api3('extension', 'get', array(
'options' => array(
Expand Down Expand Up @@ -570,7 +573,10 @@ function drush_civicrm_ext_list() {
* Implementation of command 'civicrm-ext-install'
*/
function drush_civicrm_ext_install($extension_name) {
civicrm_initialize();
if (!civicrm_initialize()) {
drush_print(dt("CiviCRM is not setup."));
return;
}
try {
$result = civicrm_api('extension', 'install', array('key' => $extension_name, 'version' => 3));
if ($result['values'] && $result['values'] == 1) {
Expand All @@ -593,7 +599,10 @@ function drush_civicrm_ext_install($extension_name) {
* Implementation of command 'civicrm-ext-disable'
*/
function drush_civicrm_ext_disable($extension_name) {
civicrm_initialize();
if (!civicrm_initialize()) {
drush_print(dt("CiviCRM is not setup."));
return;
}
try {
$result = civicrm_api('extension', 'disable', array('key' => $extension_name, 'version' => 3));
if ($result['values'] && $result['values'] == 1) {
Expand All @@ -616,7 +625,10 @@ function drush_civicrm_ext_disable($extension_name) {
* Implementation of command 'civicrm-ext-uninstall'
*/
function drush_civicrm_ext_uninstall($extension_name) {
civicrm_initialize();
if (!civicrm_initialize()) {
drush_print(dt("CiviCRM is not setup."));
return;
}
try {
$result = civicrm_api('extension', 'uninstall', array('key' => $extension_name, 'version' => 3));
if ($result['values'] && $result['values'] == 1) {
Expand Down Expand Up @@ -1538,7 +1550,10 @@ function drush_civicrm_api() {
break;
}

civicrm_initialize();
if (!civicrm_initialize()) {
drush_print(dt("CiviCRM is not setup."));
return;
}

global $user;
CRM_Core_BAO_UFMatch::synchronize($user, FALSE, 'Drupal',
Expand Down Expand Up @@ -1569,7 +1584,10 @@ function drush_civicrm_api() {
* Implementation of command 'civicrm-sync-users-contacts'
*/
function drush_civicrm_sync_users_contacts() {
civicrm_initialize();
if (!civicrm_initialize()) {
drush_print(dt("CiviCRM is not setup."));
return;
}
$result = CRM_Utils_System::synchronizeUsers();
$status = ts('Checked one user record.',
array(
Expand Down Expand Up @@ -1598,7 +1616,10 @@ function drush_civicrm_sync_users_contacts() {

function drush_civicrm_sql_rebuild_triggers() {
$table = drush_get_option('table', NULL);
civicrm_initialize();
if (!civicrm_initialize()) {
drush_print(dt("CiviCRM is not setup."));
return;
}
$triggerService = Civi::service('sql_triggers');
$triggerService->rebuild($table, TRUE);
if (\Civi::settings()->get('logging_no_trigger_permission')) {
Expand Down