X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=xml%2FGenCode.php;h=043850e92eb05b12fff3287c3d7dd95517f72ab1;hb=d080148e6e512e4e2b361127fc1a71d15deb40d7;hp=2306149725bdcc9bff382f42e0eae00427b338d2;hpb=3d519e1c57aa496d16003c629df1ab22d5beb062;p=civicrm-core.git diff --git a/xml/GenCode.php b/xml/GenCode.php index 2306149725..043850e92e 100644 --- a/xml/GenCode.php +++ b/xml/GenCode.php @@ -1,6 +1,18 @@ = 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); @@ -187,22 +199,9 @@ Alternatively you can get a version of CiviCRM that matches your PHP version } function generateListAll($tables) { - $allDAO = "CoreDAOCodePath . "listAll.php", $allDAO); + $this->smarty->clear_all_assign(); + $this->smarty->assign('tables', $tables); + file_put_contents($this->CoreDAOCodePath . "AllCoreTables.php", $this->smarty->fetch('listAll.tpl')); } function generateCiviTestTruncate($tables) { @@ -223,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)); @@ -241,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; @@ -277,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); @@ -296,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'); @@ -347,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); @@ -358,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() { @@ -518,8 +507,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; @@ -532,7 +523,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), @@ -598,6 +590,19 @@ Alternatively you can get a version of CiviCRM that matches your PHP version $table['foreignKey'] = &$foreign; } + if ($this->value('dynamicForeignKey', $tableXML)) { + $dynamicForeign = array(); + foreach ($tableXML->dynamicForeignKey as $foreignXML) { + if ($this->value('drop', $foreignXML, 0) > 0 and $this->value('drop', $foreignXML, 0) <= $this->buildVersion) { + continue; + } + if ($this->value('add', $foreignXML, 0) <= $this->buildVersion) { + $this->getDynamicForeignKey($foreignXML, $dynamicForeign, $name); + } + } + $table['dynamicForeignKey'] = $dynamicForeign; + } + $tables[$name] = &$table; return; } @@ -701,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; } @@ -841,6 +864,15 @@ Alternatively you can get a version of CiviCRM that matches your PHP version $foreignKeys[$name] = &$foreignKey; } + function getDynamicForeignKey(&$foreignXML, &$dynamicForeignKeys) { + $foreignKey = array( + 'idColumn' => trim($foreignXML->idColumn), + 'typeColumn' => trim($foreignXML->typeColumn), + 'key' => trim($this->value('key', $foreignXML)), + ); + $dynamicForeignKeys[] = $foreignKey; + } + protected function value($key, &$object, $default = NULL) { if (isset($object->$key)) { return (string ) $object->$key; @@ -917,4 +949,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__)); + } }