Based on on parts of the monolithic Bolt\Database\IntegrityChecker class.
Author: Gawain Lynch (gawain.lynch@gmail.com)
Inheritance: implements Bolt\Storage\Database\Schema\SchemaManagerInterface
Exemplo n.º 1
0
 /**
  * Create/update database table.
  */
 public function build()
 {
     $tableName = $this->tableName;
     // User/client account table
     $this->schemaManager->registerExtensionTable(function (DbalSchema $schema) use($tableName) {
         // @codingStandardsIgnoreStart
         $table = $schema->createTable($tableName . '_account');
         $table->addColumn('guid', 'guid', []);
         $table->addColumn('resource_owner_id', 'string', ['notnull' => false, 'length' => 128]);
         $table->addColumn('password', 'string', ['notnull' => false, 'length' => 64]);
         $table->addColumn('email', 'string', ['notnull' => false, 'length' => 254]);
         $table->addColumn('enabled', 'boolean', ['default' => false]);
         $table->setPrimaryKey(['guid']);
         $table->addUniqueIndex(['resource_owner_id']);
         $table->addUniqueIndex(['email']);
         $table->addIndex(['enabled']);
         return $table;
         // @codingStandardsIgnoreEnd
     });
     // User/client provider table
     $this->schemaManager->registerExtensionTable(function (DbalSchema $schema) use($tableName) {
         // @codingStandardsIgnoreStart
         $table = $schema->createTable($tableName . '_provider');
         $table->addColumn('guid', 'guid', []);
         $table->addColumn('provider', 'string', ['length' => 64]);
         $table->addColumn('resource_owner_id', 'string', ['length' => 128]);
         $table->addColumn('refresh_token', 'string', ['notnull' => false, 'default' => null, 'length' => 128]);
         $table->addColumn('resource_owner', 'text', ['notnull' => false, 'default' => null]);
         $table->addColumn('lastupdate', 'datetime', ['notnull' => false, 'default' => null]);
         $table->setPrimaryKey(['guid']);
         $table->addIndex(['provider']);
         $table->addIndex(['resource_owner_id']);
         $table->addIndex(['refresh_token']);
         return $table;
         // @codingStandardsIgnoreEnd
     });
     // User/client provider table
     $this->schemaManager->registerExtensionTable(function (DbalSchema $schema) use($tableName) {
         // @codingStandardsIgnoreStart
         $table = $schema->createTable($tableName . '_tokens');
         $table->addColumn('access_token', 'string', ['length' => 128]);
         $table->addColumn('guid', 'guid', []);
         $table->addColumn('access_token_data', 'text', ['notnull' => false, 'default' => null]);
         $table->addColumn('expires', 'integer', ['notnull' => false, 'default' => null]);
         $table->setPrimaryKey(['access_token']);
         $table->addIndex(['guid']);
         $table->addIndex(['expires']);
         return $table;
         // @codingStandardsIgnoreEnd
     });
 }
Exemplo n.º 2
0
 /**
  * Trigger database schema checks if required.
  *
  * @param GetResponseEvent $event
  */
 protected function schemaCheck(GetResponseEvent $event)
 {
     $session = $event->getRequest()->getSession();
     $validSession = $session->isStarted() && $session->get('authentication');
     $expired = $this->schemaManager->isCheckRequired();
     if ($validSession && $expired && $this->schemaManager->isUpdateRequired()) {
         $msg = Trans::__("The database needs to be updated/repaired. Go to 'Configuration' > '<a href=\"%link%\">Check Database</a>' to do this now.", ['%link%' => $this->urlGenerator->generate('dbcheck')]);
         $this->loggerFlash->error($msg);
     }
 }
Exemplo n.º 3
0
 /**
  * Trigger database schema checks if required.
  *
  * @param GetResponseEvent $event
  */
 protected function schemaCheck(GetResponseEvent $event)
 {
     $session = $event->getRequest()->getSession();
     $validSession = $session->isStarted() && $session->get('authentication');
     $expired = $this->schemaManager->isCheckRequired();
     // Don't show the check if we're in the dbcheck already.
     $notInCheck = !in_array($event->getRequest()->get('_route'), ['dbcheck', 'dbupdate_result', 'dbupdate']);
     if ($validSession && $expired && $this->schemaManager->isUpdateRequired() && $notInCheck) {
         $msg = Trans::__("The database needs to be updated/repaired. Go to 'Configuration' > '<a href=\"%link%\">Check Database</a>' to do this now.", ['%link%' => $this->urlGenerator->generate('dbcheck')]);
         $this->loggerFlash->error($msg);
     }
 }
Exemplo n.º 4
0
 /**
  * Get the field type for a given column.
  *
  * @param string                       $name
  * @param \Doctrine\DBAL\Schema\Column $column
  */
 protected function getFieldTypeFor($name, $column)
 {
     $contentKey = $this->schemaManager->getKeyForTable($name);
     if ($contentKey && isset($this->contenttypes[$contentKey][$column->getName()])) {
         $type = $this->contenttypes[$contentKey]['fields'][$column->getName()]['type'];
     } elseif ($column->getType()) {
         $type = get_class($column->getType());
     }
     if (isset($this->typemap[$type])) {
         $type = new $this->typemap[$type]();
     } else {
         $type = new $this->typemap['text']();
     }
     return $type;
 }
Exemplo n.º 5
0
 /**
  * Set the taxonomy.
  *
  * @param string $contentKey
  * @param string $className
  * @param Table  $table
  */
 public function setTaxonomies($contentKey, $className, $table)
 {
     if (!isset($this->contenttypes[$contentKey]['taxonomy'])) {
         return;
     }
     foreach ($this->contenttypes[$contentKey]['taxonomy'] as $taxonomytype) {
         $taxonomyConfig = $this->taxonomies[$taxonomytype];
         if (isset($taxonomyConfig['alias'])) {
             $taxonomy = $taxonomyConfig['alias'];
         } else {
             $taxonomy = $taxonomytype;
         }
         $mapping = ['fieldname' => $taxonomy, 'type' => 'null', 'fieldtype' => $this->typemap['taxonomy'], 'target' => $this->schemaManager->getTableName('taxonomy')];
         $this->metadata[$className]['fields'][$taxonomy] = $mapping;
         $this->metadata[$className]['fields'][$taxonomy]['data'] = $taxonomyConfig;
     }
 }
Exemplo n.º 6
0
 /**
  * Run the checks on the tables to see if they firstly exist, then if they
  * require update.
  */
 protected function checkTables()
 {
     $fromTables = $this->manager->getInstalledTables();
     $toTables = $this->manager->getSchemaTables();
     /** @var $fromTable Table */
     foreach ($toTables as $toTableAlias => $toTable) {
         $tableName = $toTable->getName();
         if (!isset($fromTables[$toTableAlias])) {
             // Table doesn't exist. Mark it for pending creation.
             $this->pending = true;
             $this->tablesCreate[$tableName] = $toTable;
             $this->getResponse()->addTitle($tableName, sprintf('Table `%s` is not present.', $tableName));
             $this->systemLog->debug('Database table missing: ' . $tableName);
             continue;
         }
         // Table exists. Check for required updates.
         $fromTable = $fromTables[$toTableAlias];
         $this->checkTable($fromTable, $toTable);
     }
 }