/** * @param $config */ function civicrm_main(&$config) { global $sqlPath, $crmPath, $cmsPath, $installType; if ($installType == 'drupal') { $siteDir = isset($config['site_dir']) ? $config['site_dir'] : getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']); civicrm_setup($cmsPath . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . $siteDir . DIRECTORY_SEPARATOR . 'files'); } elseif ($installType == 'wordpress') { civicrm_setup(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'files'); } $dsn = "mysql://{$config['mysql']['username']}:{$config['mysql']['password']}@{$config['mysql']['server']}/{$config['mysql']['database']}?new_link=true"; civicrm_source($dsn, $sqlPath . DIRECTORY_SEPARATOR . 'civicrm.mysql'); if (!empty($config['loadGenerated'])) { civicrm_source($dsn, $sqlPath . DIRECTORY_SEPARATOR . 'civicrm_generated.mysql', TRUE); } else { if (isset($config['seedLanguage']) and preg_match('/^[a-z][a-z]_[A-Z][A-Z]$/', $config['seedLanguage']) and file_exists($sqlPath . DIRECTORY_SEPARATOR . "civicrm_data.{$config['seedLanguage']}.mysql") and file_exists($sqlPath . DIRECTORY_SEPARATOR . "civicrm_acl.{$config['seedLanguage']}.mysql")) { civicrm_source($dsn, $sqlPath . DIRECTORY_SEPARATOR . "civicrm_data.{$config['seedLanguage']}.mysql"); civicrm_source($dsn, $sqlPath . DIRECTORY_SEPARATOR . "civicrm_acl.{$config['seedLanguage']}.mysql"); } else { civicrm_source($dsn, $sqlPath . DIRECTORY_SEPARATOR . 'civicrm_data.mysql'); civicrm_source($dsn, $sqlPath . DIRECTORY_SEPARATOR . 'civicrm_acl.mysql'); } } // generate backend settings file if ($installType == 'drupal') { $configFile = $cmsPath . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . $siteDir . DIRECTORY_SEPARATOR . 'civicrm.settings.php'; } elseif ($installType == 'wordpress') { $configFile = $cmsPath . DIRECTORY_SEPARATOR . 'civicrm.settings.php'; } $string = civicrm_config($config); civicrm_write_file($configFile, $string); }
function civicrm_main() { global $civicrmUpgrade, $adminPath; civicrm_setup(); // setup vars $configFile = $adminPath . DIRECTORY_SEPARATOR . 'civicrm.settings.php'; // generate backend config file $string = "\n<?php\ndefine('CIVICRM_SETTINGS_PATH', '{$configFile}');\n\$error = @include_once( '{$configFile}' );\nif ( \$error == false ) {\n echo \"Could not load the settings file at: {$configFile}\n\";\n exit( );\n}\n\n// Load class loader\nrequire_once \$civicrm_root . '/CRM/Core/ClassLoader.php';\nCRM_Core_ClassLoader::singleton()->register();\n"; $string = trim($string); civicrm_write_file($adminPath . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm.config.php', $string); $liveSite = substr_replace(JURI::root(), '', -1, 1); $siteKey = md5(uniqid('', true) . $liveSite); // generate backend settings file $string = civicrm_config(FALSE, $siteKey); civicrm_write_file($configFile, $string); // generate frontend settings file $string = civicrm_config(TRUE, $siteKey); civicrm_write_file(JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_civicrm' . DIRECTORY_SEPARATOR . 'civicrm.settings.php', $string); define('CIVICRM_SETTINGS_PATH', $configFile); include_once CIVICRM_SETTINGS_PATH; // for install case only if (!$civicrmUpgrade) { $sqlPath = $adminPath . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'sql'; civicrm_source($sqlPath . DIRECTORY_SEPARATOR . 'civicrm.mysql'); civicrm_source($sqlPath . DIRECTORY_SEPARATOR . 'civicrm_data.mysql'); require_once 'CRM/Core/ClassLoader.php'; CRM_Core_ClassLoader::singleton()->register(); require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(); // now also build the menu require_once 'CRM/Core/Menu.php'; CRM_Core_Menu::store(); } }
function civicrm_main() { global $civicrmUpgrade, $adminPath; civicrm_setup(); // setup vars $configFile = $adminPath . DIRECTORY_SEPARATOR . 'civicrm.settings.php'; // generate backend config file $string = "\n<?php\nrequire_once '{$configFile}';\n"; $string = trim($string); civicrm_write_file($adminPath . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm.config.php', $string); // generate backend settings file $string = civicrm_config(false); civicrm_write_file($configFile, $string); // generate frontend settings file $string = civicrm_config(true); civicrm_write_file(JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_civicrm' . DIRECTORY_SEPARATOR . 'civicrm.settings.php', $string); include_once $configFile; // for install case only if (!$civicrmUpgrade) { $sqlPath = $adminPath . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'sql'; civicrm_source($sqlPath . DIRECTORY_SEPARATOR . 'civicrm.mysql'); civicrm_source($sqlPath . DIRECTORY_SEPARATOR . 'civicrm_data.mysql'); require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(); // now also build the menu require_once 'CRM/Core/Menu.php'; CRM_Core_Menu::store(); } }
function civicrm_main() { global $sqlPath, $comPath, $crmPath, $frontPath; civicrm_setup(); civicrm_source($sqlPath . DIRECTORY_SEPARATOR . 'civicrm_40.mysql'); civicrm_source($sqlPath . DIRECTORY_SEPARATOR . 'civicrm_data.mysql'); // generate backend settings file $configFile = $comPath . DIRECTORY_SEPARATOR . 'civicrm.settings.php'; $string = civicrm_config(false); civicrm_write_file($configFile, $string); // generate backend config file $string = "\n<?php\ninclude_once '{$configFile}';\n?>\n"; $string = trim($string); civicrm_write_file($crmPath . DIRECTORY_SEPARATOR . 'civicrm.config.php', $string); // generate frontend settings file $string = civicrm_config(true); civicrm_write_file($frontPath . DIRECTORY_SEPARATOR . 'civicrm.settings.php', $string); }
/** * Implementation of command 'install' */ private function install() { # validate if (!($dbuser = $this->getOption('dbuser', false))) { return WP_CLI::error('CiviCRM database username not specified.'); } if (!($dbpass = $this->getOption('dbpass', false))) { return WP_CLI::error('CiviCRM database password not specified.'); } if (!($dbhost = $this->getOption('dbhost', false))) { return WP_CLI::error('CiviCRM database host not specified.'); } if (!($dbname = $this->getOption('dbname', false))) { return WP_CLI::error('CiviCRM database name not specified.'); } if (!$this->getOption('tarfile', false) and !$this->getOption('zipfile', false)) { return WP_CLI::error('Must specify either --tarfile or --zipfile'); } if ($lang = $this->getOption('lang', false) and !($langtarfile = $this->getOption('langtarfile', FALSE))) { return WP_CLI::error('CiviCRM language tarfile not specified.'); } # begin install $wp_root = ABSPATH; if ($pluginPath = $this->getOption('destination', FALSE)) { $pluginPath = $wp_root . $pluginPath; } else { $pluginPath = $wp_root . 'wp-content/plugins'; } if (is_dir($pluginPath . '/civicrm')) { return WP_CLI::error("Existing CiviCRM found. No action taken."); } # extract the archive if ($this->getOption('tarfile', false)) { # should probably never get to here as Wordpress Civi comes in a zip file, but # just in case that ever changes .. if (!$this->untar($pluginPath)) { return WP_CLI::error("Error extracting tarfile"); } } elseif ($this->getOption('zipfile', false)) { if (!$this->unzip($pluginPath)) { return WP_CLI::error("Error extracting zipfile"); } } else { return WP_CLI::error("No zipfile specified, use --zipfile=path/to/zipfile"); } # include civicrm installer helper file global $crmPath; $crmPath = "{$pluginPath}/civicrm/civicrm"; $civicrmInstallerHelper = "{$crmPath}/install/civicrm.php"; if (!file_exists($civicrmInstallerHelper)) { return WP_CLI::error("Archive could not be unpacked OR CiviCRM installer helper file is missing."); } WP_CLI::success("Archive unpacked."); require_once $civicrmInstallerHelper; if ($lang != '') { if (!$this->untar($pluginPath, 'langtarfile')) { return WP_CLI::error("No language tarfile specified, use --langtarfile=path/to/tarfile"); } } # create files dirs civicrm_setup("{$pluginPath}/files"); WP_CLI::launch("chmod 0777 {$pluginPath}/files/civicrm -R"); # now we've got some files in place, require PEAR DB and check db setup $dsn = "mysql://{$dbuser}:{$dbpass}@{$dbhost}/{$dbname}?new_link=true"; $dsn_nodb = "mysql://{$dbuser}:{$dbpass}@{$dbhost}"; require_once ABSPATH . '/wp-content/plugins/civicrm/civicrm/packages/DB.php'; $db = DB::connect($dsn); if (DB::iserror($db)) { $db = DB::connect($dsn_nodb); if (DB::iserror($db)) { return WP_CLI::error("Unable to connect to database. Please re-check credentials."); } $db->query("CREATE DATABASE {$dbname}"); if (DB::iserror($db)) { return WP_CLI::error('CiviCRM database was not found. Failed to create one.'); } $db->disconnect(); } # install db $sqlPath = "{$crmPath}/sql"; # setup database with civicrm structure and data WP_CLI::line("Loading CiviCRM database structure .."); civicrm_source($dsn, $sqlPath . '/civicrm.mysql'); WP_CLI::line("Loading CiviCRM database with required data .."); # testing the translated sql files availability $data_file = $sqlPath . '/civicrm_data.mysql'; $acl_file = $sqlPath . '/civicrm_acl.mysql'; if ($lang != '') { if (file_exists($sqlPath . '/civicrm_data.' . $lang . '.mysql') and file_exists($sqlPath . '/civicrm_acl.' . $lang . '.mysql') and $lang != '') { $data_file = $sqlPath . '/civicrm_data.' . $lang . '.mysql'; $acl_file = $sqlPath . '/civicrm_acl.' . $lang . '.mysql'; } else { WP_CLI::warning("No sql files could be retrieved for '{$lang}' using default language."); } } civicrm_source($dsn, $data_file); civicrm_source($dsn, $acl_file); WP_CLI::success("CiviCRM database loaded successfully."); # generate civicrm.settings.php file $settingsTplFile = "{$crmPath}/templates/CRM/common/civicrm.settings.php.tpl"; if (!file_exists($settingsTplFile)) { $settingsTplFile = "{$crmPath}/templates/CRM/common/civicrm.settings.php.template"; if (!file_exists($settingsTplFile)) { return WP_CLI::error("Could not find CiviCRM settings template and therefore could not create settings file."); } } WP_CLI::line("Generating civicrm settings file .."); if ($baseUrl = $this->getOption('site_url', false)) { $ssl = $this->getOption('ssl', false); $protocol = $ssl == 'on' ? 'https' : 'http'; } $baseUrl = !$baseUrl ? get_bloginfo('url') : $protocol . '://' . $baseUrl; if (substr($baseUrl, -1) != '/') { $baseUrl .= '/'; } $params = array('crmRoot' => $crmPath . '/', 'templateCompileDir' => "{$pluginPath}/files/civicrm/templates_c", 'frontEnd' => 0, 'cms' => 'WordPress', 'baseURL' => $baseUrl, 'dbUser' => $dbuser, 'dbPass' => $dbpass, 'dbHost' => $dbhost, 'dbName' => $dbname, 'CMSdbUser' => DB_USER, 'CMSdbPass' => DB_PASSWORD, 'CMSdbHost' => DB_HOST, 'CMSdbName' => DB_NAME, 'siteKey' => md5(uniqid('', TRUE) . $baseUrl)); $str = file_get_contents($settingsTplFile); foreach ($params as $key => $value) { $str = str_replace('%%' . $key . '%%', $value, $str); } $str = trim($str); $configFile = "{$pluginPath}/civicrm/civicrm.settings.php"; civicrm_write_file($configFile, $str); WP_CLI::launch("chmod 0644 {$configFile}"); WP_CLI::success(sprintf("Settings file generated: %s", $configFile)); # activate plugin and we're done @WP_CLI::run_command(array('plugin', 'activate', 'civicrm'), array()); WP_CLI::success("CiviCRM installed."); }