Merge fix - CRM-15764
authorChris Burgess <chris@giantrobot.co.nz>
Sun, 28 Dec 2014 18:33:42 +0000 (07:33 +1300)
committerRohan Katkar <rohan.katkar@webaccessglobal.com>
Thu, 1 Jan 2015 11:27:06 +0000 (16:57 +0530)
CRM/Core/Component.php
CRM/Core/I18n.php
CRM/Upgrade/Incremental/php/ThreeThree.php
CRM/Utils/File.php
CRM/Utils/System/Drupal.php
CRM/Utils/System/Drupal6.php
CRM/Utils/System/WordPress.php

index 5987f5936063a9c306a32d67b4a47399d8eff747..84dd89d535c62da054c387f75d23161c32a38398 100644 (file)
@@ -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') {
index 79e7255a304e3e4ee191499b9b6aafdd7ce1aab8..8fef7866cc29aee35257c8ea2018493b316595f6 100644 (file)
@@ -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;
index b23aad77cf0047d59e08e738ef38f844a4a5a21d..f7a56beb17cb83fe2550d2c2d6a18ae735bf98fc 100644 (file)
@@ -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;
index 4931e00ad40f18a6edef9626e25097d9cf16de64..f435ad175e5d04928dd8e5a1d3d9d7fc61135a38 100644 (file)
@@ -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} == '.') {
index 6cd0e7fd8568116ca930db6c0cec7a4eecb89c1d..06cb699977bde8bd8fa29691f15d3c39b99a9ae1 100644 (file)
@@ -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;
       }
index 9c62e3df0d844a7295c3592dd396f195fbfeaa96..665a7c459563a86ba0b9d647f2639e97b91921bf 100644 (file)
@@ -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;
       }
index cc28477347309e09277e27bb201ea87fe8175f09..10169a13626ac811e7a29cdf52d95f36bbd6dcb5 100644 (file)
@@ -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;