Skip to content
Draft
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
2 changes: 1 addition & 1 deletion civicrm.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: CiviCRM Core
type: module
description: 'Constituent Relationship Management system. Allows sites to manage contacts, relationships and groups, and track contact activities, contributions, memberships and events.'
package: CiviCRM
core_version_requirement: ^9 || ^10 || ^11
core_version_requirement: ^9 || ^10 || ^11 || ^12
75 changes: 0 additions & 75 deletions civicrm.install
Original file line number Diff line number Diff line change
Expand Up @@ -43,81 +43,6 @@ function civicrm_uninstall() {
$setup->uninstallDatabase();
}

/**
* Implements hook_requirements().
*/
function civicrm_requirements($phase) {
$requirements = [];

$civicrm_base = _civicrm_find_civicrm();

// Introduced in 11.2, and then compatibility layer removed in 11.3, so we
// have to support both.
if (class_exists('\Drupal\Core\Extension\Requirement\RequirementSeverity')) {
$severityMap = [
'info' => \Drupal\Core\Extension\Requirement\RequirementSeverity::OK,
'warning' => \Drupal\Core\Extension\Requirement\RequirementSeverity::Warning,
'error' => \Drupal\Core\Extension\Requirement\RequirementSeverity::Error,
];
}
else {
$severityMap = [
'info' => REQUIREMENT_OK,
'warning' => REQUIREMENT_WARNING,
'error' => REQUIREMENT_ERROR,
];
}

if ($civicrm_base) {
$requirements['civicrm.location'] = [
'title' => 'CiviCRM location',
'severity' => $severityMap['info'],
'description' => 'CiviCRM core directory',
];
}
else {
$requirements['civicrm.location'] = [
'title' => 'CiviCRM location',
'severity' => $severityMap['error'],
'description' => 'CiviCRM must be installed via composer.',
];
return $requirements;
}

/** @var \Civi\Setup $setup */
$setup = _civicrm_setup();
if ($phase === 'install' && !$setup->checkAuthorized()->isAuthorized()) {
$requirements['civicrm.checkAuthorized'] = [
'title' => 'CiviCRM Installation Not Authorized',
'description' => 'The current user does not have sufficient permissions to perform installation.',
'severity' => $severityMap['warning'],
];
return $requirements;
}

$sections = [
'system' => 'CiviCRM: System',
'database' => 'CiviCRM: Database',
'other' => 'CiviCRM: Other',
];

if ($phase !== 'runtime') {
foreach ($setup->checkRequirements()->getMessages() as $msg) {
$section = isset($sections[$msg['section']]) ? $sections[$msg['section']] : $sections['other'];
$key = 'civicrm.' . $msg['section'] . '.' . $msg['name'];
$requirements[$key] = [
'title' => $section . ': ' . $msg['message'],
'description' => $section . ': ' . $msg['message'],
'severity' => $severityMap[$msg['severity']],
];
}
}

ksort($requirements);

return $requirements;
}

/**
* @return \Civi\Setup
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/civicrmtheme/civicrmtheme.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name: CiviCRM Theme
type: module
description: 'Define alternate themes for CiviCRM.'
package: CiviCRM
core_version_requirement: ^9 || ^10 || ^11
core_version_requirement: ^9 || ^10 || ^11 || ^12
dependencies:
- civicrm
98 changes: 98 additions & 0 deletions src/Hook/CivicrmRequirementsHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace Drupal\civicrm\Hook;

use Drupal\Core\Extension\Requirement\RequirementSeverity;
use Drupal\Core\Hook\Attribute\Hook;


/**
* RuntimeRequirements for file.
*/
class CivicrmRequirementsHook {

/**
* Implements hook_runtime_requirements().
*/
#[Hook('runtime_requirements')]
public function runtime(): array {
$requirements = [];
// modified version of _civicrm_find_civicrm() from civicrm.install
// Move to a service?
$possible_paths = [];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to a service? This code is also needed in CivicrmInstallRequirements

if ($path = \Drupal::service('extension.list.module')->getPath('civicrm')) {
$possible_paths[] = $path;
}
$possible_paths[] = 'vendor/civicrm/civicrm-core';
$possible_paths[] = '../vendor/civicrm/civicrm-core';

foreach ($possible_paths as $path) {
if (file_exists($path . '/CRM/Core/ClassLoader.php')) {
$civicrm_base = \Drupal::service('file_system')->realpath($path);
break;
}
}

$severityMap = [
'info' => RequirementSeverity::OK,
'warning' => RequirementSeverity::Warning,
'error' => RequirementSeverity::Error,
];

if ($civicrm_base) {
$requirements['civicrm.location'] = [
'title' => 'CiviCRM location',
'severity' => $severityMap['info'],
'description' => 'CiviCRM core directory',
];
}
else {
$requirements['civicrm.location'] = [
'title' => 'CiviCRM location',
'severity' => $severityMap['error'],
'description' => 'CiviCRM must be installed via composer.',
];
return $requirements;
}

// Modification of _civicrm_setup()
// Move to a service?
if (defined('CIVI_SETUP')) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to a service? This is also needed in CivicrmInstallRequirements

/** @var \Civi\Setup $setup */
$setup = \Civi\Setup::instance();
}
else {
if ($civicrm_base) {
require_once $civicrm_base . '/CRM/Core/ClassLoader.php';
\CRM_Core_ClassLoader::singleton()->register();

\Civi\Setup::assertProtocolCompatibility(1.0);
\Civi\Setup::init([
'cms' => 'Drupal8',
'srcPath' => $civicrm_base,
]);
/** @var \Civi\Setup $setup */
$setup = \Civi\Setup::instance();
}
}

$sections = [
'system' => 'CiviCRM: System',
'database' => 'CiviCRM: Database',
'other' => 'CiviCRM: Other',
];

foreach ($setup->checkRequirements()->getMessages() as $msg) {
$section = isset($sections[$msg['section']]) ? $sections[$msg['section']] : $sections['other'];
$key = 'civicrm.' . $msg['section'] . '.' . $msg['name'];
$requirements[$key] = [
'title' => $section . ': ' . $msg['message'],
'description' => $section . ': ' . $msg['message'],
'severity' => $severityMap[$msg['severity']],
];
}

ksort($requirements);
return $requirements;
}
}
111 changes: 111 additions & 0 deletions src/Install/Requirements/CivicrmInstallRequirements.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

declare(strict_types=1);

namespace Drupal\civicrm\Install\Requirements;

use Drupal\Core\Extension\InstallRequirementsInterface;
use Drupal\Core\Extension\Requirement\RequirementSeverity;

class CivicrmInstallRequirements implements InstallRequirementsInterface {

/**
* {@inheritdoc}
*/
public static function getRequirements(): array {
$requirements = [];

// modified version of _civicrm_find_civicrm() from civicrm.install
// Move to a service?
$possible_paths = [];
if ($path = \Drupal::service('extension.list.module')->getPath('civicrm')) {
$possible_paths[] = $path;
}
$possible_paths[] = 'vendor/civicrm/civicrm-core';
$possible_paths[] = '../vendor/civicrm/civicrm-core';

foreach ($possible_paths as $path) {
if (file_exists($path . '/CRM/Core/ClassLoader.php')) {
$civicrm_base = \Drupal::service('file_system')->realpath($path);
break;
}
}

// Introduced in 11.2, and then compatibility layer removed in 11.3, so we
// have to support both.
$severityMap = [
'info' => RequirementSeverity::OK,
'warning' => RequirementSeverity::Warning,
'error' => RequirementSeverity::Error,
];

if ($civicrm_base) {
$requirements['civicrm.location'] = [
'title' => 'CiviCRM location',
'severity' => $severityMap['info'],
'description' => 'CiviCRM core directory',
];
}
else {
$requirements['civicrm.location'] = [
'title' => 'CiviCRM location',
'severity' => $severityMap['error'],
'description' => 'CiviCRM must be installed via composer.',
];
return $requirements;
}

// Modification of _civicrm_setup()
// Move to a service?
if (defined('CIVI_SETUP')) {
/** @var \Civi\Setup $setup */
$setup = \Civi\Setup::instance();
}
else {
if ($civicrm_base) {
require_once $civicrm_base . '/CRM/Core/ClassLoader.php';
\CRM_Core_ClassLoader::singleton()->register();

\Civi\Setup::assertProtocolCompatibility(1.0);
\Civi\Setup::init([
'cms' => 'Drupal8',
'srcPath' => $civicrm_base,
]);
/** @var \Civi\Setup $setup */
$setup = \Civi\Setup::instance();
}
}

if (!$setup->checkAuthorized()->isAuthorized()) {
$requirements['civicrm.checkAuthorized'] = [
'title' => 'CiviCRM Installation Not Authorized',
'description' => 'The current user does not have sufficient permissions to perform installation.',
'severity' => $severityMap['warning'],
];
return $requirements;
}

$sections = [
'system' => 'CiviCRM: System',
'database' => 'CiviCRM: Database',
'other' => 'CiviCRM: Other',
];


foreach ($setup->checkRequirements()->getMessages() as $msg) {
$section = isset($sections[$msg['section']]) ? $sections[$msg['section']] : $sections['other'];
$key = 'civicrm.' . $msg['section'] . '.' . $msg['name'];
$requirements[$key] = [
'title' => $section . ': ' . $msg['message'],
'description' => $section . ': ' . $msg['message'],
'severity' => $severityMap[$msg['severity']],
];
}


ksort($requirements);

return $requirements;
}

}