From 5757adf36db0c9346547da241d9d6743b6fb647c Mon Sep 17 00:00:00 2001 From: Herb vd Dool Date: Mon, 18 Apr 2016 00:35:50 -0400 Subject: [PATCH] CiviCRM install in backdrop working --- install/civicrm.php | 15 +++- install/index.php | 198 +++++++++++++++++++++++++++++++++++++++++- install/template.html | 14 +++ 3 files changed, 222 insertions(+), 5 deletions(-) diff --git a/install/civicrm.php b/install/civicrm.php index b9f8888fcc..c23bf6020b 100644 --- a/install/civicrm.php +++ b/install/civicrm.php @@ -88,6 +88,9 @@ function civicrm_main(&$config) { $siteDir . DIRECTORY_SEPARATOR . 'files' ); } + elseif ($installType == 'backdrop') { + civicrm_setup($cmsPath . DIRECTORY_SEPARATOR . 'files'); + } elseif ($installType == 'wordpress') { $upload_dir = wp_upload_dir(); $files_dirname = $upload_dir['basedir']; @@ -120,6 +123,9 @@ function civicrm_main(&$config) { if ($installType == 'drupal') { $configFile = $cmsPath . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . $siteDir . DIRECTORY_SEPARATOR . 'civicrm.settings.php'; } + elseif ($installType == 'backdrop') { + $configFile = $cmsPath . DIRECTORY_SEPARATOR . 'civicrm.settings.php'; + } elseif ($installType == 'wordpress') { $configFile = $files_dirname . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm.settings.php'; } @@ -233,6 +239,13 @@ function civicrm_config(&$config) { $params['CMSdbHost'] = $config['cmsdb']['server']; $params['CMSdbName'] = addslashes($config['cmsdb']['database']); } + elseif ($installType == 'backdrop') { + $params['cms'] = 'Backdrop'; + $params['CMSdbUser'] = addslashes($config['backdrop']['username']); + $params['CMSdbPass'] = addslashes($config['backdrop']['password']); + $params['CMSdbHost'] = $config['backdrop']['server']; + $params['CMSdbName'] = addslashes($config['backdrop']['database']); + } else { $params['cms'] = 'WordPress'; $params['CMSdbUser'] = addslashes(DB_USER); @@ -275,7 +288,7 @@ function civicrm_cms_base() { $baseURL = $_SERVER['SCRIPT_NAME']; - if ($installType == 'drupal') { + if ($installType == 'drupal' || $installType == 'backdrop') { //don't assume 6 dir levels, as civicrm //may or may not be in sites/all/modules/ //lets allow to install in custom dir. CRM-6840 diff --git a/install/index.php b/install/index.php index 17a134f03d..276c1c4ca1 100644 --- a/install/index.php +++ b/install/index.php @@ -43,7 +43,6 @@ /** * CiviCRM Installer */ - ini_set('max_execution_time', 3000); if (stristr(PHP_OS, 'WIN')) { @@ -85,7 +84,7 @@ global $installURLPath; $installType = strtolower($_SESSION['civicrm_install_type']); -if ($installType == 'drupal') { +if ($installType == 'drupal' || $installType == 'backdrop') { $crmPath = dirname(dirname($_SERVER['SCRIPT_FILENAME'])); $installDirPath = $installURLPath = ''; } @@ -143,6 +142,21 @@ if ($installType == 'drupal') { } } +if ($installType == 'backdrop') { + // Load backdrop database config + if (isset($_POST['backdrop'])) { + $backdropConfig = $_POST['backdrop']; + } + else { + $backdropConfig = array( + "server" => "localhost", + "username" => "backdrop", + "password" => "", + "database" => "backdrop", + ); + } +} + $loadGenerated = 0; if (isset($_POST['loadGenerated'])) { $loadGenerated = 1; @@ -164,6 +178,7 @@ foreach ($langs as $locale => $_) { $installTypeToUF = array( 'wordpress' => 'WordPress', 'drupal' => 'Drupal', + 'backdrop' => 'Backdrop', ); $uf = (isset($installTypeToUF[$installType]) ? $installTypeToUF[$installType] : 'Drupal'); @@ -206,6 +221,12 @@ if ($installType == 'drupal') { 'civicrm.settings.php' ); } +elseif ($installType == 'backdrop') { + $object = new CRM_Utils_System_Backdrop(); + $cmsPath = $object->cmsRootPath(); + $siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']); + $alreadyInstalled = file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR . 'civicrm.settings.php'); +} elseif ($installType == 'wordpress') { $cmsPath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm'; $upload_dir = wp_upload_dir(); @@ -232,6 +253,18 @@ if ($installType == 'drupal') { } } +if ($installType == 'backdrop') { + // Lets check only /modules/. + $pattern = '/' . preg_quote(CIVICRM_DIRECTORY_SEPARATOR . 'modules', CIVICRM_DIRECTORY_SEPARATOR) . '/'; + + if (!preg_match($pattern, str_replace("\\", "/", $_SERVER['SCRIPT_FILENAME']))) { + $directory = 'modules'; + $errorTitle = ts("Oops! Please correct your install location"); + $errorMsg = ts("Please untar (uncompress) your downloaded copy of CiviCRM in the %1 directory below your Drupal root directory.", array(1 => $directory)); + errorDisplayPage($errorTitle, $errorMsg); + } +} + // Exit with error if CiviCRM has already been installed. if ($alreadyInstalled) { $errorTitle = ts("Oops! CiviCRM is already installed"); @@ -244,6 +277,12 @@ if ($alreadyInstalled) { $siteDir, )); } + if ($installType == 'backdrop') { + $settings_directory = implode(CIVICRM_DIRECTORY_SEPARATOR, array( + ts('[your Backdrop root directory]'), + $siteDir, + )); + } $docLink = CRM_Utils_System::docURL2('Installation and Upgrades', FALSE, ts('Installation Guide'), NULL, NULL, "wiki"); $errorMsg = ts("CiviCRM has already been installed. ", array(1 => $settings_directory, 2 => $docLink)); @@ -286,6 +325,31 @@ if ($installType == 'drupal') { errorDisplayPage($errorTitle, $errorMsg); } } +elseif ($installType == 'backdrop') { + // Ensure that they have downloaded the correct version of CiviCRM + if ($civicrm_version['cms'] != 'Backdrop') { + $errorTitle = ts("Oops! Incorrect CiviCRM version"); + $errorMsg = ts("This installer can only be used for the Backdrop version of CiviCRM."); + errorDisplayPage($errorTitle, $errorMsg); + } + + define('BACKDROP_ROOT', $cmsPath); + + $backdropVersionFiles = array( + // Backdrop + implode(CIVICRM_DIRECTORY_SEPARATOR, array($cmsPath, 'core', 'includes', 'bootstrap.inc')), + ); + foreach ($backdropVersionFiles as $backdropVersionFile) { + if (file_exists($backdropVersionFile)) { + require_once $backdropVersionFile; + } + } + if (!defined('BACKDROP_VERSION') or version_compare(BACKDROP_VERSION, '1.0') < 0) { + $errorTitle = ts("Oops! Incorrect Backdrop version"); + $errorMsg = ts("This version of CiviCRM can only be used with Backdrop 1.x. Please ensure that '%1' exists if you are running Backdrop 1.0 and over.", array(1 => implode("' or '", $backdropVersionFiles))); + errorDisplayPage($errorTitle, $errorMsg); + } +} elseif ($installType == 'wordpress') { //HACK for now $civicrm_version['cms'] = 'WordPress'; @@ -312,6 +376,9 @@ if ($databaseConfig) { if ($installType == 'drupal') { $dbReq->checkdatabase($drupalConfig, 'Drupal'); } + if ($installType == 'backdrop') { + $dbReq->checkdatabase($backdropConfig, 'Backdrop'); + } } // Actual processor @@ -419,7 +486,7 @@ class InstallRequirements { ) ); } - $onlyRequire = ($dbName == 'Drupal') ? TRUE : FALSE; + $onlyRequire = ($dbName == 'Drupal' || $dbName == 'Backdrop') ? TRUE : FALSE; $this->requireDatabaseOrCreatePermissions( $databaseConfig['server'], $databaseConfig['username'], @@ -432,7 +499,7 @@ class InstallRequirements { ), $onlyRequire ); - if ($dbName != 'Drupal') { + if ($dbName != 'Drupal' && $dbName != 'Backdrop') { $this->requireMySQLInnoDB($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], @@ -540,6 +607,15 @@ class InstallRequirements { $siteDir, ); } + elseif ($installType == 'backdrop') { + + // make sure that we can write to sites/default and files/ + $writableDirectories = array( + $cmsPath . CIVICRM_DIRECTORY_SEPARATOR . + 'files', + $cmsPath, + ); + } elseif ($installType == 'wordpress') { // make sure that we can write to uploads/civicrm/ $upload_dir = wp_upload_dir(); @@ -1430,6 +1506,90 @@ class Installer extends InstallRequirements { $output .= ''; echo $output; } + elseif ( + $installType == 'backdrop' + ) { + + // clean output + @ob_clean(); + + $output .= ''; + $output .= ''; + $output .= ''; + $output .= '' . ts('CiviCRM Installed') . ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= '

' . ts('CiviCRM has been successfully installed') . '

'; + $output .= ''; + $output .= '
'; + $output .= ''; + $output .= ''; + echo $output; + } elseif ($installType == 'drupal' && version_compare(VERSION, '6.0') >= 0) { // clean output @ob_clean(); @@ -1550,6 +1710,36 @@ function civicrm_install_set_drupal_perms() { } } +function civicrm_install_set_backdrop_perms() { + $perms = array( + 'access all custom data', + 'access uploaded files', + 'make online contributions', + 'profile create', + 'profile edit', + 'profile view', + 'register for events', + 'view event info', + 'view event participants', + 'access CiviMail subscribe/unsubscribe pages', + ); + + // Adding a permission that has not yet been assigned to a module by + // a hook_permission implementation results in a database error. + // CRM-9042 + $allPerms = array_keys(module_invoke_all('permission')); + foreach (array_diff($perms, $allPerms) as $perm) { + watchdog('civicrm', + 'Cannot grant the %perm permission because it does not yet exist.', + array('%perm' => $perm), + WATCHDOG_ERROR + ); + } + $perms = array_intersect($perms, $allPerms); + user_role_grant_permissions(BACKDROP_AUTHENTICATED_ROLE, $perms); + user_role_grant_permissions(BACKDROP_ANONYMOUS_ROLE, $perms); +} + /** * @param $cmsPath * @param $str diff --git a/install/template.html b/install/template.html index 7fcd53e4cb..1380c1ca10 100644 --- a/install/template.html +++ b/install/template.html @@ -113,6 +113,15 @@ if ($text_direction == 'rtl') {

+ +

+

+
+
+
+
+

+

@@ -134,6 +143,11 @@ if ($text_direction == 'rtl') { echo "

" . ts('Drupal Database Details') . "

"; $dbReq->showTable(ts("MySQL %1 Configuration", array(1 => 'Drupal'))); }?> + +" . ts('Backdrop Database Details') . ""; +$dbReq->showTable(ts("MySQL %1 Configuration", array(1 => 'Backdrop'))); +}?>

-- 2.25.1