CRM-12495 - cleanup civicrm_task / task_status / project
[civicrm-core.git] / xml / GenCode.php
index d8ed559af661f59ae9220cbae6d3dc34d1d39617..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) {
@@ -210,7 +222,7 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
 
   function generateCreateSql($database, $tables, $fileName = 'civicrm.mysql') {
     echo "Generating sql file\n";
-    $this->smarty->clear_all_assign();
+    $this->reset_smarty_assignments();
     $this->smarty->assign_by_ref('database', $database);
     $this->smarty->assign_by_ref('tables', $tables);
     $dropOrder = array_reverse(array_keys($tables));
@@ -228,12 +240,12 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
 
   function generateNavigation() {
     echo "Generating navigation file\n";
-    $this->smarty->clear_all_assign();
+    $this->reset_smarty_assignments();
     file_put_contents($this->sqlCodePath . "civicrm_navigation.mysql", $this->smarty->fetch('civicrm_navigation.tpl'));
   }
 
   function generateLocalDataSql($db_version, $locales) {
-    $this->smarty->clear_all_assign();
+    $this->reset_smarty_assignments();
 
     global $tsLocale;
     $oldTsLocale = $tsLocale;
@@ -264,7 +276,7 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
   }
 
   function generateSample() {
-    $this->smarty->clear_all_assign();
+    $this->reset_smarty_assignments();
     $sample = $this->smarty->fetch('civicrm_sample.tpl');
     $sample .= $this->smarty->fetch('civicrm_acl.tpl');
     file_put_contents($this->sqlCodePath . 'civicrm_sample.mysql', $sample);
@@ -283,11 +295,10 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
   }
 
   function generateDAOs($tables) {
-    $this->smarty->clear_all_assign();
     foreach (array_keys($tables) as $name) {
       $this->smarty->clear_all_cache();
       echo "Generating $name as " . $tables[$name]['fileName'] . "\n";
-      $this->smarty->clear_all_assign();
+      $this->reset_smarty_assignments();
 
       $this->smarty->assign_by_ref('table', $tables[$name]);
       $php = $this->smarty->fetch('dao.tpl');
@@ -334,8 +345,7 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
       }
     }
 
-    $this->smarty->clear_all_cache();
-    $this->smarty->clear_all_assign();
+    $this->reset_smarty_assignments();
     $this->smarty->assign_by_ref('columns', $columns);
     $this->smarty->assign_by_ref('indices', $indices);
 
@@ -505,8 +515,10 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
   function getTable($tableXML, &$database, &$tables) {
     $name = trim((string ) $tableXML->name);
     $klass = trim((string ) $tableXML->class);
-    $base = $this->value('base', $tableXML) . '/DAO/';
-    $pre = str_replace('/', '_', $base);
+    $base = $this->value('base', $tableXML);
+    $sourceFile = "xml/schema/{$base}/{$klass}.xml";
+    $daoPath = "{$base}/DAO/";
+    $pre = str_replace('/', '_', $daoPath);
     $this->classNames[$name] = $pre . $klass;
 
     $localizable = FALSE;
@@ -519,7 +531,8 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
 
     $table = array(
       'name' => $name,
-      'base' => $base,
+      'base' => $daoPath,
+      'sourceFile' => $sourceFile,
       'fileName' => $klass . '.php',
       'objectName' => $klass,
       'labelName' => substr($name, 8),
@@ -926,4 +939,13 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
     }
     return 'CRM_Utils_Type::HUGE';
   }
+
+  /**
+   * Clear the smarty cache and assign default values
+   */
+  function reset_smarty_assignments() {
+    $this->smarty->clear_all_assign();
+    $this->smarty->clear_all_cache();
+    $this->smarty->assign('generated', "DO NOT EDIT.  Generated by " . basename(__FILE__));
+  }
 }