Пример #1
0
 public function parse($definition, \Concrete\Core\Database\Connection $db)
 {
     $schema = new \Doctrine\DBAL\Schema\Schema();
     foreach ($definition as $tableName => $details) {
         if ($db->tableExists($tableName)) {
             continue;
         }
         $table = $schema->createTable($tableName);
         $table = $this->addColumns($table, $details['columns']);
         $table->setPrimaryKey($details['primary']);
     }
     return $schema;
 }
Пример #2
0
 protected function _getColumnOptions(\Concrete\Core\Database\Connection $db, \SimpleXMLElement $column)
 {
     $type = (string) $column['type'];
     $size = (string) $column['size'];
     $options = array();
     if ($size) {
         if (in_array($type, array('N', 'F'))) {
             $precision = explode('.', $size);
             $options['precision'] = $precision[0];
             $options['scale'] = $precision[1];
         } else {
             $options['length'] = $size;
         }
     }
     if ($column->unsigned || $column->UNSIGNED) {
         $options['unsigned'] = true;
     }
     if ($column->default) {
         if (isset($column->default['value'])) {
             $options['default'] = (string) $column->default['value'];
         }
         if (isset($column->default['VALUE'])) {
             $options['default'] = (string) $column->default['VALUE'];
         }
     }
     if ($column->DEFAULT) {
         if (isset($column->DEFAULT['value'])) {
             $options['default'] = (string) $column->DEFAULT['value'];
         }
         if (isset($column->DEFAULT['VALUE'])) {
             $options['default'] = (string) $column->DEFAULT['VALUE'];
         }
     }
     if ($column->notnull || $column->NOTNULL) {
         $options['notnull'] = true;
     } else {
         $options['notnull'] = false;
     }
     if ($column->autoincrement || $column->AUTOINCREMENT) {
         $options['autoincrement'] = true;
     }
     if ($type == 'T' && isset($column->deftimestamp) || isset($column->DEFTIMESTAMP)) {
         $platform = $db->getDatabasePlatform();
         $options['default'] = $platform->getCurrentTimestampSQL();
         $options['version'] = true;
     }
     return $options;
 }