Returns a list of fields defined in `migration.json`.

@param string $module Module name.
@param bool $validate Should the data be validated against the schema.
@return string[] List of fields.
336631
public static function getRealModuleFields(string $module, bool $validate = true) : array
    {
        $moduleFields = [];

        $mc = new ModuleConfig(ConfigType::MIGRATION(), $module, null, ['cacheSkip' => true]);
        $mc->setParser(new Parser($mc->createSchema(), ['validate' => $validate]));
        $moduleFields = Convert::objectToArray($mc->parse());
        $fields = Hash::extract($moduleFields, '{*}.name');

        return (array)$fields;
    }
838214
public function getWorkflow($name, $validate = true)
    {
        $useCacheTxt = $this->getProperties()->getProperty(self::CACHE, 'false');
        $useCache = false;
        if ('true' === $useCacheTxt) {
            $useCache = true;
        }

        if ($useCache && array_key_exists($name, $this->cache)) {
            $descriptor = $this->cache[$name];
            return $descriptor;
        }

        try {
            $uri = $this->uriFactory($name);
            $descriptor = WorkflowLoader::load($uri);

            if ($useCache) {
                $this->cache[$name] = $descriptor;
            }
        } catch (\Exception $e) {
            $errMsg = sprintf('Ошибка при загрузке workflow: %s', $name);
            throw new FactoryException($errMsg, $e->getCode(), $e);
        }

        return $descriptor;
    }
236660
public function getList($db=true) {
		if(!file_exists($this->dir.'/migrations.json'))
			return [];
		$migrations = json_decode(file_get_contents($this->dir.'/migrations.json'), true);

		if($db) {
			$tracking = [];

			$this->createTable();
			foreach($this->db->dal()->from('_migrations')->get() as $r)
				$tracking[$r['name']] = ['migrated' => strtotime($r['migrated'])];

			foreach($migrations as $migration=>$params) {
				if(isset($tracking[$migration]))
					$migrations[$migration] = array_merge($migrations[$migration], $tracking[$migration]);
			}
		}

		uasort($migrations, function($a, $b) {
			if(isset($a['migrated']) && !isset($b['migrated']))
				return -1;
			elseif(!isset($a['migrated']) && isset($b['migrated']))
				return 1;
			elseif(isset($a['migrated']) && isset($b['migrated'])) {
				if($a['migrated'] !== $b['migrated'])
					return $a['migrated'] > $b['migrated'];
			}
			return $a['added'] > $b['added'];
		});
		
		return $migrations;
	}
922530
public static List<String> getList(boolean validate, String key) {
		String value = getString(validate, key);

		List<String> result = new ArrayList<>();
		if (value != null) {
			String[] parts = value.split("[,]");
			for (String part : parts) {
				if (part.trim().length() > 0) {
					result.add(part.trim());
				}
			}
		}
		return result;
	}
817290
public function validate(array $data, $validateProperties = true)
    {
        $groupsImporter = $this->getImporterByName('groups');
        $rolesImporter  = $this->getImporterByName('roles');
        $toolsImporter  = $this->getImporterByName('tools');
        $importer       = $this->getImporterByName('workspace_properties');
        $usersImporter  = $this->getImporterByName('user');

        //properties
        if ($validateProperties) {
            if (isset($data['properties'])) {
                $properties['properties'] = $data['properties'];
                $importer->validate($properties);
            }
        }

        if (isset($data['roles'])) {
            $roles['roles'] = $data['roles'];
            $rolesImporter->validate($roles);
        }

        if (isset ($data['tools'])) {
            $tools['tools'] = $data['tools'];
            $toolsImporter->validate($tools);
        }

    }
664127
public function changelogFor(Module $module)
    {
        $path = $module->getPath().'/CHANGELOG.md';
        if (! $this->finder->isFile($path)) {
            return [];
        }

        $parser = new \Changelog\Parser(file_get_contents($path));

        return $parser->getReleases();
    }
858061
protected function getModuleSchemaPaths(array $modulePaths): array
    {
        $schemaPaths = [];

        $fileFinder = $this->createFinder()->in($modulePaths)->name('*.schema.xml');

        /*** @var \Symfony\Component\Finder\SplFileInfo[] $files */
        $files = $fileFinder->files();

        foreach ($files as $file) {
            $schemaPaths[] = $file->getRealPath();
        }

        return $schemaPaths;
    }
1365178
public function saveConfigurationModel($model, $validate = true, $apply = true)
    {
        if (!$model) {
            return false;
        }
        if ($validate && !$model->validate()) {
            return false;
        }
        if ($this->modelClass) {
            //If modelClass is using
            $modelClass = $this->modelClass;
            //Check object and save
            if (
                ($model instanceof $modelClass) &&
                $this->_keyStorage->set($this->getKey(), $model)
            ) {
                //Apply new configuration
                if ($apply) {
                    $this->_configuration = $model;
                    $this->configure();
                }
                return true;
            } else {
                return false;
            }
        } else {
            return $this->saveConfigurationArray($model->getAttributes(), $apply);
        }
    }
33910
public static function getFields(string $module)
    {
        $modules = Modules::findFirstByName($module);

        if ($modules) {
            return self::find([
                'modules_id = ?0',
                'bind' => [$modules->id],
                'columns' => 'name, label, type'
            ]);
        }

        return null;
    }
284124
protected function requireMigrations($module)
    {
        $path = $this->getMigrationPath($module);

        $migrations = $this->laravel['files']->glob($path.'*_*.php');

        foreach ($migrations as $migration) {
            $this->laravel['files']->requireOnce($migration);
        }
    }
814205
public function save($new = false, $validate=true,$validateFields=[])
    {
        $this->isNewRecord = $new;

        if($validate){
            if(!$this->validate($validateFields)){
                return false;
            }
        }
        if(!static::beforeSave()) return false;
        $db = X::app()->db->table(self::tableName());
        $tableFields = $db->getFields(self::tableName());
        foreach($this->_modelData as $k=>$v){
            //删除数据库没有的字段
            if(!in_array($k,$tableFields)) unset($this->_modelData[$k]);
        }
        if ($new) {
            return $db->add($this->_modelData);
        } else {
            $id = $this->{self::$pk};
            unset($this->_modelData[self::$pk]);
            return $db->update([self::$pk => $id], $this->_modelData);
        }
    }
246867
protected function getAttendeesFields(Table $table, array $modules) : array
    {
        $associations = [];
        foreach ($table->associations() as $association) {
            if (in_array(Inflector::humanize($association->getTarget()->getTable()), $modules)) {
                $associations[] = $association;
            }
        }

        if (empty($associations)) {
            return [];
        }

        $result = [];
        foreach ($associations as $association) {
            $foreignKey = $association->getForeignKey();
            if (!is_string($foreignKey)) {
                throw new UnsupportedForeignKeyException();
            }
            if (in_array($foreignKey, $this->skipAttendeesIn)) {
                continue;
            }
            $result[] = $foreignKey;
        }

        return $result;
    }
709922
public function beanToArray(array $fields_name, \SugarBean $bean, $pretty = false, $lang = 'en_us')
    {
        $module_definition = null;
        if ($pretty) {
            $module_definition = $this->getModuleFields($bean->module_name, $lang);
        }
        $fields = array();
        foreach ($fields_name as $field_name) {
            $key = $field_name;
            $value = $bean->$field_name;
            if (!is_null($module_definition)) {
                list($key, $value) = $this->applyLabelsToField($module_definition, $key, $value);
            }
            $fields[$key] = $value;
        }
        return $fields;
    }
942027
public function getInvalidFields()
    {
        $invalidFields = array();
        foreach ($this->currentFields as $field) {
            if (!$field->isValid) {
                $invalidFields[] = $field;
            }
        }
        return $invalidFields;
    }
107451
public function getInvalidRules($field = null)
    {
        return $field ?
            isset($this->invalidRules[$field]) ? $this->invalidRules[$field] : array()
            : $this->invalidRules;
    }
568329
public function getValidationRules($formName = false)
    {
        if (is_bool($formName))
            $formName = $this->currentFormName;

        if (array_key_exists($formName, $this->validationRules)) {
            return $this->validationRules[$formName];
        }

        return [];
    }
274421
public function save($validate = true)
	{
		if ($this->frozen())
		{
			throw new \Exception('Cannot modify a frozen row.');
		}

		$vars = $this->_data;

		// Set default if there are any
		isset(static::$_defaults) and $vars = $vars + static::$_defaults;

		if ($validate and isset(static::$_rules) and ! empty(static::$_rules))
		{
			$vars = $this->pre_validate($vars);
			$validated = $this->post_validate($this->run_validation($vars));

			if ($validated)
			{
				$validated = array_filter($this->validation()->validated(), function($val){
					return ($val !== null);
				});

				$vars = $validated + $vars;
			}
			else
			{
				return false;
			}
		}

		$vars = $this->prep_values($vars);

		if (isset(static::$_properties))
		{
			$vars = \Arr::filter_keys($vars, static::$_properties);
		}

		if(isset(static::$_updated_at))
		{
			if(isset(static::$_mysql_timestamp) and static::$_mysql_timestamp === true)
			{
				$vars[static::$_updated_at] = \Date::forge()->format('mysql');
			}
			else
			{
				$vars[static::$_updated_at] = \Date::forge()->get_timestamp();
			}
		}

		if ($this->is_new())
		{
			if(isset(static::$_created_at))
			{
				if(isset(static::$_mysql_timestamp) and static::$_mysql_timestamp === true)
				{
					$vars[static::$_created_at] = \Date::forge()->format('mysql');
				}
				else
				{
					$vars[static::$_created_at] = \Date::forge()->get_timestamp();
				}
			}

			$query = \DB::insert(static::$_table_name)
			            ->set($vars);

			$this->pre_save($query);
			$result = $query->execute(static::get_connection(true));

			if ($result[1] > 0)
			{
				// workaround for PDO connections not returning the insert_id
				if ($result[0] === false and isset($vars[static::primary_key()]))
				{
					$result[0] = $vars[static::primary_key()];
				}
				$this->set($vars);
				empty($result[0]) or $this->{static::primary_key()} = $result[0];
				$this->is_new(false);
			}

			return $this->post_save($result);
		}

		$query = \DB::update(static::$_table_name)
		         ->set($vars)
		         ->where(static::primary_key(), '=', $this->{static::primary_key()});

		$this->pre_update($query);
		$result = $query->execute(static::get_connection(true));
		$result > 0 and $this->set($vars);

		return $this->post_update($result);
	}