Merge pull request #11642 from JKingsnorth/CRM-21739
[civicrm-core.git] / CRM / Core / CodeGen / Specification.php
index f4333ec338b566c0cc2bd65be33c897e48282c50..5d06369437a77e09d017cbd3e143d86673844206 100644 (file)
@@ -16,19 +16,25 @@ class CRM_Core_CodeGen_Specification {
    * @param string $buildVersion
    *   Which version of the schema to build.
    */
-  public function parse($schemaPath, $buildVersion) {
+  public function parse($schemaPath, $buildVersion, $verbose = TRUE) {
     $this->buildVersion = $buildVersion;
 
-    echo "Parsing schema description " . $schemaPath . "\n";
+    if ($verbose) {
+      echo "Parsing schema description " . $schemaPath . "\n";
+    }
     $dbXML = CRM_Core_CodeGen_Util_Xml::parse($schemaPath);
 
-    echo "Extracting database information\n";
+    if ($verbose) {
+      echo "Extracting database information\n";
+    }
     $this->database = &$this->getDatabase($dbXML);
 
     $this->classNames = array();
 
     # TODO: peel DAO-specific stuff out of getTables, and spec reading into its own class
-    echo "Extracting table information\n";
+    if ($verbose) {
+      echo "Extracting table information\n";
+    }
     $this->tables = $this->getTables($dbXML, $this->database);
 
     $this->resolveForeignKeys($this->tables, $this->classNames);
@@ -231,8 +237,6 @@ class CRM_Core_CodeGen_Specification {
       $this->getPrimaryKey($tableXML->primaryKey, $fields, $table);
     }
 
-    // some kind of refresh?
-    CRM_Core_Config::singleton(FALSE);
     if ($this->value('index', $tableXML)) {
       $index = array();
       foreach ($tableXML->index as $indexXML) {
@@ -242,13 +246,13 @@ class CRM_Core_CodeGen_Specification {
 
         $this->getIndex($indexXML, $fields, $index);
       }
+      CRM_Core_BAO_SchemaHandler::addIndexSignature($name, $index);
       $table['index'] = &$index;
     }
 
     if ($this->value('foreignKey', $tableXML)) {
       $foreign = array();
       foreach ($tableXML->foreignKey as $foreignXML) {
-        // print_r($foreignXML);
 
         if ($this->value('drop', $foreignXML, 0) > 0 and $this->value('drop', $foreignXML, 0) <= $this->buildVersion) {
           continue;
@@ -282,7 +286,7 @@ class CRM_Core_CodeGen_Specification {
    */
   public function getField(&$fieldXML, &$fields) {
     $name = trim((string ) $fieldXML->name);
-    $field = array('name' => $name, 'localizable' => $fieldXML->localizable);
+    $field = array('name' => $name, 'localizable' => ((bool) $fieldXML->localizable) ? 1 : 0);
     $type = (string ) $fieldXML->type;
     switch ($type) {
       case 'varchar':
@@ -361,6 +365,7 @@ class CRM_Core_CodeGen_Specification {
     $field['headerPattern'] = $this->value('headerPattern', $fieldXML);
     $field['dataPattern'] = $this->value('dataPattern', $fieldXML);
     $field['uniqueName'] = $this->value('uniqueName', $fieldXML);
+    $field['serialize'] = $this->value('serialize', $fieldXML);
     $field['html'] = $this->value('html', $fieldXML);
     if (!empty($field['html'])) {
       $validOptions = array(
@@ -554,9 +559,6 @@ class CRM_Core_CodeGen_Specification {
       $index['unique'] = TRUE;
     }
 
-    //echo "\$index = \n";
-    //print_r($index);
-
     // field array cannot be empty
     if (empty($index['field'])) {
       echo "No fields defined for index $indexName\n";