/**
  * Transforms the XML from Adodb XML into
  * Doctrine DBAL Schema.
  */
 public function parse(\Concrete\Core\Database\Connection\Connection $db)
 {
     $filter = null;
     if ($this->ignoreExistingTables) {
         $filter = function ($tableName) use($db) {
             return $db->tableExists($tableName) ? false : true;
         };
     }
     return \DoctrineXml\Parser::fromDocument($this->rawXML->asXML(), $db->getDatabasePlatform(), true, false, $filter);
 }
 public function parse($definition, \Concrete\Core\Database\Connection\Connection $db)
 {
     $schema = new \Doctrine\DBAL\Schema\Schema();
     foreach ($definition as $tableName => $details) {
         if ($db->tableExists($tableName)) {
             continue;
         }
         $table = $schema->createTable($tableName);
         if (isset($details['columns'])) {
             $table = $this->addColumns($table, $details['columns']);
         } else {
             throw new \Exception(t('Invalid column definition: %s in table %s', var_export($details, true), $tableName));
         }
         $table->setPrimaryKey($details['primary']);
     }
     return $schema;
 }
Beispiel #3
0
 protected function _getColumnOptions(\Concrete\Core\Database\Connection\Connection $db, \SimpleXMLElement $column)
 {
     $type = strtoupper((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;
         }
     }
     switch ($type) {
         case 'X':
             $options['length'] = 65535;
             // this means 'X' will result in a 'TEXT' column
             break;
         case 'X2':
             // no length limitation -> this means 'X2' will result in a 'LONGTEXT' column
             break;
     }
     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;
 }
 /**
  * Create EntityManager
  * 
  * @param Connection $connection
  * @return \Doctrine\ORM\EntityManager
  */
 public function create(Connection $connection)
 {
     // Get config with containing all metadata drivers
     $configuration = $this->configFactory->getConfiguration();
     // Get orm event manager
     $eventManager = $connection->getEventManager();
     // Pass the database connection, the orm config and the event manager
     // to the concrete5 event system so packages can hook in to the process
     // and alter the values
     $event = new \Symfony\Component\EventDispatcher\GenericEvent();
     $event->setArgument('connection', $connection);
     $event->setArgument('configuration', $configuration);
     $event->setArgument('eventManager', $eventManager);
     Events::dispatch('on_entity_manager_configure', $event);
     // Reasign the values from the dispatched event
     $conn = $event->getArgument('connection');
     $config = $event->getArgument('configuration');
     $evm = $event->getArgument('eventManager');
     // Inject the orm eventManager into the entityManager so orm events
     // can be triggered.
     return EntityManager::create($conn, $config, $evm);
 }
 /**
  * Store a path in the database against a storage location for a file version and a thumbnail handle
  *
  * @param $path
  * @param $file_id
  * @param $version_id
  * @param $storage_location_id
  * @param $thumbnail_handle
  */
 protected function storePath($path, $file_id, $version_id, $storage_location_id, $thumbnail_handle)
 {
     $this->connection->insert('FileImageThumbnailPaths', array('path' => $path, 'fileID' => $file_id, 'fileVersionID' => $version_id, 'storageLocationID' => $storage_location_id, 'thumbnailTypeHandle' => $thumbnail_handle));
 }