public static function getComponentsFromFile($crmFolderDir) {
$components = array();
//traverse CRM folder and check for Info file
- if (is_dir($crmFolderDir)) {
- $dir = opendir($crmFolderDir);
+ if (is_dir($crmFolderDir) && $dir = opendir($crmFolderDir)) {
while ($subDir = readdir($dir)) {
// skip the extensions diretory since it has an Info.php file also
if ($subDir == 'Extension') {
// check which ones are available; add them to $all if not there already
$config = CRM_Core_Config::singleton();
$codes = array();
- if (is_dir($config->gettextResourceDir)) {
- $dir = opendir($config->gettextResourceDir);
+ if (is_dir($config->gettextResourceDir) && $dir = opendir($config->gettextResourceDir)) {
while ($filename = readdir($dir)) {
if (preg_match('/^[a-z][a-z]_[A-Z][A-Z]$/', $filename)) {
$codes[] = $filename;
//CRM-7123 -lets activate needful languages.
$config = CRM_Core_Config::singleton();
$locales = array();
- if (is_dir($config->gettextResourceDir)) {
- $dir = opendir($config->gettextResourceDir);
+ if (is_dir($config->gettextResourceDir) && $dir = opendir($config->gettextResourceDir)) {
while ($filename = readdir($dir)) {
if (preg_match('/^[a-z][a-z]_[A-Z][A-Z]$/', $filename)) {
$locales[$filename] = $filename;
throw new Exception("Overly broad deletion");
}
- if ($sourcedir = @opendir($target)) {
+ if ($sourcedir = opendir($target)) {
while (FALSE !== ($sibling = readdir($sourcedir))) {
if (!in_array($sibling, $exceptions)) {
$object = $target . DIRECTORY_SEPARATOR . $sibling;
* @param $source
* @param $destination
*/
- public static function copyDir($source, $destination) {
- $dir = opendir($source);
- @mkdir($destination);
- while (FALSE !== ($file = readdir($dir))) {
- 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);
+ static function copyDir($source, $destination) {
+ if ($dir = opendir($source)) {
+ @mkdir($destination);
+ while (FALSE !== ($file = readdir($dir))) {
+ 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($dir);
}
- closedir($dir);
}
/**
*/
public static function getFilesByExtension($path, $ext) {
$path = self::addTrailingSlash($path);
- $dh = opendir($path);
- $files = array();
- while (FALSE !== ($elem = readdir($dh))) {
- if (substr($elem, -(strlen($ext) + 1)) == '.' . $ext) {
- $files[] .= $path . $elem;
+ if ($dh = opendir($path)) {
+ $files = array();
+ while (FALSE !== ($elem = readdir($dh))) {
+ if (substr($elem, -(strlen($ext) + 1)) == '.' . $ext) {
+ $files[] .= $path . $elem;
+ }
}
+ closedir($dh);
+ return $files;
}
- closedir($dh);
- return $files;
}
/**
}
}
}
- $dh = opendir($subdir);
- if ($dh) {
+ if ($dh = opendir($subdir)) {
while (FALSE !== ($entry = readdir($dh))) {
$path = $subdir . DIRECTORY_SEPARATOR . $entry;
if ($entry{0} == '.') {
//lets remove sript name to reduce one iteration.
array_pop($pathVars);
- //CRM-7429 --do check for upper most 'includes' dir,
- //which would effectually work for multisite installation.
+ // CRM-7429 -- do check for uppermost 'includes' dir, which would
+ // work for multisite installation.
do {
$cmsRoot = $firstVar . '/' . implode('/', $pathVars);
$cmsIncludePath = "$cmsRoot/includes";
- //stop as we found bootstrap.
- if (@opendir($cmsIncludePath) &&
- file_exists("$cmsIncludePath/bootstrap.inc")
- ) {
+ // Stop if we find bootstrap.
+ //
+ // @TODO What is opendir() here for?
+ if (opendir($cmsIncludePath) && file_exists("$cmsIncludePath/bootstrap.inc")) {
$valid = TRUE;
break;
}
do {
$cmsRoot = $firstVar . '/' . implode('/', $pathVars);
$cmsIncludePath = "$cmsRoot/includes";
- //stop as we found bootstrap.
- if (@opendir($cmsIncludePath) &&
- file_exists("$cmsIncludePath/bootstrap.inc")
- ) {
+ // Stop if we found bootstrap.
+ //
+ // @TODO What is opendir() here for?
+ if (opendir($cmsIncludePath) && file_exists("$cmsIncludePath/bootstrap.inc")) {
$valid = TRUE;
break;
}
*/
public function validInstallDir($dir) {
$includePath = "$dir/wp-includes";
- if (
- @opendir($includePath) &&
- file_exists("$includePath/version.php")
- ) {
+ if (opendir($includePath) && file_exists("$includePath/version.php")) {
return TRUE;
}
return FALSE;