From 948d11bf08078fe173f573a9873561736610bc5f Mon Sep 17 00:00:00 2001 From: Chris Burgess Date: Mon, 29 Dec 2014 07:33:42 +1300 Subject: [PATCH] Merge fix - CRM-15764 --- CRM/Core/Component.php | 3 +- CRM/Core/I18n.php | 3 +- CRM/Upgrade/Incremental/php/ThreeThree.php | 3 +- CRM/Utils/File.php | 43 +++++++++++----------- CRM/Utils/System/Drupal.php | 12 +++--- CRM/Utils/System/Drupal6.php | 8 ++-- CRM/Utils/System/WordPress.php | 5 +-- 7 files changed, 36 insertions(+), 41 deletions(-) diff --git a/CRM/Core/Component.php b/CRM/Core/Component.php index 5987f59360..84dd89d535 100644 --- a/CRM/Core/Component.php +++ b/CRM/Core/Component.php @@ -442,8 +442,7 @@ class CRM_Core_Component { 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') { diff --git a/CRM/Core/I18n.php b/CRM/Core/I18n.php index 79e7255a30..8fef7866cc 100644 --- a/CRM/Core/I18n.php +++ b/CRM/Core/I18n.php @@ -131,8 +131,7 @@ class CRM_Core_I18n { // 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; diff --git a/CRM/Upgrade/Incremental/php/ThreeThree.php b/CRM/Upgrade/Incremental/php/ThreeThree.php index b23aad77cf..f7a56beb17 100644 --- a/CRM/Upgrade/Incremental/php/ThreeThree.php +++ b/CRM/Upgrade/Incremental/php/ThreeThree.php @@ -292,8 +292,7 @@ WHERE id = %2 //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; diff --git a/CRM/Utils/File.php b/CRM/Utils/File.php index 4931e00ad4..f435ad175e 100644 --- a/CRM/Utils/File.php +++ b/CRM/Utils/File.php @@ -140,7 +140,7 @@ class CRM_Utils_File { 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; @@ -175,20 +175,21 @@ class CRM_Utils_File { * @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); } /** @@ -392,15 +393,16 @@ class CRM_Utils_File { */ 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; } /** @@ -610,8 +612,7 @@ HTACCESS; } } } - $dh = opendir($subdir); - if ($dh) { + if ($dh = opendir($subdir)) { while (FALSE !== ($entry = readdir($dh))) { $path = $subdir . DIRECTORY_SEPARATOR . $entry; if ($entry{0} == '.') { diff --git a/CRM/Utils/System/Drupal.php b/CRM/Utils/System/Drupal.php index 6cd0e7fd85..06cb699977 100644 --- a/CRM/Utils/System/Drupal.php +++ b/CRM/Utils/System/Drupal.php @@ -778,15 +778,15 @@ AND u.status = 1 //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; } diff --git a/CRM/Utils/System/Drupal6.php b/CRM/Utils/System/Drupal6.php index 9c62e3df0d..665a7c4595 100644 --- a/CRM/Utils/System/Drupal6.php +++ b/CRM/Utils/System/Drupal6.php @@ -727,10 +727,10 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { 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; } diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index cc28477347..10169a1362 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -509,10 +509,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { */ 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; -- 2.25.1