Gets a information about the current database - Monostate for Dibi\Connection::getDatabaseInfo().
public static getDatabaseInfo ( ) : Dibi\Reflection\Database | ||
return | Dibi\Reflection\Database |
/** * */ public function indexAction() { die('todo'); $overwrite = !is_null(Core_Request::getInstance()->getArgv(4)) ? Core_Request::getInstance()->getArgv(4) : false; foreach (dibi::getDatabaseInfo()->getTables() as $table_data) { if ($table_data->getName() == Migration_MigrationModel::getTableName()) { continue; } $ddl_data = dibi::query('SHOW CREATE TABLE ' . $table_data->getName())->fetch()->toArray(); $ddl_query = $ddl_data['Create Table']; $migration_time = time(); $migration_name = 'Create' . ucfirst($table_data->getName()); $migration_name = str_replace(' ', '', $migration_name); $migration_name = str_replace('-', '', $migration_name); $migration_name = str_replace('_', '', $migration_name); $filename = cfg()->migration_path . $migration_name . '.php'; if (Core_Files::fileSize($filename) && !$overwrite) { echo PHP_EOL . 'Migration "Create ' . ucfirst($table_data->getName()) . '" Exists' . PHP_EOL; continue; } $template_data = Core_Files::getContent(cfg()->migration_path . Migration_FilesHelper::TEMPLATE_FILE_NAME); $template_data = str_replace('Template', $migration_name, $template_data); $template_data = str_replace('__NAME__', $migration_name, $template_data); $template_data = str_replace('__CREATED_AT__', $migration_time, $template_data); $template_data = str_replace('__CREATED_CFG__', Core_Request::getInstance()->getArgv(1), $template_data); $template_data = preg_replace('#//__UP_ACTION__#', $ddl_query, $template_data); $down_query = 'DROP TABLE IF EXISTS `' . $table_data->getName() . '`'; $template_data = preg_replace('#//__DOWN_ACTION__#', $down_query, $template_data); Core_Files::putContent($filename, $template_data); echo PHP_EOL . 'Migration ' . $filename . ' created' . PHP_EOL; } }
<!DOCTYPE html><link rel="stylesheet" href="data/style.css"> <h1>Database Reflection | dibi</h1> <?php require_once 'Nette/Debug.php'; require_once '../dibi/dibi.php'; dibi::connect(array('driver' => 'sqlite', 'database' => 'data/sample.sdb')); // retrieve database reflection $database = dibi::getDatabaseInfo(); echo "<h2>Database '{$database->name}'</h2>\n"; echo "<ul>\n"; foreach ($database->getTables() as $table) { echo '<li>', ($table->view ? 'view' : 'table') . " {$table->name}</li>\n"; } echo "</ul>\n"; // table reflection $table = $database->getTable('products'); echo "<h2>Table '{$table->name}'</h2>\n"; echo "Columns\n"; echo "<ul>\n"; foreach ($table->getColumns() as $column) { echo "<li>{$column->name} <i>{$column->nativeType}</i> <code>{$column->default}</code></li>\n"; } echo "</ul>\n"; echo "Indexes"; echo "<ul>\n"; foreach ($table->getIndexes() as $index) { echo "<li>{$index->name} " . ($index->primary ? 'primary ' : '') . ($index->unique ? 'unique' : '') . ' ('; foreach ($index->getColumns() as $column) { echo "{$column->name}, ";
/** * Does the configuration storage exist? * Will return true if all schema objects are available. * * @see server/classes/AbstractAjxpUser#storageExists() * @return boolean false if storage does not exist */ function storageExists() { $this->log('Checking for existence of AJXP_User storage...'); try { $dbinfo = dibi::getDatabaseInfo(); $dbtables = $dbinfo->getTableNames(); if (!in_array('ajxp_user_rights', $dbtables) || !in_array('ajxp_user_prefs', $dbtables) || !in_array('ajxp_user_bookmarks', $dbtables)) { return false; } } catch (DibiException $e) { return false; } return true; }
/** * Does the configuration storage exist? * Will return true if all schema objects are available. * * @see AbstractAjxpUser#storageExists() * @return boolean false if storage does not exist */ function storageExists() { $this->log('Checking for existence of AJXP_User storage...'); try { $dbinfo = dibi::getDatabaseInfo(); $dbtables = $dbinfo->getTableNames(); if (!in_array('ajxp_user_rights', $dbtables) || !in_array('ajxp_user_prefs', $dbtables) || !in_array('ajxp_user_bookmarks', $dbtables)) { return false; } //$result_rights = dibi::query('SELECT [repo_uuid], [rights] FROM [ajxp_user_rights] WHERE [login] = %s', $this->getId()); //$this->rights = $result_rights->fetchPairs('repo_uuid', 'rights'); $this->load(); if (!isset($this->rights["ajxp.admin"])) { return false; } } catch (DibiException $e) { return false; } return true; }