If you have moved an existing CiviCRM installation from one location or server to another there are several steps you will need to follow. They are detailed on this CiviCRM wiki page - {$docLink}. A fix for the specific problem that caused this error message to be displayed is to set the value of the config_backend column in the civicrm_domain table to NULL. However we strongly recommend that you review and follow all the steps in that document.

"; CRM_Utils_System::civiExit(); } else { return FALSE; } } return TRUE; } /** * Delete a directory given a path name, delete children directories * and files if needed * * @param string $target * The path name. * @param bool $rmdir * @param bool $verbose * * @throws Exception * @return void */ public static function cleanDir($target, $rmdir = TRUE, $verbose = TRUE) { static $exceptions = array('.', '..'); if ($target == '' || $target == '/') { throw new Exception("Overly broad deletion"); } if ($dh = @opendir($target)) { while (FALSE !== ($sibling = readdir($dh))) { if (!in_array($sibling, $exceptions)) { $object = $target . DIRECTORY_SEPARATOR . $sibling; if (is_dir($object)) { CRM_Utils_File::cleanDir($object, $rmdir, $verbose); } elseif (is_file($object)) { if (!unlink($object)) { CRM_Core_Session::setStatus(ts('Unable to remove file %1', array(1 => $object)), ts('Warning'), 'error'); } } } } closedir($dh); if ($rmdir) { if (rmdir($target)) { if ($verbose) { CRM_Core_Session::setStatus(ts('Removed directory %1', array(1 => $target)), '', 'success'); } return TRUE; } else { CRM_Core_Session::setStatus(ts('Unable to remove directory %1', array(1 => $target)), ts('Warning'), 'error'); } } } } /** * @param string $source * @param string $destination */ public static function copyDir($source, $destination) { if ($dh = opendir($source)) { @mkdir($destination); while (FALSE !== ($file = readdir($dh))) { if (($file != '.') && ($file != '..')) { if (is_dir($source . DIRECTORY_SEPARATOR . $file)) { CRM_Utils_File::copyDir($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); } else { copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); } } } closedir($dh); } } /** * Given a file name, recode it (in place!) to UTF-8 * * @param string $name * Name of file. * * @return bool * whether the file was recoded properly */ public static function toUtf8($name) { static $config = NULL; static $legacyEncoding = NULL; if ($config == NULL) { $config = CRM_Core_Config::singleton(); $legacyEncoding = $config->legacyEncoding; } if (!function_exists('iconv')) { return FALSE; } $contents = file_get_contents($name); if ($contents === FALSE) { return FALSE; } $contents = iconv($legacyEncoding, 'UTF-8', $contents); if ($contents === FALSE) { return FALSE; } $file = fopen($name, 'w'); if ($file === FALSE) { return FALSE; } $written = fwrite($file, $contents); $closed = fclose($file); if ($written === FALSE or !$closed) { return FALSE; } return TRUE; } /** * Appends a slash to the end of a string if it doesn't already end with one * * @param string $path * @param string $slash * * @return string */ public static function addTrailingSlash($path, $slash = NULL) { if (!$slash) { // FIXME: Defaulting to backslash on windows systems can produce unexpected results, esp for URL strings which should always use forward-slashes. // I think this fn should default to forward-slash instead. $slash = DIRECTORY_SEPARATOR; } if (!in_array(substr($path, -1, 1), array('/', '\\'))) { $path .= $slash; } return $path; } /** * @param $dsn * @param string $fileName * @param null $prefix * @param bool $isQueryString * @param bool $dieOnErrors */ public static function sourceSQLFile($dsn, $fileName, $prefix = NULL, $isQueryString = FALSE, $dieOnErrors = TRUE) { require_once 'DB.php'; $db = DB::connect($dsn); if (PEAR::isError($db)) { die("Cannot open $dsn: " . $db->getMessage()); } if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System::isDevelopment())) { $db->query('SET SESSION sql_mode = STRICT_TRANS_TABLES'); } if (!$isQueryString) { $string = $prefix . file_get_contents($fileName); } else { // use filename as query string $string = $prefix . $fileName; } //get rid of comments starting with # and -- $string = preg_replace("/^#[^\n]*$/m", "\n", $string); $string = preg_replace("/^(--[^-]).*/m", "\n", $string); $queries = preg_split('/;\s*$/m', $string); foreach ($queries as $query) { $query = trim($query); if (!empty($query)) { CRM_Core_Error::debug_query($query); $res = &$db->query($query); if (PEAR::isError($res)) { if ($dieOnErrors) { die("Cannot execute $query: " . $res->getMessage()); } else { echo "Cannot execute $query: " . $res->getMessage() . "

"; } } } } } /** * @param $ext * * @return bool */ public static function isExtensionSafe($ext) { static $extensions = NULL; if (!$extensions) { $extensions = CRM_Core_OptionGroup::values('safe_file_extension', TRUE); //make extensions to lowercase $extensions = array_change_key_case($extensions, CASE_LOWER); // allow html/htm extension ONLY if the user is admin // and/or has access CiviMail if (!(CRM_Core_Permission::check('access CiviMail') || CRM_Core_Permission::check('administer CiviCRM') || (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings') ) ) ) { unset($extensions['html']); unset($extensions['htm']); } } //support lower and uppercase file extensions return isset($extensions[strtolower($ext)]) ? TRUE : FALSE; } /** * Determine whether a given file is listed in the PHP include path * * @param string $name * Name of file. * * @return bool * whether the file can be include()d or require()d */ public static function isIncludable($name) { $x = @fopen($name, 'r', TRUE); if ($x) { fclose($x); return TRUE; } else { return FALSE; } } /** * Remove the 32 bit md5 we add to the fileName * also remove the unknown tag if we added it */ public static function cleanFileName($name) { // replace the last 33 character before the '.' with null $name = preg_replace('/(_[\w]{32})\./', '.', $name); return $name; } /** * @param string $name * * @return string */ public static function makeFileName($name) { $uniqID = md5(uniqid(rand(), TRUE)); $info = pathinfo($name); $basename = substr($info['basename'], 0, -(strlen(CRM_Utils_Array::value('extension', $info)) + (CRM_Utils_Array::value('extension', $info) == '' ? 0 : 1)) ); if (!self::isExtensionSafe(CRM_Utils_Array::value('extension', $info))) { // munge extension so it cannot have an embbeded dot in it // The maximum length of a filename for most filesystems is 255 chars. // We'll truncate at 240 to give some room for the extension. return CRM_Utils_String::munge("{$basename}_" . CRM_Utils_Array::value('extension', $info) . "_{$uniqID}", '_', 240) . ".unknown"; } else { return CRM_Utils_String::munge("{$basename}_{$uniqID}", '_', 240) . "." . CRM_Utils_Array::value('extension', $info); } } /** * @param $path * @param $ext * * @return array */ public static function getFilesByExtension($path, $ext) { $path = self::addTrailingSlash($path); $files = array(); if ($dh = opendir($path)) { while (FALSE !== ($elem = readdir($dh))) { if (substr($elem, -(strlen($ext) + 1)) == '.' . $ext) { $files[] .= $path . $elem; } } closedir($dh); } return $files; } /** * Restrict access to a given directory (by planting there a restrictive .htaccess file) * * @param string $dir * The directory to be secured. * @param bool $overwrite */ public static function restrictAccess($dir, $overwrite = FALSE) { // note: empty value for $dir can play havoc, since that might result in putting '.htaccess' to root dir // of site, causing site to stop functioning. // FIXME: we should do more checks here - if (!empty($dir) && is_dir($dir)) { $htaccess = << Order allow,deny Deny from all HTACCESS; $file = $dir . '.htaccess'; if ($overwrite || !file_exists($file)) { if (file_put_contents($file, $htaccess) === FALSE) { CRM_Core_Error::movedSiteError($file); } } } } /** * Restrict remote users from browsing the given directory. * * @param $publicDir */ public static function restrictBrowsing($publicDir) { if (!is_dir($publicDir) || !is_writable($publicDir)) { return; } // base dir $nobrowse = realpath($publicDir) . '/index.html'; if (!file_exists($nobrowse)) { @file_put_contents($nobrowse, ''); } // child dirs $dir = new RecursiveDirectoryIterator($publicDir); foreach ($dir as $name => $object) { if (is_dir($name) && $name != '..') { $nobrowse = realpath($name) . '/index.html'; if (!file_exists($nobrowse)) { @file_put_contents($nobrowse, ''); } } } } /** * Create the base file path from which all our internal directories are * offset. This is derived from the template compile directory set */ public static function baseFilePath($templateCompileDir = NULL) { static $_path = NULL; if (!$_path) { if ($templateCompileDir == NULL) { $config = CRM_Core_Config::singleton(); $templateCompileDir = $config->templateCompileDir; } $path = dirname($templateCompileDir); //this fix is to avoid creation of upload dirs inside templates_c directory $checkPath = explode(DIRECTORY_SEPARATOR, $path); $cnt = count($checkPath) - 1; if ($checkPath[$cnt] == 'templates_c') { unset($checkPath[$cnt]); $path = implode(DIRECTORY_SEPARATOR, $checkPath); } $_path = CRM_Utils_File::addTrailingSlash($path); } return $_path; } /** * @param $directory * * @return string */ public static function relativeDirectory($directory) { // Do nothing on windows if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { return $directory; } // check if directory is relative, if so return immediately if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) { return $directory; } // make everything relative from the baseFilePath $basePath = self::baseFilePath(); // check if basePath is a substr of $directory, if so // return rest of string if (substr($directory, 0, strlen($basePath)) == $basePath) { return substr($directory, strlen($basePath)); } // return the original value return $directory; } /** * @param $directory * * @return string */ public static function absoluteDirectory($directory) { // check if directory is already absolute, if so return immediately // Note: Windows PHP accepts any mix of "/" or "\", so "C:\htdocs" or "C:/htdocs" would be a valid absolute path if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && preg_match(';^[a-zA-Z]:[/\\\\];', $directory)) { return $directory; } // check if directory is already absolute, if so return immediately if (substr($directory, 0, 1) == DIRECTORY_SEPARATOR) { return $directory; } // make everything absolute from the baseFilePath $basePath = self::baseFilePath(); return $basePath . $directory; } /** * Make a file path relative to some base dir * * @param $directory * @param $basePath * * @return string */ public static function relativize($directory, $basePath) { if (substr($directory, 0, strlen($basePath)) == $basePath) { return substr($directory, strlen($basePath)); } else { return $directory; } } /** * Create a path to a temporary file which can endure for multiple requests * * TODO: Automatic file cleanup using, eg, TTL policy * * @param string $prefix * * @return string, path to an openable/writable file * @see tempnam */ public static function tempnam($prefix = 'tmp-') { //$config = CRM_Core_Config::singleton(); //$nonce = md5(uniqid() . $config->dsn . $config->userFrameworkResourceURL); //$fileName = "{$config->configAndLogDir}" . $prefix . $nonce . $suffix; $fileName = tempnam(sys_get_temp_dir(), $prefix); return $fileName; } /** * Create a path to a temporary directory which can endure for multiple requests * * TODO: Automatic file cleanup using, eg, TTL policy * * @param string $prefix * * @return string, path to an openable/writable directory; ends with '/' * @see tempnam */ public static function tempdir($prefix = 'tmp-') { $fileName = self::tempnam($prefix); unlink($fileName); mkdir($fileName, 0700); return $fileName . '/'; } /** * Search directory tree for files which match a glob pattern. * * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored. * * @param string $dir * base dir. * @param string $pattern * glob pattern, eg "*.txt". * @param bool $relative * TRUE if paths should be made relative to $dir * @return array(string) */ public static function findFiles($dir, $pattern, $relative = FALSE) { $dir = rtrim($dir, '/'); $todos = array($dir); $result = array(); while (!empty($todos)) { $subdir = array_shift($todos); $matches = glob("$subdir/$pattern"); if (is_array($matches)) { foreach ($matches as $match) { if (!is_dir($match)) { $result[] = $relative ? CRM_Utils_File::relativize($match, "$dir/") : $match; } } } if ($dh = opendir($subdir)) { while (FALSE !== ($entry = readdir($dh))) { $path = $subdir . DIRECTORY_SEPARATOR . $entry; if ($entry{0} == '.') { // ignore } elseif (is_dir($path)) { $todos[] = $path; } } closedir($dh); } } return $result; } /** * Determine if $child is a sub-directory of $parent * * @param string $parent * @param string $child * @param bool $checkRealPath * * @return bool */ public static function isChildPath($parent, $child, $checkRealPath = TRUE) { if ($checkRealPath) { $parent = realpath($parent); $child = realpath($child); } $parentParts = explode('/', rtrim($parent, '/')); $childParts = explode('/', rtrim($child, '/')); while (($parentPart = array_shift($parentParts)) !== NULL) { $childPart = array_shift($childParts); if ($parentPart != $childPart) { return FALSE; } } if (empty($childParts)) { return FALSE; // same directory } else { return TRUE; } } /** * Move $fromDir to $toDir, replacing/deleting any * pre-existing content. * * @param string $fromDir * The directory which should be moved. * @param string $toDir * The new location of the directory. * @param bool $verbose * * @return bool * TRUE on success */ public static function replaceDir($fromDir, $toDir, $verbose = FALSE) { if (is_dir($toDir)) { if (!self::cleanDir($toDir, TRUE, $verbose)) { return FALSE; } } // return rename($fromDir, $toDir); // CRM-11987, https://bugs.php.net/bug.php?id=54097 CRM_Utils_File::copyDir($fromDir, $toDir); if (!CRM_Utils_File::cleanDir($fromDir, TRUE, FALSE)) { CRM_Core_Session::setStatus(ts('Failed to clean temp dir: %1', array(1 => $fromDir)), '', 'alert'); return FALSE; } return TRUE; } }