Merge pull request #768 from pradpnayak/CRM-12470
[civicrm-core.git] / xml / GenCode.php
index 55d2fe9a4b41d3253784e707513e23444e15c75f..b59c5ce6c47557ac83721731f32a4b1570ef7b22 100644 (file)
@@ -1,6 +1,18 @@
 <?php
 ini_set('include_path', '.' . PATH_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'packages' . PATH_SEPARATOR . '..');
-ini_set('memory_limit', '512M');
+// make sure the memory_limit is at least 512 MB
+$memLimitString = trim(ini_get('memory_limit'));
+$memLimitUnit   = strtolower(substr($memLimitString, -1));
+$memLimit       = (int) $memLimitString;
+switch ($memLimitUnit) {
+    case 'g': $memLimit *= 1024;
+    case 'm': $memLimit *= 1024;
+    case 'k': $memLimit *= 1024;
+}
+
+if ($memLimit >= 0 and $memLimit < 536870912) {
+    ini_set('memory_limit', '512M');
+}
 date_default_timezone_set('UTC'); // avoid php warnings if timezone is not set - CRM-10844
 
 define('CIVICRM_UF', 'Drupal');
@@ -202,7 +214,7 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
     }
 
     // TODO deal with the BAO's too ?
-    file_put_contents($this->CoreDAOCodePath . ".listAll.php", $allDAO);
+    file_put_contents($this->CoreDAOCodePath . "listAll.php", $allDAO);
   }
 
   function generateCiviTestTruncate($tables) {