* This class generates form components for Error Handling and Debugging
*/
class CRM_Admin_Form_Setting_UpdateConfigBackend extends CRM_Admin_Form_Setting {
- protected $_oldBaseDir;
- protected $_oldBaseURL;
- protected $_oldSiteName;
/**
* Build the form object.
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Settings - Cleanup Caches and Update Paths'));
- list(
- $this->_oldBaseURL,
- $this->_oldBaseDir,
- $this->_oldSiteName
- ) = CRM_Core_BAO_ConfigSetting::getConfigSettings();
-
- $this->assign('oldBaseURL', $this->_oldBaseURL);
- $this->assign('oldBaseDir', $this->_oldBaseDir);
- $this->assign('oldSiteName', $this->_oldSiteName);
-
$this->addElement(
'submit', $this->getButtonName('next', 'cleanup'), 'Cleanup Caches',
array('class' => 'crm-form-submit', 'id' => 'cleanup-cache')
);
- $this->add('text', 'newBaseURL', ts('New Base URL'), NULL, TRUE);
- $this->add('text', 'newBaseDir', ts('New Base Directory'), NULL, TRUE);
- if ($this->_oldSiteName) {
- $this->add('text', 'newSiteName', ts('New Site Name'), NULL, TRUE);
- }
- $this->addFormRule(array('CRM_Admin_Form_Setting_UpdateConfigBackend', 'formRule'));
-
- parent::buildQuickForm();
- }
-
- public function setDefaultValues() {
- if (!$this->_defaults) {
- parent::setDefaultValues();
-
- $config = CRM_Core_Config::singleton();
- list(
- $this->_defaults['newBaseURL'],
- $this->_defaults['newBaseDir'],
- $this->_defaults['newSiteName']
- ) = CRM_Core_BAO_ConfigSetting::getBestGuessSettings();
- }
+ $this->addElement(
+ 'submit', $this->getButtonName('next', 'resetpaths'), 'Reset Paths',
+ array('class' => 'crm-form-submit', 'id' => 'resetpaths')
+ );
- return $this->_defaults;
- }
-
- /**
- * @param $fields
- *
- * @return array
- */
- public static function formRule($fields) {
- $tmpDir = trim($fields['newBaseDir']);
-
- $errors = array();
- if (!is_writable($tmpDir)) {
- $errors['newBaseDir'] = ts('%1 directory does not exist or cannot be written by webserver',
- array(1 => $tmpDir)
- );
- }
- return $errors;
+ //parent::buildQuickForm();
}
public function postProcess() {
CRM_Core_BAO_WordReplacement::rebuild();
CRM_Core_Session::setStatus(ts('Cache has been cleared and menu has been rebuilt successfully.'), ts("Success"), "success");
- return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/updateConfigBackend', 'reset=1'));
- }
-
- // redirect to admin page after saving
- $session = CRM_Core_Session::singleton();
- $session->pushUserContext(CRM_Utils_System::url('civicrm/admin'));
-
- $params = $this->controller->exportValues($this->_name);
-
- //CRM-5679
- foreach ($params as $name => & $val) {
- if ($val && in_array($name, array('newBaseDir', 'newSiteName'))) {
- $val = CRM_Utils_File::addTrailingSlash($val);
- }
}
- //CRM-15365 - Fix BaseURL to avoid wrong trailing slash on Windows installs
- foreach ($params as $name => & $val) {
- if ($val && in_array($name, array('newBaseURL'))) {
- $val = CRM_Utils_File::addTrailingSlash($val, "/");
- }
- }
+ if (!empty($_POST['_qf_UpdateConfigBackend_next_resetpaths'])) {
+ $msg = CRM_Core_BAO_ConfigSetting::doSiteMove();
- $from = array($this->_oldBaseURL, $this->_oldBaseDir);
- $to = array(
- trim($params['newBaseURL']),
- trim($params['newBaseDir']),
- );
- if ($this->_oldSiteName &&
- $params['newSiteName']
- ) {
- $from[] = $this->_oldSiteName;
- $to[] = $params['newSiteName'];
+ CRM_Core_Session::setStatus($msg, ts("Success"), "success");
}
- $newValues = str_replace($from,
- $to,
- $this->_defaults
- );
-
- parent::commonProcess($newValues);
-
- parent::rebuildMenu();
+ return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/updateConfigBackend', 'reset=1'));
}
}
}
}
- /**
- * @return array
- */
- public static function getConfigSettings() {
- $config = CRM_Core_Config::singleton();
-
- $url = $dir = $siteName = $siteRoot = NULL;
- if ($config->userFramework == 'Joomla') {
- $url = preg_replace(
- '|administrator/components/com_civicrm/civicrm/|',
- '',
- $config->userFrameworkResourceURL
- );
-
- // lets use imageUploadDir since we dont mess around with its values
- // in the config object, lets kep it a bit generic since folks
- // might have different values etc
-
- //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths
- if (DIRECTORY_SEPARATOR == '\\') {
- $dir = preg_replace(
- '|civicrm[/\\\\]templates_c[/\\\\].*$|',
- '',
- $config->templateCompileDir
- );
- }
- else {
- $dir = preg_replace(
- '|civicrm/templates_c/.*$|',
- '',
- $config->templateCompileDir
- );
- }
-
- $siteRoot = preg_replace(
- '|/media/civicrm/.*$|',
- '',
- $config->imageUploadDir
- );
- }
- elseif ($config->userFramework == 'WordPress') {
- $url = preg_replace(
- '|wp-content/plugins/civicrm/civicrm/|',
- '',
- $config->userFrameworkResourceURL
- );
-
- // lets use imageUploadDir since we dont mess around with its values
- // in the config object, lets kep it a bit generic since folks
- // might have different values etc
-
- //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths
- if (DIRECTORY_SEPARATOR == '\\') {
- $dir = preg_replace(
- '|civicrm[/\\\\]templates_c[/\\\\].*$|',
- '',
- $config->templateCompileDir
- );
- }
- else {
- $dir = preg_replace(
- '|civicrm/templates_c/.*$|',
- '',
- $config->templateCompileDir
- );
- }
-
- $siteRoot = preg_replace(
- '|/wp-content/plugins/files/civicrm/.*$|',
- '',
- $config->imageUploadDir
- );
- }
- else {
- $url = preg_replace(
- '|sites/[\w\.\-\_]+/modules/civicrm/|',
- '',
- $config->userFrameworkResourceURL
- );
-
- // lets use imageUploadDir since we dont mess around with its values
- // in the config object, lets kep it a bit generic since folks
- // might have different values etc
-
- //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths
- if (DIRECTORY_SEPARATOR == '\\') {
- $dir = preg_replace(
- '|[/\\\\]files[/\\\\]civicrm[/\\\\].*$|',
- '\\\\files\\\\',
- $config->imageUploadDir
- );
- }
- else {
- $dir = preg_replace(
- '|/files/civicrm/.*$|',
- '/files/',
- $config->imageUploadDir
- );
- }
-
- $matches = array();
- if (preg_match(
- '|/sites/([\w\.\-\_]+)/|',
- $config->imageUploadDir,
- $matches
- )) {
- $siteName = $matches[1];
- if ($siteName) {
- $siteName = "/sites/$siteName/";
- $siteNamePos = strpos($dir, $siteName);
- if ($siteNamePos !== FALSE) {
- $siteRoot = substr($dir, 0, $siteNamePos);
- }
- }
- }
- }
-
- return array($url, $dir, $siteName, $siteRoot);
- }
-
- /**
- * Return likely default settings.
- * @return array
- * site settings
- * - $url
- * - $dir Base Directory
- * - $siteName
- * - $siteRoot
- */
- public static function getBestGuessSettings() {
- $config = CRM_Core_Config::singleton();
-
- //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths
- if (DIRECTORY_SEPARATOR == '\\') {
- $needle = 'civicrm[/\\\\]templates_c[/\\\\].*$';
- }
- else {
- $needle = 'civicrm/templates_c/.*$';
- }
-
- $dir = preg_replace(
- "|$needle|",
- '',
- $config->templateCompileDir
- );
-
- list($url, $siteName, $siteRoot) = $config->userSystem->getDefaultSiteSettings($dir);
- return array($url, $dir, $siteName, $siteRoot);
- }
-
/**
* @param array $defaultValues
*
*/
public static function doSiteMove($defaultValues = array()) {
$moveStatus = ts('Beginning site move process...') . '<br />';
- // get the current and guessed values
- list($oldURL, $oldDir, $oldSiteName, $oldSiteRoot) = self::getConfigSettings();
- list($newURL, $newDir, $newSiteName, $newSiteRoot) = self::getBestGuessSettings();
-
- // retrieve these values from the argument list
- $variables = array('URL', 'Dir', 'SiteName', 'SiteRoot', 'Val_1', 'Val_2', 'Val_3');
- $states = array('old', 'new');
- foreach ($variables as $varSuffix) {
- foreach ($states as $state) {
- $var = "{$state}{$varSuffix}";
- if (!isset($$var)) {
- if (isset($defaultValues[$var])) {
- $$var = $defaultValues[$var];
- }
- else {
- $$var = NULL;
- }
+ $settings = Civi::settings();
+
+ foreach (array_merge(self::getPathSettings(), self::getUrlSettings()) as $key) {
+ $value = $settings->get($key);
+ if ($value && $value != $settings->getDefault($key)) {
+ if ($settings->getMandatory($key) === NULL) {
+ $settings->revert($key);
+ $moveStatus .= ts("WARNING: The setting (%1) has been reverted.", array(
+ 1 => $key,
+ ));
+ $moveStatus .= '<br />';
}
- $$var = CRM_Utils_Request::retrieve($var,
- 'String',
- CRM_Core_DAO::$_nullArray,
- FALSE,
- $$var,
- 'REQUEST'
- );
- }
- }
-
- $from = $to = array();
- foreach ($variables as $varSuffix) {
- $oldVar = "old{$varSuffix}";
- $newVar = "new{$varSuffix}";
- //skip it if either is empty or both are exactly the same
- if ($$oldVar &&
- $$newVar &&
- $$oldVar != $$newVar
- ) {
- $from[] = $$oldVar;
- $to[] = $$newVar;
- }
- }
-
- $sql = "
-SELECT config_backend
-FROM civicrm_domain
-WHERE id = %1
-";
- $params = array(1 => array(CRM_Core_Config::domainID(), 'Integer'));
- $configBackend = CRM_Core_DAO::singleValueQuery($sql, $params);
- if (!$configBackend) {
- CRM_Core_Error::fatal(ts('Returning early due to unexpected error - civicrm_domain.config_backend column value is NULL. Try visiting CiviCRM Home page.'));
- }
- $configBackend = unserialize($configBackend);
-
- $configBackend = str_replace($from,
- $to,
- $configBackend
- );
-
- $configBackend = serialize($configBackend);
- $sql = "
-UPDATE civicrm_domain
-SET config_backend = %2
-WHERE id = %1
-";
- $params[2] = array($configBackend, 'String');
- CRM_Core_DAO::executeQuery($sql, $params);
-
- // Apply the changes to civicrm_option_values
- $optionGroups = array('url_preferences', 'directory_preferences');
- foreach ($optionGroups as $option) {
- foreach ($variables as $varSuffix) {
- $oldVar = "old{$varSuffix}";
- $newVar = "new{$varSuffix}";
-
- $from = $$oldVar;
- $to = $$newVar;
-
- if ($from && $to && $from != $to) {
- $sql = '
-UPDATE civicrm_option_value
-SET value = REPLACE(value, %1, %2)
-WHERE option_group_id = (
- SELECT id
- FROM civicrm_option_group
- WHERE name = %3 )
-';
- $params = array(
- 1 => array($from, 'String'),
- 2 => array($to, 'String'),
- 3 => array($option, 'String'),
- );
- CRM_Core_DAO::executeQuery($sql, $params);
+ else {
+ $moveStatus .= ts("WARNING: The setting (%1) is overridden and could not be reverted.", array(
+ 1 => $key,
+ ));
+ $moveStatus .= '<br />';
}
}
}
- $moveStatus .=
- ts('Directory and Resource URLs have been updated in the moved database to reflect current site location.') .
- '<br />';
-
$config = CRM_Core_Config::singleton();
// clear the template_c and upload directory also
return $params;
}
+ /**
+ * @return array
+ */
+ private static function getUrlSettings() {
+ return array(
+ 'userFrameworkResourceURL',
+ 'imageUploadURL',
+ 'customCSSURL',
+ 'extensionsURL',
+ );
+ }
+
+ /**
+ * @return array
+ */
+ private static function getPathSettings() {
+ return array(
+ 'uploadDir',
+ 'imageUploadDir',
+ 'customFileUploadDir',
+ 'customTemplateDir',
+ 'customPHPPathDir',
+ 'extensionsDir',
+ );
+ }
+
}
<div class="crm-block crm-form-block crm-config-backend-form-block">
<div id="help">
<p>
- {ts}Use this form if you need to reset the Base Directory Path and Base URL settings for your CiviCRM installation. These settings are stored in the database, and generally need adjusting after moving a CiviCRM installation to another location in the file system and/or to another URL.{/ts}</p>
+ {ts}When migrating a site to a new server, the paths and URLs of your CiviCRM installation may change. {/ts}
+ </p>
<p>
- {ts}CiviCRM will attempt to detect the new values that should be used. These are provided below as the default values for the <strong>New Base Directory</strong> and <strong>New Base URL</strong> fields.{/ts}</p>
+ {capture assign="pathsURL"}{crmURL p="civicrm/admin/setting/path" q="reset=1"}{/capture}
+ {capture assign="urlsURL"}{crmURL p="civicrm/admin/setting/url" q="reset=1"}{/capture}
+ {ts 1=$pathsURL 2=$urlsURL}The old paths and URLs may be retained in some database records. Use this form to clear caches or to reset paths to their defaults. If you need further customizations, then update the <a href="%1">Directories</a> and <a href="%2">Resource URLs</a>.{/ts}
+ </p>
</div>
<div>
<span class="crm-button crm-icon-button">
<span class="crm-button-icon ui-icon-trash"> </span>
{$form._qf_UpdateConfigBackend_next_cleanup.html}
</span>
+ <span class="crm-button crm-icon-button">
+ <span class="crm-button-icon ui-icon-trash"> </span>
+ {$form._qf_UpdateConfigBackend_next_resetpaths.html}
+ </span>
</div>
- <table>
- <tr class="crm-config-backend-form-block-oldBaseDir">
- <td class="label">{ts}Old Base Directory{/ts}</td>
- <td>{$oldBaseDir}</td>
- </tr>
- <tr class="crm-config-backend-form-block-newBaseDir">
- <td class="label">{$form.newBaseDir.label}</td>
- <td>{$form.newBaseDir.html|crmAddClass:'huge'}<br />
- <span class="description">{ts}For Drupal and WordPress installs, this is the absolute path to the location of the 'files' directory. For Joomla installs this is the absolute path to the location of the 'media' directory.{/ts}</span></td>
- </tr>
- <tr class="crm-config-backend-form-block-oldBaseURL">
- <td class="label">{ts}Old Base URL{/ts}</td>
- <td>{$oldBaseURL}</td>
- </tr>
- <tr class="crm-config-backend-form-block-newBaseURL">
- <td class="label">{$form.newBaseURL.label}</td>
- <td>{$form.newBaseURL.html|crmAddClass:'huge'}<br />
- <span class="description">{ts}This is the URL for your Drupal, Joomla or WordPress site (e.g. http://www.mysite.com/drupal/).{/ts}</span></td>
- </tr>
-{if $oldSiteName}
- <tr class="crm-config-backend-form-block-oldSiteName">
- <td class="label">{ts}Old Site Name{/ts}</td>
- <td>{$oldSiteName}</td>
- </tr>
- <tr class="crm-config-backend-form-block-newSiteName">
- <td class="label">{$form.newSiteName.label}</td>
- <td>{$form.newSiteName.html|crmAddClass:'huge'}<br />
- <span class="description">{ts}This is the your site name for a multisite install.{/ts}</span></td>
- </tr>
-{/if}
- </table>
<div>{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
<div class="spacer"></div>
</div>