CRM-12495 - cleanup civicrm_task / task_status / project
[civicrm-core.git] / xml / GenCode.php
index e061552eb404c8d741d0c65f86a8402269865e8a..ea7a62081bb1b6a7562e4095bc4b33d0668378b4 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');
@@ -189,7 +201,7 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
   function generateListAll($tables) {
     $this->smarty->clear_all_assign();
     $this->smarty->assign('tables', $tables);
-    file_put_contents($this->CoreDAOCodePath . "../AllCoreTables.php", $this->smarty->fetch('listAll.tpl'));
+    file_put_contents($this->CoreDAOCodePath . "AllCoreTables.php", $this->smarty->fetch('listAll.tpl'));
   }
 
   function generateCiviTestTruncate($tables) {