Merge pull request #1707 from lcdservices/CRM-13455
[civicrm-core.git] / xml / GenCode.php
index a2a5ebac7ab62f8d98169b033607770caaa0ab58..043850e92eb05b12fff3287c3d7dd95517f72ab1 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');
@@ -129,7 +141,7 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
       exit();
     }
 
-    $this->generateTemplateVersion($argVersion);
+    $this->generateTemplateVersion($db_version);
 
     $this->setupCms($argCms, $db_version);
 
@@ -343,16 +355,8 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
     $this->beautifier->save();
   }
 
-  function generateTemplateVersion($argVersion) {
-    // add the Subversion revision to templates
-    // use svnversion if the version was not specified explicitely on the commandline
-    if (isset($argVersion) and $argVersion != '') {
-      $svnversion = $argVersion;
-    }
-    else {
-      $svnversion = `svnversion .`;
-    }
-    file_put_contents($this->tplCodePath . "/CRM/common/version.tpl", $svnversion);
+  function generateTemplateVersion($dbVersion) {
+    file_put_contents($this->tplCodePath . "/CRM/common/version.tpl", $dbVersion);
   }
 
   function findLocales() {
@@ -702,15 +706,33 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
     $field['dataPattern'] = $this->value('dataPattern', $fieldXML);
     $field['uniqueName'] = $this->value('uniqueName', $fieldXML);
     $field['pseudoconstant'] = $this->value('pseudoconstant', $fieldXML);
-    if(!empty($fieldXML->pseudoconstant)){
+    if(!empty($field['pseudoconstant'])){
       //ok this is a bit long-winded but it gets there & is consistent with above approach
       $field['pseudoconstant'] = array();
-      $validOptions = array('name', 'optionGroupName', 'table', 'keyColumn', 'labelColumn','class');
-      foreach ($validOptions as $pseudoOption){
+      $validOptions = array(
+        // Fields can specify EITHER optionGroupName OR table, not both
+        // (since declaring optionGroupName means we are using the civicrm_option_value table)
+        'optionGroupName',
+        'table',
+        // If table is specified, keyColumn and labelColumn are also required
+        'keyColumn',
+        'labelColumn',
+        // Non-translated machine name for programmatic lookup. Defaults to 'name' if that column exists
+        'nameColumn',
+        // Where clause snippet (will be joined to the rest of the query with AND operator)
+        'condition',
+      );
+      foreach ($validOptions as $pseudoOption) {
         if(!empty($fieldXML->pseudoconstant->$pseudoOption)){
           $field['pseudoconstant'][$pseudoOption] = $this->value($pseudoOption, $fieldXML->pseudoconstant);
         }
       }
+      // For now, fields that have option lists that are not in the db can simply
+      // declare an empty pseudoconstant tag and we'll add this placeholder.
+      // That field's BAO::buildOptions fn will need to be responsible for generating the option list
+      if (empty($field['pseudoconstant'])) {
+        $field['pseudoconstant'] = 'not in database';
+      }
     }
     $fields[$name] = &$field;
   }