Checks the schema is properly set up.

@throws \moodle_exception
@return void
332707
public function validate_setup() {
        $fields = \search_solr\document::get_default_fields_definition();

        // Field id is already there.
        unset($fields['id']);

        $this->check_index();
        $this->validate_fields($fields, true);
    }
1175516
protected function bootSchemas()
    {
        $configSchemas = config('graphql.schemas');
        foreach ($configSchemas as $name => $schema) {
            $this->app['graphql']->addSchema($name, $schema);
        }
    }
1313092
public function setSchema(Schema $schema)
    {
        $this->schema = $schema;

        if (!$this->getSchema()->hasTable($this->getName())) {
            $this->getSchema()->addTable($this);
        }
    }
1215288
public function checkDbTableExists() {
		$ds = $this->getDataSource();
		$existsTables = $ds->listSources();
		if (empty($existsTables)) {
			return false;
		}

		$schemaList = [];
		$schemaCheckingList = [''];
		$schemaCheckingListCfg = $this->_modelConfigInstaller->getListSchemaChecking();
		if (!empty($schemaCheckingList)) {
			$schemaCheckingList = array_merge($schemaCheckingList, $schemaCheckingListCfg);
		}
		foreach ($schemaCheckingList as $schemaCheckingListItem) {
			$name = null;
			$path = null;
			$file = null;
			$connection = null;
			$plugin = null;

			if (preg_match('/[\s\b]?\-\-name\s+(\w+)/', $schemaCheckingListItem, $matches) && (count($matches) == 2)) {
				list($plugin, $name) = pluginSplit($matches[1]);
			} elseif (preg_match('/^(\w+)/', $schemaCheckingListItem, $matches) && (count($matches) == 2)) {
				$name = $matches[1];
			}

			if (preg_match('/[\s\b]?(?:\-p|\-\-plugin)\s+(\w+)/', $schemaCheckingListItem, $matches) && (count($matches) == 2)) {
				$plugin = $matches[1];
			}

			if (preg_match('/[\s\b]?(?:\-c|\-\-connection)\s+(\w+)/', $schemaCheckingListItem, $matches) && (count($matches) == 2)) {
				$connection = $matches[1];
			}

			if (preg_match('/[\s\b]?\-\-path\s+(\w+)/', $schemaCheckingListItem, $matches) && (count($matches) == 2)) {
				$path = $matches[1];
			}

			if (preg_match('/[\s\b]?\-\-file\s+(\w+)/', $schemaCheckingListItem, $matches) && (count($matches) == 2)) {
				$file = $matches[1];
			}

			if (!empty($name)) {
				$file = Inflector::underscore($name);
			} elseif (empty($file)) {
				$file = 'schema.php';
			}

			if (strpos($file, '.php') === false) {
				$file .= '.php';
			}

			if (!empty($plugin) && empty($name)) {
				$name = $plugin;
			}

			$name = Inflector::camelize($name);
			$schemaList[] = compact('name', 'path', 'file', 'connection', 'plugin');
		}

		$existsTables = array_flip($existsTables);
		foreach ($schemaList as $schemaListItem) {
			$Schema = new CakeSchema($schemaListItem);
			$oldSchema = $Schema->load();
			if (!$oldSchema) {
				return false;
			}

			$diffTables = array_diff_key($oldSchema->tables, $existsTables);
			if (!empty($diffTables)) {
				return false;
			}
			unset($Schema);
		}

		return true;
	}
1216341
public function validate() : bool
    {
        $table = $this->getConfig()->getTable();
        foreach ([$this->config->getField(), $this->config->getDisplayField()] as $field) {
            if ($table->getSchema()->hasColumn($field)) {
                continue;
            }

            $this->errors[] = sprintf('Unknown column "%s" for table "%s"', $field, $table->getAlias());
        }

        return empty($this->errors);
    }
874023
public function setup(){
		if($this->hasOption('autoinit') && $this->options()->autoinit){
			if($this->hasOption('default')){
				$this->setValue($this->options()->default);
			}else{
				$this->setValue('now');
			}
		}
	}
276613
def validate(schema):
    """"""
    try:
        tableschema.validate(schema)
        click.echo("Schema is valid")
        sys.exit(0)
    except tableschema.exceptions.ValidationError as exception:
        click.echo("Schema is not valid")
        click.echo(exception.errors)
        sys.exit(1)
84600
public function check()
    {
        $result = true;

        $configurationSettings = [
            'Database.Host',
            'Database.Username',
            'Database.Password',
            'Database.Port',
            'Database.Name',
        ];

        foreach ($configurationSettings as $setting) {
            if ($this->configuration->hasConfigurationKey($setting) === false) {
                $this->missingConfiguration[] = $setting;
                $result = false;
            }
        }

        return $result;
    }
27359
private function validate()
    {
        if ($this->hasValidated) {
            return;
        }

        $this->checkDepth();

        foreach ($this->schema as $rule => $parameter) {
            $this->currentKeyword   = $rule;
            $this->currentParameter = $parameter;
            $this->mergeErrors($this->validateRule($rule, $parameter));
            $this->currentKeyword = $this->currentParameter = null;
        }

        $this->hasValidated = true;
    }
289212
public function check()
    {
        // Check for a title.
        if (trim($this->title) == '')
        {
            $this->setError(JText::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_CATEGORY'));

            return false;
        }

        $this->alias = trim($this->alias);

        if (empty($this->alias))
        {
            $this->alias = $this->title;
        }

        $this->alias = JApplicationHelper::stringURLSafe($this->alias, $this->language);

        if (trim(str_replace('-', '', $this->alias)) == '')
        {
            $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
        }

        return true;
    }
793045
public function setup()
	{
		$this->addRule('component', function($data)
		{
			self::$connection->setQuery("SELECT element FROM `#__extensions` AS e WHERE e.type = 'component' ORDER BY e.name ASC");
			$extensions = self::$connection->loadColumn();
			if (!in_array($data['component'], $extensions))
			{
				return Lang::txt('Component does not exist.');
			}
			return false;
		});
	}
1195242
public function check_config()
    {
        $this->load_config();

        if (!$this->configured) {
            return;
        }

        $out = $seen = array();

        // iterate over the current configuration
        foreach (array_keys($this->config) as $prop) {
            if ($replacement = $this->replaced_config[$prop]) {
                $out['replaced'][]  = array('prop' => $prop, 'replacement' => $replacement);
                $seen[$replacement] = true;
            }
            else if (!$seen[$prop] && in_array($prop, $this->obsolete_config)) {
                $out['obsolete'][] = array('prop' => $prop);
                $seen[$prop]       = true;
            }
        }

        // the old default mime_magic reference is obsolete
        if ($this->config['mime_magic'] == '/usr/share/misc/magic') {
            $out['obsolete'][] = array(
                'prop'    => 'mime_magic',
                'explain' => "Set value to null in order to use system default"
            );
        }

        // check config dependencies and contradictions
        if ($this->config['enable_spellcheck'] && $this->config['spellcheck_engine'] == 'pspell') {
            if (!extension_loaded('pspell')) {
                $out['dependencies'][] = array(
                    'prop'    => 'spellcheck_engine',
                    'explain' => "This requires the <tt>pspell</tt> extension which could not be loaded."
                );
            }
            else if (!empty($this->config['spellcheck_languages'])) {
                foreach ($this->config['spellcheck_languages'] as $lang => $descr) {
                    if (!@pspell_new($lang)) {
                        $out['dependencies'][] = array(
                            'prop'    => 'spellcheck_languages',
                            'explain' => "You are missing pspell support for language $lang ($descr)"
                        );
                    }
                }
            }
        }

        if ($this->config['log_driver'] == 'syslog') {
            if (!function_exists('openlog')) {
                $out['dependencies'][] = array(
                    'prop'    => 'log_driver',
                    'explain' => "This requires the <tt>syslog</tt> extension which could not be loaded."
                );
            }

            if (empty($this->config['syslog_id'])) {
                $out['dependencies'][] = array(
                    'prop'    => 'syslog_id',
                    'explain' => "Using <tt>syslog</tt> for logging requires a syslog ID to be configured"
                );
            }
        }

        // check ldap_public sources having global_search enabled
        if (is_array($this->config['ldap_public']) && !is_array($this->config['autocomplete_addressbooks'])) {
            foreach ($this->config['ldap_public'] as $ldap_public) {
                if ($ldap_public['global_search']) {
                    $out['replaced'][] = array(
                        'prop'        => 'ldap_public::global_search',
                        'replacement' => 'autocomplete_addressbooks'
                    );
                    break;
                }
            }
        }

        return $out;
    }
1224088
private function schema() {
		
		//todo: consider caching this
		$expanded_tables = [];
		$tables = config('center.tables', []);

		foreach ($tables as $table=>$table_properties) {
			
			//sanitize for use in db names and php functions
			$table = str_slug($table, '_');

			//parse table definition
			$table_properties = self::associateNumericKeys($table_properties);
			$table_properties['name'] = $table;
			$table_properties['title'] = trans('center::' . $table . '.title');
			if (!isset($table_properties['keep_clean'])) $table_properties['keep_clean'] = false;
			if (!isset($table_properties['creatable'])) $table_properties['creatable'] = true;
			if (!isset($table_properties['editable'])) $table_properties['editable'] = true;
			if (!isset($table_properties['deletable'])) $table_properties['deletable'] = true;
			if (!isset($table_properties['list'])) $table_properties['list'] = [];
			if (!isset($table_properties['export'])) $table_properties['export'] = [];
			if (!isset($table_properties['search'])) $table_properties['search'] = [];
			if (!isset($table_properties['filters'])) $table_properties['filters'] = [];
			if (!isset($table_properties['timestamps'])) $table_properties['timestamps'] = true;
			
			//temp, soon to look up from permissions table
			$table_properties['dates'] = [];
			
			//loop through fields
			if (!isset($table_properties['fields'])) $table_properties['fields'] = [];
			$expanded_fields = [];
			foreach ($table_properties['fields'] as $field=>$field_properties) {
				
				//resolve shorthand, eg 'updated_at'
				if (is_int($field)) $field = $field_properties;
				if (is_string($field_properties)) {
					if (strpos($field_properties, ' ') !== false) {
						$parts = explode(' ', $field_properties);
						$field_properties = [
							'required' => in_array('required', $parts),
							'hidden' => in_array('hidden', $parts),
							'type' => implode(array_diff($parts, ['required', 'hidden'])),
						];
					} else {
						$field_properties = ['type' => $field_properties];
					}
				}
				$field_properties = self::associateNumericKeys($field_properties);

				//set types on reserved system fields
				if ($field == 'permissions') $field_properties['type'] = 'permissions';
				if (in_array($field, ['created_at', 'updated_at', 'deleted_at'])) $field_properties['type'] = 'datetime';
				if (in_array($field, ['id', 'created_by', 'updated_by', 'deleted_by', 'precedence'])) $field_properties['type'] = 'integer';
				
				//check field type is supported
				if (!in_array($field_properties['type'], self::$field_types)) {
					trigger_error('field ' . $table . '.' . $field . ' is of type ' . $field_properties['type'] . ' which is not supported.');
				}
				
				//relationship columns always end in _id, eg image_id
				//this is so that $model->image_id and $model->image->src can work
				if (in_array($field_properties['type'], ['image', 'select', 'user'])) {
					if (!ends_with($field, '_id')) $field .= '_id';
				}

				//set other field attributes
				$field_properties['name'] = $field;
				$field_properties['title'] = trans('center::' . $table . '.fields.' . $field);
				if (!isset($field_properties['required'])) {
					if (in_array($field, ['id', 'created_at', 'updated_at'])) {
						$field_properties['required'] = true;
					} elseif (in_array($field_properties['type'], ['checkbox'])) {
						$field_properties['required'] = true;
					} else {
						$field_properties['required'] = false;
					}
				}

				//in general, the name of a checkboxes field should be the name of its joining table
				//however your are allowed to name the source, and let the system set the joining table for you
				if (($field_properties['type'] == 'checkboxes') && empty($field_properties['source'])) {
					$field_properties['source'] = $field;
					$field = $field_properties['name'] = RowController::formatJoiningTable($table, $field);
				}
				
				if ($field_properties['type'] == 'user') $field_properties['source'] = config('center.db.users');

				//field max lengths
				if ($field_properties['type'] == 'phone') $field_properties['maxlength'] = 10;
				if ($field_properties['type'] == 'zip') $field_properties['maxlength'] = 5;
				if ($field_properties['type'] == 'us_state') $field_properties['maxlength'] = 2;
				if ($field_properties['type'] == 'country') $field_properties['maxlength'] = 2;
				
				if (!isset($field_properties['hidden'])) $field_properties['hidden'] = in_array($field, ['id', 'created_at', 'updated_at', 'deleted_at', 'created_by', 'updated_by', 'deleted_by', 'password', 'precedence']);
				if (in_array($field_properties['type'], ['image' ,'images'])) {
					if (empty($field_properties['width'])) $field_properties['width'] = null;
					if (empty($field_properties['height'])) $field_properties['height'] = null;
				}

				//empty source on 
				if (in_array($field_properties['type'], ['latitude', 'longitude', 'slug'])) {
					if (empty($field_properties['source'])) $field_properties['source'] = null;
				}
				
				//forced overrides
				if ($field_properties['type'] == 'password') $field_properties['hidden'] = true;
				if ($field_properties['hidden']) $field_properties['required'] = false;
				
				//save
				$expanded_fields[$field] = (object) $field_properties;
				
			}
			
			//save fields to table as an object
			$table_properties['fields'] = (object) $expanded_fields;

			//default table properties
			if (!isset($table_properties['list_grouping'])) $table_properties['list_grouping'] = '';
			if (!isset($table_properties['model'])) $table_properties['model'] = studly_case(str_singular($table));
			if (!isset($table_properties['hidden'])) $table_properties['hidden'] = false;
			if (!isset($table_properties['links'])) $table_properties['links'] = [];
			if (!isset($table_properties['order_by'])) {
				$table_properties['order_by'] = [$table . '.id'=>'asc'];
			} else {
				$table_properties['order_by'] = self::associateNumericKeys($table_properties['order_by'], 'asc');
				foreach ($table_properties['order_by'] as $column => $direction) {
					//add table name to disambiguate
					if (!strstr($column, '.')) {
						unset($table_properties['order_by'][$column]);
						$table_properties['order_by'][$table . '.' . $column] = $direction;
					}
				}
			}

			//save table to $tables array as an object
			$expanded_tables[$table] = (object) $table_properties;
		}

		//sort alpha by title
		uksort($expanded_tables, function($a, $b) use ($expanded_tables) {
			return $expanded_tables[$a]->title > $expanded_tables[$b]->title;
		});

		//dd($expanded_tables);

		Config::set('center.tables', $expanded_tables);		
	}
952763
protected function checkColumnsValidity(): void
    {
        $this->getAttribute('columns')->map(function (TableListColumn $column) {
            $this->checkSortableColumnHasAttribute($column);
            $isSearchable = in_array(
                $column->getAttribute('attribute'),
                $this->getAttribute('searchableColumns')->pluck('attribute')->toArray()
            );
            if ($isSearchable) {
                $this->checkSearchableColumnHasAttribute($column);
                $this->checkSearchedAttributeDoesExistInRelatedTable($column);
            }
        });
    }
492404
public function is_ready() {
        if (empty($this->pathtopython)) {
            $settingurl = new \moodle_url('/admin/settings.php', array('section' => 'systempaths'));
            return get_string('pythonpathnotdefined', 'mlbackend_python', $settingurl->out());
        }

        // Check the installed pip package version.
        $cmd = "{$this->pathtopython} -m moodlemlbackend.version";

        $output = null;
        $exitcode = null;
        // Execute it sending the standard error to $output.
        $result = exec($cmd . ' 2>&1', $output, $exitcode);

        $vercheck = self::check_pip_package_version($result);

        if ($vercheck === 0) {
            return true;
        }

        if ($exitcode != 0) {
            return get_string('pythonpackagenotinstalled', 'mlbackend_python', $cmd);
        }

        if ($result) {
            $a = [
                'installed' => $result,
                'required' => self::REQUIRED_PIP_PACKAGE_VERSION,
            ];

            if ($vercheck < 0) {
                return get_string('packageinstalledshouldbe', 'mlbackend_python', $a);

            } else if ($vercheck > 0) {
                return get_string('packageinstalledtoohigh', 'mlbackend_python', $a);
            }
        }

        return get_string('pythonpackagenotinstalled', 'mlbackend_python', $cmd);
    }
1219691
function setup() {
        global $SESSION;

        if (empty($this->columns) || empty($this->uniqueid)) {
            return false;
        }

        // Load any existing user preferences.
        if ($this->persistent) {
            $this->prefs = json_decode(get_user_preferences('flextable_' . $this->uniqueid), true);
            $oldprefs = $this->prefs;
        } else if (isset($SESSION->flextable[$this->uniqueid])) {
            $this->prefs = $SESSION->flextable[$this->uniqueid];
            $oldprefs = $this->prefs;
        }

        // Set up default preferences if needed.
        if (!$this->prefs or optional_param($this->request[TABLE_VAR_RESET], false, PARAM_BOOL)) {
            $this->prefs = array(
                'collapse' => array(),
                'sortby'   => array(),
                'i_first'  => '',
                'i_last'   => '',
                'textsort' => $this->column_textsort,
            );
        }

        if (!isset($oldprefs)) {
            $oldprefs = $this->prefs;
        }

        if (($showcol = optional_param($this->request[TABLE_VAR_SHOW], '', PARAM_ALPHANUMEXT)) &&
                isset($this->columns[$showcol])) {
            $this->prefs['collapse'][$showcol] = false;

        } else if (($hidecol = optional_param($this->request[TABLE_VAR_HIDE], '', PARAM_ALPHANUMEXT)) &&
                isset($this->columns[$hidecol])) {
            $this->prefs['collapse'][$hidecol] = true;
            if (array_key_exists($hidecol, $this->prefs['sortby'])) {
                unset($this->prefs['sortby'][$hidecol]);
            }
        }

        // Now, update the column attributes for collapsed columns
        foreach (array_keys($this->columns) as $column) {
            if (!empty($this->prefs['collapse'][$column])) {
                $this->column_style[$column]['width'] = '10px';
            }
        }

        if (($sortcol = optional_param($this->request[TABLE_VAR_SORT], '', PARAM_ALPHANUMEXT)) &&
                $this->is_sortable($sortcol) && empty($this->prefs['collapse'][$sortcol]) &&
                (isset($this->columns[$sortcol]) || in_array($sortcol, get_all_user_name_fields())
                && isset($this->columns['fullname']))) {

            if (array_key_exists($sortcol, $this->prefs['sortby'])) {
                // This key already exists somewhere. Change its sortorder and bring it to the top.
                $sortorder = $this->prefs['sortby'][$sortcol] == SORT_ASC ? SORT_DESC : SORT_ASC;
                unset($this->prefs['sortby'][$sortcol]);
                $this->prefs['sortby'] = array_merge(array($sortcol => $sortorder), $this->prefs['sortby']);
            } else {
                // Key doesn't exist, so just add it to the beginning of the array, ascending order
                $this->prefs['sortby'] = array_merge(array($sortcol => SORT_ASC), $this->prefs['sortby']);
            }

            // Finally, make sure that no more than $this->maxsortkeys are present into the array
            $this->prefs['sortby'] = array_slice($this->prefs['sortby'], 0, $this->maxsortkeys);
        }

        // MDL-35375 - If a default order is defined and it is not in the current list of order by columns, add it at the end.
        // This prevents results from being returned in a random order if the only order by column contains equal values.
        if (!empty($this->sort_default_column))  {
            if (!array_key_exists($this->sort_default_column, $this->prefs['sortby'])) {
                $defaultsort = array($this->sort_default_column => $this->sort_default_order);
                $this->prefs['sortby'] = array_merge($this->prefs['sortby'], $defaultsort);
            }
        }

        $ilast = optional_param($this->request[TABLE_VAR_ILAST], null, PARAM_RAW);
        if (!is_null($ilast) && ($ilast ==='' || strpos(get_string('alphabet', 'langconfig'), $ilast) !== false)) {
            $this->prefs['i_last'] = $ilast;
        }

        $ifirst = optional_param($this->request[TABLE_VAR_IFIRST], null, PARAM_RAW);
        if (!is_null($ifirst) && ($ifirst === '' || strpos(get_string('alphabet', 'langconfig'), $ifirst) !== false)) {
            $this->prefs['i_first'] = $ifirst;
        }

        // Save user preferences if they have changed.
        if ($this->prefs != $oldprefs) {
            if ($this->persistent) {
                set_user_preference('flextable_' . $this->uniqueid, json_encode($this->prefs));
            } else {
                $SESSION->flextable[$this->uniqueid] = $this->prefs;
            }
        }
        unset($oldprefs);

        if (empty($this->baseurl)) {
            debugging('You should set baseurl when using flexible_table.');
            global $PAGE;
            $this->baseurl = $PAGE->url;
        }

        $this->currpage = optional_param($this->request[TABLE_VAR_PAGE], 0, PARAM_INT);
        $this->setup = true;

        // Always introduce the "flexible" class for the table if not specified
        if (empty($this->attributes)) {
            $this->attributes['class'] = 'flexible';
        } else if (!isset($this->attributes['class'])) {
            $this->attributes['class'] = 'flexible';
        } else if (!in_array('flexible', explode(' ', $this->attributes['class']))) {
            $this->attributes['class'] = trim('flexible ' . $this->attributes['class']);
        }
    }
1098423
protected function _mysql()
	{
		$this->_msg(sprintf('Adding label and status columns'), 0);
		$this->_status( '' );

		foreach ($this->_mysql as $table => $columns) {

			if ($this->_schema->tableExists($table)) {

				foreach ($columns as $column => $stmt) {

					$this->_msg(sprintf('Checking column "%1$s.%2$s": ', $table, $column), 1);

					if (!$this->_schema->columnExists($table, $column)) {
						$this->_execute($stmt);
						$this->_status('added');
					} else {
						$this->_status('OK');
					}
				}
			}
		}
	}