CRM-20809 : Create .gitignore file to ignore extensions cache files
authorJitendra Purohit <jitendra@fuzion.co.nz>
Tue, 4 Jul 2017 09:11:31 +0000 (14:41 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Tue, 4 Jul 2017 09:30:28 +0000 (15:00 +0530)
CRM/Extension/System.php
tools/extensions/.gitignore

index 0601939855001dfde9ba1305d1d9b2c172e0e993..c8ea7e1274663c87ed969c6552d5ce8909339be8 100644 (file)
@@ -225,12 +225,31 @@ class CRM_Extension_System {
       $cacheDir = NULL;
       if ($this->getDefaultContainer()) {
         $cacheDir = $this->getDefaultContainer()->getBaseDir() . DIRECTORY_SEPARATOR . 'cache';
+        $this->createGitIgnoreForCacheFiles($this->getDefaultContainer()->getBaseDir());
       }
       $this->browser = new CRM_Extension_Browser($this->getRepositoryUrl(), '', $cacheDir);
     }
     return $this->browser;
   }
 
+  /**
+   * Create .gitignore to remove cache dir.
+   *
+   * @param string $extPath
+   */
+  public function createGitIgnoreForCacheFiles($extPath) {
+    if (!empty($extPath)) {
+      $path = $extPath . DIRECTORY_SEPARATOR . '.gitignore';
+      if (file_exists($path)) {
+        //Return if cache dir is already ignored.
+        if (in_array('cache', explode("\n", file_get_contents($path)))) {
+          return;
+        }
+      }
+      file_put_contents($path, "cache\n", FILE_APPEND);
+    }
+  }
+
   /**
    * Get the service for loading code from remotely-available extensions
    *
index 05d4332dde0f7f616e95e001d891cac187da3284..8ca96b755607d1a2292c61ca1ab566cc5d977657 100644 (file)
@@ -3,3 +3,4 @@ civisualize
 civivolunteer
 org.civicoop.civirules
 org.civicrm.angularprofiles
+cache