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 */ 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'); } } } } /** * Concatenate several files. * * @param array $files * List of file names. * @param string $delim * An optional delimiter to put between files. * @return string */ public static function concat($files, $delim = '') { $buf = ''; $first = TRUE; foreach ($files as $file) { if (!$first) { $buf .= $delim; } $buf .= file_get_contents($file); $first = FALSE; } return $buf; } /** * @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; } /** * Save a fake file somewhere * * @param string $dir * The directory where the file should be saved. * @param string $contents * Optional: the contents of the file. * * @return string * The filename saved, or FALSE on failure. */ public static function createFakeFile($dir, $contents = 'delete me') { $dir = self::addTrailingSlash($dir); $file = 'delete-this-' . CRM_Utils_String::createRandom(10, CRM_Utils_String::ALPHANUMERIC); $success = file_put_contents($dir . $file, $contents); return ($success === FALSE) ? FALSE : $file; } /** * @param string|NULL $dsn * Use NULL to load the default/active connection from CRM_Core_DAO. * Otherwise, give a full DSN string. * @param string $fileName * @param null $prefix * @param bool $isQueryString * @param bool $dieOnErrors */ public static function sourceSQLFile($dsn, $fileName, $prefix = NULL, $isQueryString = FALSE, $dieOnErrors = TRUE) { if ($dsn === NULL) { $db = CRM_Core_DAO::getConnection(); } else { 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'); } $db->query('SET NAMES utf8'); $transactionId = CRM_Utils_Type::escape(CRM_Utils_Request::id(), 'String'); $db->query('SET @uniqueID = ' . "'$transactionId'"); 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 = self::stripComments($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() . "";
}
}
}
}
}
/**
*
* Strips comment from a possibly multiline SQL string
*
* @param string $string
*
* @return string
* stripped string
*/
public static function stripComments($string) {
return preg_replace("/^(#|--).*\R*/m", "", $string);
}
/**
* @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.
*
* @param $name
*
* @return mixed
*/
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 = <<