@param \xPDOQuery|array|null $criteria
@param string $server_type
@param string $name
@param bool $create_migration_file

@return array
324115
public function makeResourceSeeds($criteria, $server_type = 'master', $name = null, $create_migration_file = true)
    {
        $keys = [
            'web' => []
        ];

        $collection = $this->modx->getCollection('modResource', $criteria);
        foreach ($collection as $resource) {
            $blendResource = new Resource($this->modx, $this->blender, $resource->get('alias'), $resource->get('context_key'));
            $seed_key = $blendResource
                ->setSeedsDir($this->format->getMigrationName('resource', $name))
                ->seed();
            $this->blender->out("ID: ".$resource->get('id').' Key: '.$seed_key);

            if (!isset($keys[$resource->get('context_key')])) {
                $keys[$resource->get('context_key')] = [];
            }

            $keys[$resource->get('context_key')][] = $seed_key;
        }

        if ($create_migration_file) {
            /** @var MigrationsCreator $migrationCreator */
            $migrationCreator = new MigrationsCreator($this->blender->getUserInteractionHandler(), $keys);

            $migrationCreator
                ->setPathTimeStamp($this->format->getPathTimeStamp())
                ->setVerbose($this->blender->getVerbose())
                ->setName($name)
                ->setDescription('')
                ->setServerType($server_type)
                ->setMigrationsPath($this->blender->getMigrationPath())
                ->createResourceMigrationClassFile();

            $this->logCreatedSeedMigration($migrationCreator->getLogData());
        }
        return $keys;
    }
407493
public function forceInitialMigration($reference, $criteria = self::FORCEDMIGRATION_INCLUSIVE)
    {
        $reference = trim((string) $reference);
        if ($reference === '') {
            throw new Exception(t('Invalid initial migration reference.'));
        }
        if (!in_array($criteria, [static::FORCEDMIGRATION_INCLUSIVE, static::FORCEDMIGRATION_EXCLUSIVE], true)) {
            throw new Exception(t('Invalid initial migration criteria.'));
        }

        // Remove possible 'Version' prefix from the migration identifier.
        // This allows a user to also use VersionXXXXXXXXXXXX, which corresponds with the class name.
        $reference = str_replace('Version', '', $reference);

        $migration = $this->findInitialMigration($reference, $criteria);
        if ($migration === null) {
            throw new Exception(t('Unable to find a migration with identifier %s', $reference));
        }
        $this->forcedInitialMigration = $migration;
    }
95736
public function createCriteriaColumn(
        $query_name = "",
        $table_name = "table_name",
        $column_name = "column_name",
        $column_type = "string",
        $column_length = 0,
        $column_mask = "MASK",
        $in_select = true
    ) {
        // Default Query Column Name to Datbase Column Name ( if not set )

        // If the column already exists we are probably importing over the
        // top of an existing query, so just update it
        if ($cl = ReporticoUtility::getQueryColumn($query_name, $this->columns)) {
            $cl->table_name = $table_name;
            $cl->column_name = $column_name;
            $cl->column_type = $column_type;
            $cl->column_length = $column_length;
            $cl->column_mask = $column_mask;
        } else {
            $this->columns[] = new CriteriaColumn
            (
                $this,
                $query_name,
                $table_name,
                $column_name,
                $column_type,
                $column_length,
                $column_mask,
                $in_select
            );
            end($this->columns);
            $ky = key($this->columns);
            $this->display_order_set["itemno"][] = count($this->columns);
            $this->display_order_set["column"][] = &$this->columns[$ky];
        }
    }
551624
private function migrate($name, $params = [])
    {
        $generator = new TemplateGenerator();
        $generator->setContent(file_get_contents($name));

        return $generator->generate($params);
    }
583955
public function createBlankMigrationClassFile($name, $server_type = 'master', $migration_path = null)
    {
        $migrationCreator = new MigrationsCreator($this->userInteractionHandler);

        if (empty($migration_path)) {
            $migration_path = $this->getMigrationPath();
        }

        $success = $migrationCreator
            ->setPathTimeStamp($this->getSeedsDir())
            ->setVerbose($this->getVerbose())
            ->setName($name)
            ->setDescription('')
            ->setServerType($server_type)
            ->setMigrationsPath($migration_path)
            ->createBlankMigrationClassFile();

        $this->logCreatedMigration($migrationCreator->getLogData());
        return $success;
    }
652509
public function createExtendedCollection($name, MkCol $mkCol)
    {
        if (!$mkCol->hasResourceType('{'.Plugin::NS_CARDDAV.'}addressbook')) {
            throw new DAV\Exception\InvalidResourceType('Unknown resourceType for this collection');
        }
        $properties = $mkCol->getRemainingValues();
        $mkCol->setRemainingResultCode(201);
        $this->carddavBackend->createAddressBook($this->principalUri, $name, $properties);
    }
34637
public function buildQuery($in_is_expanding = false, $criteria_name = "", $in_design_mode = false, $no_warnings = false)
    {

        if (!$criteria_name) {
            $this->setRequestColumns();
        }

        $execute_mode = $this->getExecuteMode();

        // Use raw user query in >= Version 2.5
        if ($this->sql_raw) {
            // Now if any of the criteria is an SQLCOMMAND then that should be used for the report data so
            // parse the users command and execute it
            if (!$in_is_expanding && !$criteria_name && !$in_design_mode) {
                foreach ($this->lookup_queries as $key => $col) {
                    if ($col->criteria_type == "SQLCOMMAND") {
                        $this->importSQL($col->column_value);
                    }

                }
            }

            $this->query_statement = $this->sql_raw;

            // Build in criteria items
            $critwhere = "";
            if ($execute_mode != "MAINTAIN") {
                foreach ($this->lookup_queries as $k => $col) {
                    if ($col->column_name) {
                        $critwhere .= $col->getCriteriaClause();
                    }
                }
            }

            // Add in any expand criteria
            $critwhere .= $this->buildWhereExtraList($in_is_expanding, $criteria_name);

            // If user has "Main query column" criteria then parse sql to find
            // where to insert them
            if ($critwhere) {
                $p = new SqlParser($this->query_statement);
                if ($p->parse()) {
                    if ($p->haswhere) {
                        $this->query_statement =
                        substr($this->query_statement, 0, $p->whereoffset) .
                        " 1 = 1" .
                        $critwhere .
                        " AND" .
                        substr($this->query_statement, $p->whereoffset);
                    } else {
                        $this->query_statement =
                        substr($this->query_statement, 0, $p->whereoffset) .
                        " WHERE 1 = 1 " .
                        $critwhere .
                        substr($this->query_statement, $p->whereoffset);
                    }
                }
            }

            // Dont add limits/offset if crtieria query of entering SQL in design mode
            if (!$criteria_name && !$in_design_mode) {
                if ($this->datasource->_conn_driver != "pdo_informix" && $this->datasource->_conn_driver != "informix") {
                    $this->query_statement .= $this->buildLimitOffset();
                }
            }

        } else {
            // Pre Version 2.5 - parts of SQL specified in XML
            $this->query_statement = "SELECT";

            // Dont add limits/offset if crtieria query of entering SQL in design mode
            if (!$criteria_name && !$in_design_mode) {
                if ($this->datasource->_conn_driver == "pdo_informix" || $this->datasource->_conn_driver == "informix") {
                    $this->query_statement .= $this->buildLimitOffset();
                }
            }

            if ($this->rowselection == "unique") {
                if ($this->datasource->_conn_driver == "pdo_informix" || $this->datasource->_conn_driver == "informix") {
                    $this->query_statement .= " UNIQUE";
                } else {
                    $this->query_statement .= " DISTINCT";
                }
            }

            $this->query_statement .= $this->buildColumnList();
            $this->query_statement .= $this->buildTableList();

            if ($execute_mode == "MAINTAIN") {
                $this->query_statement .= $this->buildWhereList(false);
            } else {
                $this->query_statement .= $this->buildWhereList(true);
            }

            $this->query_statement .= $this->buildWhereExtraList($in_is_expanding, $criteria_name);
            $this->query_statement .= $this->buildWhereCriteriaLink($in_is_expanding);
            $this->query_statement .= $this->buildOrderList($criteria_name);

            // Dont add limits/offset if crtieria query of entering SQL in design mode
            if (!$criteria_name && !$in_design_mode) {
                if ($this->datasource->_conn_driver != "pdo_informix" && $this->datasource->_conn_driver != "informix") {
                    $this->query_statement .= $this->buildLimitOffset();
                }
            }

        }

        if ($execute_mode != "MAINTAIN") {
            $this->query_statement = Assignment::reporticoMetaSqlCriteria($this->parent_query, $this->query_statement, false, $no_warnings, $execute_mode);
        }

    }
271966
private function checkFileBasedMigration(
        FileBasedMigration $migration,
        string $migrationName,
        OutputInterface $output
    ): int {
        $methods = ['upgrade' => 'preUp', 'downgrade' => 'preDown'];
        // the right way is to use the same schema that is passed to a real migration
        $schema = new Schema();
        foreach ($methods as $direction => $method) {
            $migration->{$method}($schema);
            if ($migration->getQueries()) {
                $output->writeln(
                    sprintf('<comment>%s by migration %s contains</comment>', ucfirst($direction), $migrationName)
                );
                $this->printQueries($migration->getQueries(), $output);
            } else {
                $output->writeln(
                    sprintf('<comment>%s by migration %s is empty</comment>', ucfirst($direction), $migrationName)
                );
            }
        }
        return 0;
    }
25388
protected String createQueryStringFromCriteria(Criteria criteria, @Nullable Class<?> domainType) {
		return createQueryStringFromNode(criteria, domainType);
	}
986509
public function findOrCreate($criteria, $parameters = null)
    {
        if ($criteria instanceof Bag) {
            $criteria = $criteria->toArray();
        }

        if ($parameters === null) {
            $parameters = $criteria;
        }

        $parameters = $this->castParameters($parameters);
        $entity = $this->getRepository()->findOneBy($criteria);

        if ($entity == null) {
            return $this->create($parameters);
        }

        $result = new Result();
        $result->getResources()->push($entity);

        return $result;
    }
616713
public function makePluginSeeds($criteria, $server_type = 'master', $name = null, $create_migration_file = true)
    {
        $keys = [];
        $collection = $this->modx->getCollection('modPlugin', $criteria);

        foreach ($collection as $plugin) {
            /** @var \LCI\Blend\Blendable\Plugin $blendPlugin */
            $blendPlugin = new Plugin($this->modx, $this->blender, $plugin->get('name'));
            $seed_key = $blendPlugin
                ->setSeedsDir($this->format->getMigrationName('plugin', $name))
                ->seed();
            $this->blender->out("Plugin: ".$plugin->get('name').' Key: '.$seed_key);
            $keys[] = $seed_key;
        }

        if ($create_migration_file) {
            /** @var MigrationsCreator $migrationCreator */
            $migrationCreator = new MigrationsCreator($this->blender->getUserInteractionHandler(), $keys);

            $migrationCreator
                ->setPathTimeStamp($this->format->getPathTimeStamp())
                ->setVerbose($this->blender->getVerbose())
                ->setName($name)
                ->setDescription('')
                ->setServerType($server_type)
                ->setMigrationsPath($this->blender->getMigrationPath())
                ->createPluginMigrationClassFile();

            $this->logCreatedSeedMigration($migrationCreator->getLogData());
        }
        return $keys;
    }
1358932
public function createContentTypeWithRequiredFieldType( $fieldType, $name = null )
    {
        return $this->getFieldTypeManager()->createField( $fieldType, $name, true );
    }
173283
public static function createMigration(string $name): void
    {
        $directory = Application::getApplicationPath('migrations');

        if (!is_dir($directory)) {
            Directory::mkdir($directory, 0755);
        }

        $timestamp = time();
        $className = Util::camelCase($name, null, false);
        $phpClassName = "Migration_{$timestamp}_{$className}";
        $fileName = "{$timestamp}_{$className}.php";
        $fullPath = Application::getApplicationPath("migrations/{$fileName}");

        $migrationFileContent = file_get_contents(__DIR__ . '/MigrationTemplate.php');
        $migrationFileContent = str_replace('templateClassName', $phpClassName, $migrationFileContent);
        $migrationFileContent = str_replace('templateClassGenerated', date('r'), $migrationFileContent);

        if (file_put_contents($fullPath, $migrationFileContent) === false) {
            throw new Application\Exception("Unable to write to migration file on path={$fullPath}");
        }

        Log::info("Created DB migration with name: {$name}");
        Log::info("You may now open application/migrations/{$fileName} and add your migration code");
    }
1095852
public function makeContextSeeds($criteria, $server_type = 'master', $name = null, $create_migration_file = true)
    {
        $keys = [];
        $collection = $this->modx->getCollection('modContext', $criteria);

        foreach ($collection as $context) {
            /** @var Context $blendContext */
            $blendContext = new Context($this->modx, $this->blender, $context->get('key'));
            $seed_key = $blendContext
                ->setSeedsDir($this->format->getMigrationName('context', $name))
                ->seed();
            $this->blender->out("Context: ".$context->get('name').' Key: '.$seed_key);
            $keys[] = $seed_key;
        }

        if ($create_migration_file) {
            /** @var MigrationsCreator $migrationCreator */
            $migrationCreator = new MigrationsCreator($this->blender->getUserInteractionHandler(), $keys);

            $migrationCreator
                ->setPathTimeStamp($this->format->getPathTimeStamp())
                ->setVerbose($this->blender->getVerbose())
                ->setName($name)
                ->setDescription('')
                ->setServerType($server_type)
                ->setMigrationsPath($this->blender->getMigrationPath())
                ->createContextMigrationClassFile();

            $this->logCreatedSeedMigration($migrationCreator->getLogData());
        }
        return $keys;
    }
246959
public function exportFileAction($type, $name)
    {
        $server = $this->ldap->get($name);
        $server['userPassword'] = 'userpassword';
        $user = isset($server['user']) ? $server['user'] : null;
        $password = isset($server['password']) ? $server['password'] : null;

        if ($this->ldap->userMapping($server) && $this->ldap->connect($server, $user, $password)) {
            $users = $this->ldap->getUsers($server);
            $this->ldap->close();
            $response = new response(
                $this->templating->render(
                    'ClarolineAuthenticationBundle:export:'.$type.'.html.twig',
                    ['users' => $users, 'server' => $server]
                )
            );
        } else {
            $response = new Response('Error');
        }

        $response->headers->set('Content-Transfer-Encoding', 'octet-stream');
        $response->headers->set('Content-Type', 'application/force-download');
        $response->headers->set('Content-Disposition', 'attachment; filename='.$name.'.'.$type);
        $response->headers->set('Connection', 'close');

        return $response;
    }
785083
public function getMigrationTemplate( $name )
    {
        $template = '<?php' . PHP_EOL . PHP_EOL;
        
        if ( '' !== $this->migrationNamespace )
        {
            $template .= 'namespace ' . $this->migrationNamespace . ';' . PHP_EOL . PHP_EOL;
        }
        
        $template .= 'use RawPHP\RawMigrator\Migration;' . PHP_EOL;
        $template .= 'use RawPHP\RawDatabase\IDatabase;' . PHP_EOL . PHP_EOL;
        
        $template .= 'class ' . $name . ' extends Migration' . PHP_EOL;
        $template .= '{' . PHP_EOL;
        
        $template .= '    /**' . PHP_EOL;
        $template .= '     * Implement database changes here.' . PHP_EOL;
        $template .= '     * ' . PHP_EOL;
        $template .= '     * @param IDatabase $db database instance' . PHP_EOL;
        $template .= '     */' . PHP_EOL;
        $template .= '    public function migrateUp( IDatabase $db )' . PHP_EOL;
        $template .= '    {' . PHP_EOL;
        $template .= '        ' . PHP_EOL;
        $template .= '    }' . PHP_EOL . PHP_EOL;
        
        $template .= '    /**' . PHP_EOL;
        $template .= '     * Implement reverting changes here.' . PHP_EOL;
        $template .= '     * ' . PHP_EOL;
        $template .= '     * @param IDatabase $db database instance' . PHP_EOL;
        $template .= '     */' . PHP_EOL;
        $template .= '    public function migrateDown( IDatabase $db )' . PHP_EOL;
        $template .= '    {' . PHP_EOL;
        $template .= '        ' . PHP_EOL;
        $template .= '    }' . PHP_EOL . PHP_EOL;
        
        $template .= '    /**' . PHP_EOL;
        $template .= '     * Alternatively to <code>migrateUp()</code>, this method will' . PHP_EOL;
        $template .= '     * use transactions (if available) to process the database changes.' .
                          PHP_EOL;
        $template .= '     * ' . PHP_EOL;
        $template .= '     * @param IDatabase $db database instance' . PHP_EOL;
        $template .= '     */' . PHP_EOL;
        $template .= '    public function safeMigrateUp( IDatabase $db )' . PHP_EOL;
        $template .= '    {' . PHP_EOL;
        $template .= '        ' . PHP_EOL;
        $template .= '    }' . PHP_EOL . PHP_EOL;
        
        $template .= '    /**' . PHP_EOL;
        $template .= '     * Alternatively to <code>migrateDown()</code>, this method will' . 
                          PHP_EOL;
        $template .= '     * use transactions (if available) to revert changes.' . PHP_EOL;
        $template .= '     * ' . PHP_EOL;
        $template .= '     * @param IDatabase $db database instance' . PHP_EOL;
        $template .= '     */' . PHP_EOL;
        $template .= '    public function safeMigrateDown( IDatabase $db )' . PHP_EOL;
        $template .= '    {' . PHP_EOL;
        $template .= '        ' . PHP_EOL;
        $template .= '    }' . PHP_EOL;
        $template .= '}';
        
        return $this->filter( self::ON_GET_MIGRATION_TEMPLATE_FILTER, $template, $name );
    }
1234307
protected function _createList(string $name) : bool
    {
        /**
         * @var \CsvMigrations\Model\Table\DblistsTable
         */
        $table = $this->loadModel('CsvMigrations.Dblists');

        if ($table->exists(['name' => $name])) {
            return false;
        }

        $entity = $table->newEntity(['name' => $name]);

        return (bool)$table->save($entity);
    }