Importing the databases structures.
@return string
495028
public function actionImport()
    {
        $result = ['error' => Yii::t('podium/view', 'Error')];

        if (Yii::$app->request->isPost) {
            $drop = Yii::$app->request->post('drop');
            if ($drop !== null) {
                $installation = new Installation();
                if ((is_bool($drop) && $drop) || $drop === 'true') {
                    $result = $installation->nextDrop();
                } else {
                    $result = $installation->nextStep();
                }
            }
        }

        return Json::encode($result);
    }
319653
public function map()
    {
        $map = config('db-exporter.model.map');

        foreach ($map as $item) {
            // Find matching table name
            $tablePattern = '/' . str_replace('/', '\/', $item['tablePattern']) . '/';
            if (preg_match($tablePattern, $this->table->getTableName()) === 1) {
                $this->path      = $item['path'];
                $this->namespace = $item['namespace'];

                if ($item['className'] !== null) {
                    $pattern     = '/' . str_replace('/', '\/', $item['className']['pattern']) . '/';
                    $replacement = $item['className']['replacement'];
                    echo $replacement;
                    $this->class = preg_replace($pattern, $replacement, $this->class);
                }
                break;
            }
        }
    }
275724
public function ImportFromClientForm() {
        if(!Permission::check('ADMIN')) {
            Security::permissionFailure($this);
            return;
        }
        
        $uploadField=new FileField('ImportFile', _t('CodeBank.EXPORT_FILE', '_Client Export File'));
        $uploadField->getValidator()->setAllowedExtensions(array('cbexport'));
        File::config()->allowed_extensions=array('cbexport');
        
        
        $fields=new FieldList(
                            new LiteralField('ImportWarning', '<p class="message warning">'._t('CodeBank.IMPORT_DATA_WARNING', '_Warning clicking import will erase all snippets in the database, it is recommended you backup your database before proceeding').'</p>'),
                            new TabSet('Root',
                                                new Tab('Main',
                                                                $uploadField,
                                                                new CheckboxField('AppendData', _t('CodeBank.APPEND_IMPORT', '_Import and Append Data (keep your existing data however appending may cause duplicates)'))
                                                            )
                                            )
                        );
        
        $actions=new FieldList(
                            FormAction::create('doImportData', _t('CodeBank.IMPORT', '_Import'))->addExtraClass('ss-ui-button ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true)
                        );
        
        
        $validator=new RequiredFields(
                                    'ImportFile'
                                );
        
        
        $form=new Form($this, 'ImportFromClientForm', $fields, $actions, $validator);
        $form->addExtraClass('member-profile-form');
        
        return $form;
    }
452454
public function exportDatabases()
    {
        $exports = [];
        foreach ($this->databases as $db) {
            $exports[] = $this->createExport($db);
        }

        return $exports;
    }
446006
public function getSchema()
    {
        $this->output->writeln('Load current database schema.');
        $result = [];

        $result['database'] = $this->getDatabaseSchemata($this->dbName);

        $tables = $this->getTables();
        foreach ($tables as $table) {
            $tableName = $table['table_name'];
            $this->output->writeln(sprintf('Table: <info>%s</info>', $tableName));
            $result['tables'][$tableName]['table'] = $table;
            $result['tables'][$tableName]['columns'] = $this->getColumns($tableName);
            $result['tables'][$tableName]['indexes'] = $this->getIndexes($tableName);
            $result['tables'][$tableName]['foreign_keys'] = $this->getForeignKeys($tableName);
        }

        return $result;
    }
1137360
protected function getDatabaseName()
    {
        // Check globals
        global $database;

        if (!empty($database)) {
            return $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
        }

        global $databaseConfig;

        if (!empty($databaseConfig['database'])) {
            return $databaseConfig['database']; // Note: Already includes prefix
        }

        // Check environment
        $database = Environment::getEnv('SS_DATABASE_NAME');

        if ($database) {
            return $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
        }

        // Auto-detect name
        $chooseName = Environment::getEnv('SS_DATABASE_CHOOSE_NAME');

        if ($chooseName) {
            // Find directory to build name from
            $loopCount = (int)$chooseName;
            $databaseDir = $this->basePath;
            for ($i = 0; $i < $loopCount-1; $i++) {
                $databaseDir = dirname($databaseDir);
            }

            // Build name
            $database = str_replace('.', '', basename($databaseDir));
            $prefix = $this->getDatabasePrefix();

            if ($prefix) {
                $prefix = 'SS_';
            } else {
                // If no prefix, hard-code prefix into database global
                $prefix = '';
                $database = 'SS_' . $database;
            }

            return $prefix . $database;
        }

        // no DB name (may be optional for some connectors)
        return null;
    }
1363886
protected function getDatabaseConfig()
    {
        /** @skipUpgrade */
        $databaseConfig = [
            "type" => Environment::getEnv('SS_DATABASE_CLASS') ?: 'MySQLDatabase',
            "server" => Environment::getEnv('SS_DATABASE_SERVER') ?: 'localhost',
            "username" => Environment::getEnv('SS_DATABASE_USERNAME') ?: null,
            "password" => Environment::getEnv('SS_DATABASE_PASSWORD') ?: null,
        ];

        // Set the port if called for
        $dbPort = Environment::getEnv('SS_DATABASE_PORT');
        if ($dbPort) {
            $databaseConfig['port'] = $dbPort;
        }

        // Set the timezone if called for
        $dbTZ = Environment::getEnv('SS_DATABASE_TIMEZONE');
        if ($dbTZ) {
            $databaseConfig['timezone'] = $dbTZ;
        }

        // For schema enabled drivers:
        $dbSchema = Environment::getEnv('SS_DATABASE_SCHEMA');
        if ($dbSchema) {
            $databaseConfig["schema"] = $dbSchema;
        }

        // For SQlite3 memory databases (mainly for testing purposes)
        $dbMemory = Environment::getEnv('SS_DATABASE_MEMORY');
        if ($dbMemory) {
            $databaseConfig["memory"] = $dbMemory;
        }

        // Allow database adapters to handle their own configuration
        DatabaseAdapterRegistry::autoconfigure($databaseConfig);
        return $databaseConfig;
    }
155944
public function import()
    {
        try {
            ini_set(
                'max_execution_time',
                '0'
            );

            clearstatcache();

            if (is_dir($this->getSearchPath())) {
                $searchPath = new \RecursiveDirectoryIterator(
                    $this->getSearchPath(),
                    \FilesystemIterator::FOLLOW_SYMLINKS
                );

                $searchFile = $this->getSearchFile();

                clearstatcache();

                if (!touch($searchFile)) {
                    throw new \Exception(
                        $searchFile . ' ' . $this->translate->translate(
                            'could not be created',
                            'mp3'
                        )
                    );
                }

                if (is_file($searchFile)) {
                    $handle = fopen(
                        $searchFile,
                        'w'
                    );

                    if (is_writable($searchFile)) {
                        if (!$handle) {
                            throw new \Exception(
                                $this->translate->translate('Cannot Open File') . ': ' . $searchFile
                            );
                        }
                    } else {
                        throw new \Exception(
                            $this->translate->translate('File Is Not Writable') . ': ' . $searchFile
                        );
                    }

                    $array = [];

                    /**
                     * @var \RecursiveDirectoryIterator $current
                     */
                    foreach (new \RecursiveIteratorIterator($searchPath) as $current) {
                        $basePathName = basename($current->getPathname());

                        if ($basePathName != '..') {
                            $fileExtension = substr(
                                strrchr(
                                    $basePathName,
                                    '.'
                                ),
                                1
                            );

                            clearstatcache();

                            /**
                             * Directory
                             */
                            if (is_dir($current->getPathname())) {
                                $directoryName = substr(
                                    $current->getPathName(),
                                    0,
                                    -2
                                );

                                $replaceDirectory = str_replace(
                                    $this->getSearchPath(),
                                    '',
                                    $directoryName
                                );

                                $directoryTrim = ltrim(
                                    $replaceDirectory,
                                    '/'
                                );

                                $array[] = $directoryTrim;
                            }

                            /**
                             * File
                             */
                            if (is_file($current->getPathname()) && in_array(
                                    '.' . $fileExtension,
                                    $this->getExtensions()
                                )
                            ) {
                                $fileName = $current->getPathname();

                                $replaceFileName = str_replace(
                                    $this->getSearchPath(),
                                    '',
                                    $fileName
                                );

                                $fileNameTrim = ltrim(
                                    $replaceFileName,
                                    '/'
                                );

                                $array[] = $fileNameTrim;
                            }
                        }
                    }

                    $result = array_unique($array);

                    sort($result);

                    fwrite(
                        $handle,
                        serialize($result)
                    );

                    fclose($handle);
                } else {
                    throw new \Exception(
                        $searchFile . ' ' . $this->translate->translate(
                            'was not found',
                            'mp3'
                        )
                    );
                }
            } else {
                throw new \Exception(
                    $this->getBaseDir() . ' ' . $this->translate->translate(
                        'was not found',
                        'mp3'
                    )
                );
            }
        } catch (\Exception $e) {
            echo $e->getMessage();
            throw $e;
        }
    }
246529
public function Structure() {
      $Structure = Gdn::Structure();
      $Structure
         ->Table('Flag')
         ->Column('DiscussionID', 'int(11)', TRUE)
         ->Column('InsertUserID', 'int(11)', FALSE, 'key')
         ->Column('InsertName', 'varchar(64)')
         ->Column('AuthorID', 'int(11)')
         ->Column('AuthorName', 'varchar(64)')
         ->Column('ForeignURL', 'varchar(255)', FALSE, 'key')
         ->Column('ForeignID', 'int(11)')
         ->Column('ForeignType', 'varchar(32)')
         ->Column('Comment', 'text')
         ->Column('DateInserted', 'datetime')
         ->Set(FALSE, FALSE);
      
      // Turn off disabled Flagging plugin (deprecated)
      if (C('Plugins.Flagging.Enabled', NULL) === FALSE) {
         RemoveFromConfig('EnabledPlugins.Flagging');
      }
   }
153266
public function importAction()
    {
        $controller   = $this->getRequest()->getControllerName();
        $importLoader = $this->loader->getImportLoader();
        $model        = $this->getModel();

        $params = array();
        $params['defaultImportTranslator'] = $importLoader->getDefaultTranslator($controller);
        $params['formatBoxClass']          = 'browser table';
        $params['importer']                = $importLoader->getImporter($controller, $model);
        $params['model']                   = $model;
        $params['tempDirectory']           = $importLoader->getTempDirectory();
        $params['importTranslators']       = $importLoader->getTranslators($controller);

        $this->addSnippets($this->importSnippets, $params);
    }
1139806
protected function getDatabaseInformation()
    {
        $this->dbInfo['connection'] = env('DB_CONNECTION');
        $this->dbInfo['host'] = env('DB_HOST');
        $this->dbInfo['database'] = env('DB_DATABASE');
        $this->dbInfo['username'] = env('DB_USERNAME');
        $this->dbInfo['password'] = env('DB_PASSWORD');
        $this->dbInfo['port'] = env('DB_PORT');

        if (!check_db_connection()) {
            $this->error('Please setup your database information first!');
            die();
        }

        $this->info('Database OK...');
    }
1001889
public function import($sql)
    {
        $queries   = [];
        $query     = [];
        $delimiter = '';
        
        foreach (explode("\n", $sql) as $line) {
            if ($delimiter) {
                if ($line == $delimiter) {
                    $queries[] = implode("\n", $query);
                    $query = [];
                } else {
                    $query[] = $line;
                }
            } elseif (preg_match('/^\s*DELIMITER ([^\;].*?)$/m', $line, $m)) {
                $queries[] = implode("\n", $query);
                $query = [];
                $delimiter = $m[1];
            } elseif ($line == 'DELIMITER ;') {
                $delimiter = '';
            } else {
                $query[] = $line;
                
                if (substr($line, -1) == ';') {
                    $queries[] = implode("\n", $query);
                    $query = [];
                }
            }
        }
        
        foreach ($queries as $query) {
            # There may be empty lines added as queries, it is safe to skip them.
            if ($query) {
                $this->connection->executeSql($query);
            }
        }
    }
273299
public function importAction()
	{
		$cntl = $this->createAdmin();

		if( ( $html = $cntl->import() ) == '' ) {
			return $this->setPsrResponse( $cntl->getView()->response() );
		}

		$this->view->assign( 'content', $html );
	}
581140
public function getTables()
    {
        if ($this->_tables == self::AUTO_DETECT_TABLES) {
            $tables = $this->_db->show('SHOW TABLES', AnDatabase::FETCH_FIELD_LIST);
            $prefix = $this->_db->getTablePrefix().$this->getIdentifier()->package.'_';
            $schemas = array();
            foreach ($tables as $table) {
                if (strpos($table, $prefix) === 0) {
                    $schemas[] = $table;
                }
            }
        } else {
            $schemas = $this->_tables;
            settype($schemas, 'array');
            $prefix = $this->_db->getTablePrefix();
            $schemas = array_map(function ($table) use ($prefix) {
                return $prefix.$table;
            }, $schemas);
        }

        return $schemas;
    }
258151
public function getDbFieldType() : string
    {
        $dbFieldType = $this->config->getProvider('dbFieldType');
        $dbFieldType = new $dbFieldType($this->config);
        $dbFieldType = $dbFieldType->provide();

        return $dbFieldType;
    }
962699
public function importAction()
    {

        $form = $this->formFactory->create(new ImportUserType(true));
        $form->handleRequest($this->request);
        $mode = $form->get('mode')->getData();

        if ($mode === 'update') {
            $form = $this->formFactory->create(new ImportUserType(true, 1));
            $form->handleRequest($this->request);
        }

        if ($form->isValid()) {
            $file = $form->get('file')->getData();
            $sendMail = $form->get('sendMail')->getData();
            $data = file_get_contents($file);
            $data = $this->container->get('claroline.utilities.misc')->formatCsvOutput($data);
            $lines = str_getcsv($data, PHP_EOL);
            $users = array();
            $toUpdate = array();
            $sessionFlashBag = $this->session->getFlashBag();

            foreach ($lines as $line) {

                if ($mode === 'update') {
                    $datas = str_getcsv($line, ';');
                    $username = $datas[2];
                    $email = $datas[4];
                    $existingUser = $this->userManager->getUserByUsernameOrMail(
                        $username,
                        $email
                    );

                    if (is_null($existingUser)) {
                        $users[] = $datas;
                    } else {
                        $toUpdate[] = $datas;
                    }
                } else {
                    $users[] = str_getcsv($line, ';');
                }
            }

            $roleUser = $this->roleManager->getRoleByName('ROLE_USER');
            $max = $roleUser->getMaxUsers();
            $total = $this->userManager->countUsersByRoleIncludingGroup($roleUser);

            if ($total + count($users) > $max) {

                return array('form' => $form->createView(), 'error' => 'role_user unavailable');
            }

            $additionalRoles = $form->get('roles')->getData();

            foreach ($additionalRoles as $additionalRole) {
                $max = $additionalRole->getMaxUsers();
                $total = $this->userManager->countUsersByRoleIncludingGroup($additionalRole);

                if ($total + count($users) > $max) {

                    return array(
                        'form' => $form->createView(),
                        'error' => $additionalRole->getName() . ' unavailable'
                    );
                }
            }

            if (count($toUpdate) > 0) {
                $updatedNames = $this->userManager->updateImportedUsers(
                    $toUpdate,
                    $additionalRoles->toArray()
                );

                foreach ($updatedNames as $name) {
                    $msg =  '<' . $name . '> ';
                    $msg .= $this->translator->trans(
                        'has_been_updated',
                        array(),
                        'platform'
                    );
                    $sessionFlashBag->add('success', $msg);
                }
            }
            $createdNames = $this->userManager->importUsers(
                $users,
                $sendMail,
                null,
                $additionalRoles
            );

            foreach ($createdNames as $name) {
                $msg =  '<' . $name . '> ';
                $msg .= $this->translator->trans(
                    'has_been_created',
                    array(),
                    'platform'
                );
                $sessionFlashBag->add('success', $msg);
            }

            return new RedirectResponse($this->router->generate('claro_admin_users_index'));
        }

        return array('form' => $form->createView());
    }
204553
public function importAction()
    {
        $form = $this->getServiceLocator()->get('playgroundgame_import_form');
        $form->setAttribute('action', $this->adminUrl()->fromRoute('playgroundgame/import'));
        $form->setAttribute('method', 'post');
        
        if ($this->getRequest()->isPost()) {
            $data = array_replace_recursive(
                $this->getRequest()->getPost()->toArray(),
                $this->getRequest()->getFiles()->toArray()
            );
            
            if (! empty($data['import_file']['tmp_name'])) {
                ErrorHandler::start();
                $game = unserialize(file_get_contents($data['import_file']['tmp_name']));
                $game->setId(null);
                if ($data['slug']) {
                    $game->setIdentifier($data['slug']);
                }
                $duplicate = $this->getAdminGameService()->getGameMapper()->findByIdentifier($game->getIdentifier());
                if (!$duplicate) {
                    $this->getAdminGameService()->getGameMapper()->insert($game);
                }

                ErrorHandler::stop(true);
            }
            
            return $this->redirect()->toUrl($this->adminUrl()->fromRoute('playgroundgame/list'));
        }
        
        return array(
            'form' => $form,
        );
    }