Save schema file.

@param array $schema
@param array $settings

@throws Exception

@return void
497601
protected function saveSchemaFile(array $schema, array $settings): void
    {
        $schemaFile = $this->getSchemaFilename($settings);
        $this->output->writeln(sprintf('Save schema file: %s', basename($schemaFile)));
        $fileExt = pathinfo($schemaFile, PATHINFO_EXTENSION);

        if ($fileExt == 'php') {
            $content = var_export($schema, true);
            $content = "<?php\n\nreturn " . $content . ';';
        } elseif ($fileExt == 'json') {
            $content = json_encode($schema, JSON_PRETTY_PRINT);
        } else {
            throw new InvalidArgumentException(sprintf('Invalid schema file extension: %s', $fileExt));
        }

        file_put_contents($schemaFile, $content);
    }
453869
public function ApplyRulesBySchema($Schema) {
      $this->_Schema = $Schema->Fetch();
      foreach($this->_Schema as $Field => $Properties) {
         // Create an array to hold rules for this field
         $RuleNames = array();

         if ($Properties->AutoIncrement === TRUE) {
            // Skip all rules for auto-incrementing integer columns - they will
         // not be inserted or updated.
         } else {
            // Force non-null fields without defaults to be required.
            if ($Properties->AllowNull === FALSE && $Properties->Default == '') {
               $RuleNames[] = 'Required';
               $this->_RequiredSchemaFields[] = $Field;
            }

            // Force other constraints based on field type.
            switch($Properties->Type) {
               case 'bit':
               case 'bool':
               case 'boolean':
                  $RuleNames[] = 'Boolean';
                  break;

               case 'tinyint':
               case 'smallint':
               case 'mediumint':
               case 'int':
               case 'integer':
               case 'bigint':
                  $RuleNames[] = 'Integer';
                  break;

               case 'double':
               case 'float':
               case 'real':
               case 'decimal':
               case 'dec':
               case 'numeric':
               case 'fixed':
                  $RuleNames[] = 'Decimal';
                  break;

               case 'date':
               case 'datetime':
                  $RuleNames[] = 'Date';
                  break;
               case 'time':
                  $RuleNames[] = 'Time';
                  break;
               case 'year':
                  $RuleNames[] = 'Year';
                  break;
               case 'timestamp':
                  $RuleNames[] = 'Timestamp';
                  break;

               case 'char':
               case 'varchar':
               case 'tinyblob':
               case 'blob':
               case 'mediumblob':
               case 'longblob':
               case 'tinytext':
               case 'mediumtext':
               case 'text':
               case 'longtext':
               case 'binary':
               case 'varbinary':
                  if ($Properties->Length != '')
                     $RuleNames[] = 'Length';
                  break;

               case 'enum':
               case 'set':
                  $RuleNames[] = 'Enum';
                  break;
            }
            
            if ($Field == 'Format') {
               $RuleNames[] = 'Format';
            }
         }
         // Assign the rules to the field.
         // echo '<div>Field: '.$Field.'</div>';
         // print_r($RuleNames);
         $this->_ApplyRule($Field, $RuleNames);
      }
   }
535033
public function upgradeSchema(Schema $schema)
    {
        try {
            $table = $schema->getTable('SystemDatabaseQueryLog');
            $table->addColumn('ID', 'integer', ['unsigned' => true, 'autoincrement' => true]);
            $table->setPrimaryKey(['ID']);
        } catch (\Exception $e) {
        }
    }
237859
public function Save($FormPostValues, $Settings = FALSE) {
      $CurrentBanID = GetValue('BanID', $FormPostValues);

      // Get the current ban before saving.
      if ($CurrentBanID)
         $CurrentBan = $this->GetID($CurrentBanID, DATASET_TYPE_ARRAY);
      else
         $CurrentBan = NULL;
    
      $this->SetCounts($FormPostValues);
      $BanID = parent::Save($FormPostValues, $Settings);
      $FormPostValues['BanID'] = $BanID;

      $this->ApplyBan($FormPostValues, $CurrentBan);
   }
617910
function generateSchemaFile( $schema, $params = array() )
    {
        $sql = '';

        $i = 0;
        foreach ( $schema as $table => $tableDef )
        {
            // Skip the info structure, this is not a table
            if ( $table == '_info' )
                continue;

            if ( $i > 0 )
                $sql .= "\n\n";
            $sql .= $this->generateTableSchema( $table, $tableDef, $params );
            ++$i;
        }

        return $sql;
    }
1161724
protected function addConversionToSchema(array $schema): array
    {
        if (isset($schema['definitions']['conversionItem'])) {
            $modules = Utility::getModules();
            if (!empty($modules)) {
                $rule = $schema['definitions']['conversionItem']['properties']['modules']['additionalProperties']['anyOf'][0];
                foreach ($modules as $module) {
                    $schema['definitions']['conversionItem']['properties']['modules']['additionalProperties'] = false;
                    $schema['definitions']['conversionItem']['properties']['modules']['properties'][$module] = $rule;
                }
            }
        }

        return $schema;
    }
240493
public function create($schema, $ifNotExists = true, $options = [])
    {
        $defaultOptions = [
            'auto_increment' => 1,
            'engine' => 'InnoDB',
            'charset' => 'utf8mb4',
            'collate' => 'utf8mb4_unicode_ci'
        ];

        $options = array_merge($defaultOptions, $options);
        $schema = $this->callSchema($schema);
        $columns = [];
        $primary = [];

        foreach ($schema->getColumns() as $column) {
            $column = $this->prepareColumn($column);

            $columns[$column->getName()] = MysqlGrammar::build(
                $column->getType() . $column->getLength(),
                $column->getSigned() ? '' : 'UNSIGNED',
                $column->getAllowNull() ? '' : 'NOT NULL',
                $column->getDefault() !== false
                    ? 'DEFAULT ' . $this->db->getQuery(true)->validValue($column->getDefault())
                    : '',
                $column->getAutoIncrement() ? 'AUTO_INCREMENT' : '',
                $column->getComment() ? 'COMMENT ' . $this->db->quote($column->getComment()) : '',
                $column->getSuffix()
            );

            // Primary
            if ($column->isPrimary()) {
                $primary[] = $column->getName();
            }
        }

        $keys = [];

        foreach ($schema->getIndexes() as $index) {
            $name = $index->getName();
            $keys[$name] = [
                'type' => $index->getType(),
                'name' => $name,
                'columns' => $index->getColumns(),
                'comment' => $index->getComment() ? 'COMMENT ' . $this->db->quote($index->getComment()) : '',
            ];
        }

        $query = MysqlGrammar::createTable(
            $this->getName(),
            $columns,
            $primary,
            $keys,
            $options['auto_increment'],
            $ifNotExists,
            $options['engine'],
            $options['charset'],
            $options['collate']
        );

        $this->db->setQuery($query)->execute();

        return $this->reset();
    }
1370665
private function constructLdapSchema($schema)
    {
        // Set all the LDAP attributes
        $this->setAttribute('l', $schema->getAttribute('address_city'));

        $this->setAttribute('postalCode', $schema->getAttribute('address_code'));

        $this->setAttribute('c', $schema->getAttribute('address_country'));

        $this->setAttribute('postOfficeBox', $schema->getAttribute('address_pobox'));

        $this->setAttribute('st', $schema->getAttribute('address_state'));

        $this->setAttribute('streetAddress', $schema->getAttribute('address_street'));

        $this->setAttribute('company', $schema->getAttribute('company'));

        $this->setAttribute('pwdLastSet', ($schema->getAttribute('change_password') == 0) ? -1 : 0);

        $this->setAttribute('department', $schema->getAttribute('department'));

        $this->setAttribute('description', $schema->getAttribute('description'));

        $this->setAttribute('displayName', $schema->getAttribute('display_name'));

        $this->setAttribute('mail', $schema->getAttribute('email'));

        $this->setAttribute('employeeId', $schema->getAttribute('employee_id'));

        $this->setAttribute('accountExpires', $schema->getAttribute('expires'));

        $this->setAttribute('givenName', $schema->getAttribute('firstname'));

        $this->setAttribute('homeDirectory', $schema->getAttribute('home_directory'));

        $this->setAttribute('homeDrive', $schema->getAttribute('home_drive'));

        $this->setAttribute('initials', $schema->getAttribute('initials'));

        $this->setAttribute('userPrincipalName', $schema->getAttribute('logon_name'));

        $this->setAttribute('manager', $schema->getAttribute('manager'));

        $this->setAttribute('physicalDeliveryOfficeName', $schema->getAttribute('office'));

        $this->setAttribute('unicodePwd', $schema->getAttribute('password'));

        $this->setAttribute('profilepath', $schema->getAttribute('profile_path'));

        $this->setAttribute('scriptPath', $schema->getAttribute('script_path'));

        $this->setAttribute('sn', $schema->getAttribute('surname'));

        $this->setAttribute('title', $schema->getAttribute('title'));

        $this->setAttribute('telephoneNumber', $schema->getAttribute('telephone'));

        $this->setAttribute('mobile', $schema->getAttribute('mobile'));

        $this->setAttribute('pager', $schema->getAttribute('pager'));

        $this->setAttribute('ipphone', $schema->getAttribute('ipphone'));

        $this->setAttribute('wWWHomePage', $schema->getAttribute('web_page'));

        $this->setAttribute('facsimileTelephoneNumber', $schema->getAttribute('fax'));

        $this->setAttribute('userAccountControl', $schema->getAttribute('enabled'));

        $this->setAttribute('homephone', $schema->getAttribute('homephone'));

        // Distribution List specific schema
        $this->setAttribute('dlMemSubmitPerms', $schema->getAttribute('group_sendpermission'));

        $this->setAttribute('dlMemRejectPerms', $schema->getAttribute('group_rejectpermission'));

        // Exchange Schema
        $this->setAttribute('homeMDB', $schema->getAttribute('exchange_homemdb'));

        $this->setAttribute('mailNickname', $schema->getAttribute('exchange_mailnickname'));

        $this->setAttribute('proxyAddresses', $schema->getAttribute('exchange_proxyaddress'));

        $this->setAttribute('mDBUseDefaults', $schema->getAttribute('exchange_usedefaults'));

        $this->setAttribute('msExchPoliciesExcluded', $schema->getAttribute('exchange_policyexclude'));

        $this->setAttribute('msExchPoliciesIncluded', $schema->getAttribute('exchange_policyinclude'));

        $this->setAttribute('showInAddressBook', $schema->getAttribute('exchange_addressbook'));

        $this->setAttribute('altRecipient', $schema->getAttribute('exchange_altrecipient'));

        $this->setAttribute('deliverAndRedirect', $schema->getAttribute('exchange_deliverandredirect'));

        // This schema is designed for contacts
        $this->setAttribute('msExchHideFromAddressLists', $schema->getAttribute('exchange_hidefromlists'));

        $this->setAttribute('targetAddress', $schema->getAttribute('contact_email'));

        return $this;
    }
465439
protected function _setSchemaCache($model = null, $schema = null) {
		if (empty($model)) {
			return;
		}

		$this->_schemaCache[$model] = $schema;
	}
579777
public function getSchemaFilename($settings)
    {
        // Default
        $schemaFile = sprintf('%s/%s', getcwd(), 'schema.php');
        if (!empty($settings['schema_file'])) {
            $schemaFile = $settings['schema_file'];
        }

        return $schemaFile;
    }
1287478
public function update($schema)
    {
        $schema = $this->callSchema($schema);

        foreach ($schema->getColumns() as $column) {
            if ($this->hasColumn($column->getName())) {
                $this->modifyColumn($column);
            } else {
                $this->addColumn($column);
            }
        }

        foreach ($schema->getIndexes() as $index) {
            $this->addIndex($index);
        }

        return $this->reset();
    }
611345
public function setData(array $settings) : void
    {
        foreach ($settings as $key => $value) {
            $this->data[strtolower($key)] = $value;
        }
    }
104735
protected function writeSchemaHelp($schema) {
        // Write the command description.
        $meta = Cli::val(Cli::META, $schema, []);
        $description = Cli::val('description', $meta);

        if ($description) {
            echo implode("\n", Cli::breakLines($description, 80, false)).PHP_EOL.PHP_EOL;
        }

        unset($schema[Cli::META]);

        // Add the help.
        $schema['help'] = [
            'description' => 'Display this help.',
            'type' => 'boolean',
            'short' => '?'
        ];

        echo Cli::bold('OPTIONS').PHP_EOL;

        ksort($schema);

        $table = new Table();
        $table->setFormatOutput($this->formatOutput);

        foreach ($schema as $key => $definition) {
            $table->row();

            // Write the keys.
            $keys = "--{$key}";
            if ($shortKey = Cli::val('short', $definition, false)) {
                $keys .= ", -$shortKey";
            }
            if (Cli::val('required', $definition)) {
                $table->bold($keys);
            } else {
                $table->cell($keys);
            }

            // Write the description.
            $table->cell(Cli::val('description', $definition, ''));
        }

        $table->write();
        echo PHP_EOL;

        $args = Cli::val(Cli::ARGS, $meta, []);
        if (!empty($args)) {
            echo Cli::bold('ARGUMENTS').PHP_EOL;

            $table = new Table();
            $table->setFormatOutput($this->formatOutput);

            foreach ($args as $argName => $arg) {
                $table->row();

                if (Cli::val('required', $arg)) {
                    $table->bold($argName);
                } else {
                    $table->cell($argName);
                }

                $table->cell(Cli::val('description', $arg, ''));
            }
            $table->write();
            echo PHP_EOL;
        }
    }
1313092
public function setSchema(Schema $schema)
    {
        $this->schema = $schema;

        if (!$this->getSchema()->hasTable($this->getName())) {
            $this->getSchema()->addTable($this);
        }
    }
924590
public function dumpSchema(Schema $schema, $doFinalInitialization = true)
    {
        $rootNode = $this->document->createElement('app-data');
        $this->document->appendChild($rootNode);
        foreach ($schema->getDatabases($doFinalInitialization) as $database) {
            $this->appendDatabaseNode($database, $rootNode);
        }

        return trim($this->document->saveXML());
    }
396101
public function upgradeSchema(Schema $schema)
    {
        $config = $schema->getTable('Config');
        $config->dropPrimaryKey();
        $config->setPrimaryKey(['configNamespace', 'configGroup', 'configItem']);
    }
998500
public function clone_with_new_schema($schema)
  {
    $name = $schema->fullname();
    if (AvroSchema::is_valid_type($name))
      throw new AvroSchemaParseException(
        sprintf('Name "%s" is a reserved type name', $name));
    else if ($this->has_name($name))
      throw new AvroSchemaParseException(
        sprintf('Name "%s" is already in use', $name));
    $schemata = new AvroNamedSchemata($this->schemata);
    $schemata->schemata[$name] = $schema;
    return $schemata;
  }