/** * Read and parse. * * @param $schemaPath * @param string $buildVersion which version of the schema to build */ function parse($schemaPath, $buildVersion) { $this->buildVersion = $buildVersion; echo "Parsing schema description " . $schemaPath . "\n"; $dbXML = CRM_Core_CodeGen_Util_Xml::parse($schemaPath); // print_r( $dbXML ); echo "Extracting database information\n"; $this->database =& $this->getDatabase($dbXML); // print_r( $this->database ); $this->classNames = array(); # TODO: peel DAO-specific stuff out of getTables, and spec reading into its own class echo "Extracting table information\n"; $this->tables = $this->getTables($dbXML, $this->database); $this->resolveForeignKeys($this->tables, $this->classNames); $this->tables = $this->orderTables($this->tables); // add archive tables here $archiveTables = array(); foreach ($this->tables as $name => $table) { if ($table['archive'] == 'true') { $name = 'archive_' . $table['name']; $table['name'] = $name; $table['archive'] = 'false'; if (isset($table['foreignKey'])) { foreach ($table['foreignKey'] as $fkName => $fkValue) { if ($this->tables[$fkValue['table']]['archive'] == 'true') { $table['foreignKey'][$fkName]['table'] = 'archive_' . $table['foreignKey'][$fkName]['table']; $table['foreignKey'][$fkName]['uniqName'] = str_replace('FK_', 'FK_archive_', $table['foreignKey'][$fkName]['uniqName']); } } $archiveTables[$name] = $table; } } } }
/** * @param $CoreDAOCodePath * @param $sqlCodePath * @param $phpCodePath * @param $tplCodePath * @param $IGNORE * @param $argCms * @param $argVersion * @param $schemaPath * @param $digestPath */ public function __construct($CoreDAOCodePath, $sqlCodePath, $phpCodePath, $tplCodePath, $IGNORE, $argCms, $argVersion, $schemaPath, $digestPath) { $this->CoreDAOCodePath = $CoreDAOCodePath; $this->sqlCodePath = $sqlCodePath; $this->phpCodePath = $phpCodePath; $this->tplCodePath = $tplCodePath; $this->digestPath = $digestPath; $this->sourceDigest = NULL; // default cms is 'drupal', if not specified $this->cms = isset($argCms) ? strtolower($argCms) : 'drupal'; $versionFile = $this->phpCodePath . "/xml/version.xml"; $versionXML = CRM_Core_CodeGen_Util_Xml::parse($versionFile); $this->db_version = $versionXML->version_no; $this->buildVersion = preg_replace('/^(\\d{1,2}\\.\\d{1,2})\\.(\\d{1,2}|\\w{4,7})$/i', '$1', $this->db_version); if (isset($argVersion)) { // change the version to that explicitly passed, if any $this->db_version = $argVersion; } $this->schemaPath = $schemaPath; }