本文整理汇总了PHP中waModel::describe方法的典型用法代码示例。如果您正苦于以下问题:PHP waModel::describe方法的具体用法?PHP waModel::describe怎么用?PHP waModel::describe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类waModel
的用法示例。
在下文中一共展示了waModel::describe方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateSchema
protected function generateSchema($app_id, $tables = array())
{
$plugin_id = false;
if (strpos($app_id, '/') !== false) {
list($app_id, $plugin_id) = explode('/', $app_id, 2);
$path = wa()->getConfig()->getAppsPath($app_id, 'plugins/' . $plugin_id . '/lib/config/db.php');
} else {
$path = wa()->getConfig()->getAppsPath($app_id, 'lib/config/db.php');
}
if (waRequest::param('update') !== null) {
$schema = (include $path);
if (!$tables) {
$tables = array_keys($schema);
}
} elseif ($tables) {
if (!is_array($tables)) {
$tables = array($tables);
}
} else {
$prefix = $app_id == 'webasyst' ? 'wa' : $app_id;
if ($plugin_id) {
$prefix .= '_' . $plugin_id;
}
// @todo: use db adapter to get tables
$sql = "SHOW TABLES LIKE '" . $prefix . "\\_%'";
$tables = $this->model->query($sql)->fetchAll(null, true);
$sql = "SHOW TABLES LIKE '" . $prefix . "'";
$tables = array_merge($tables, $this->model->query($sql)->fetchAll(null, true));
}
$schema = array();
foreach ($tables as $t) {
echo $t . "\n";
try {
$schema[$t] = $this->model->describe($t, 1);
} catch (waDbException $ex) {
print "\tError: " . $ex->getMessage() . "\n";
}
}
if ($schema) {
// save schema to lib/config/db.php of the app
waUtils::varExportToFile($this->schemaToString($schema), $path, false);
}
}
示例2: generateSchema
protected function generateSchema($app_id, $tables = array())
{
$plugin_id = false;
if (strpos($app_id, '/') !== false) {
list($app_id, $plugin_id) = explode('/', $app_id, 2);
$path = wa()->getConfig()->getAppsPath($app_id, 'plugins/' . $plugin_id . '/lib/config/db.php');
} else {
$path = wa()->getConfig()->getAppsPath($app_id, 'lib/config/db.php');
}
$exists_schema = array();
if (file_exists($path)) {
$schema = (include $path);
$exists_schema = $schema;
$exists_tables = array_keys($schema);
} else {
$exists_tables = array();
}
$exclude_patterns = array();
if (!in_array($this->getParam('update'), array('all', 'none'))) {
if (!$tables) {
$tables = $exists_tables;
}
} elseif ($tables) {
if (!is_array($tables)) {
$tables = array($tables);
}
//TODO add pattern support
} else {
$exclude = array();
if ($app_id == 'webasyst') {
$prefix = 'wa';
} else {
$prefix = $app_id;
if ($plugin_id) {
$prefix .= '_' . $plugin_id;
} else {
if (SystemConfig::isDebug()) {
$plugins = waFiles::listdir(wa()->getConfig()->getAppsPath($app_id, 'plugins/'));
foreach ($plugins as $_id => $plugin_id) {
if (!preg_match('@^[a-z][a-z0-9_]+$@', $plugin_id)) {
unset($plugins[$_id]);
}
}
$plugins = array_values($plugins);
} else {
$plugins = wa($app_id)->getConfig()->getPlugins();
$plugins = array_keys($plugins);
}
foreach ($plugins as $plugin_id) {
if ($this->getParam('ignore') == 'pattern') {
$plugin_prefix = $app_id . '_' . $plugin_id;
if (in_array($plugin_prefix, $exists_tables)) {
print sprintf("Warning: Plugin %s has conflicted table namespace\n", $plugin_id);
}
$exclude = array_merge($exclude, $this->getTables($plugin_prefix));
} elseif ($this->getParam('ignore') == 'config') {
$plugin_path = wa()->getConfig()->getAppsPath($app_id, 'plugins/' . $plugin_id . '/lib/config/db.php');
if (file_exists($plugin_path)) {
$exclude_tables = (include $plugin_path);
if (is_array($exclude_tables)) {
$exclude = array_merge($exclude, array_keys($exclude_tables));
}
}
}
$exclude_patterns[] = sprintf('@(^%1$s$|^%1$s_|_%1$s$)@', $plugin_id);
}
}
}
$tables = $this->getTables($prefix);
$tables = array_diff($tables, $exclude);
}
print str_repeat('-', 120) . "\n";
echo sprintf("%s\n", $app_id);
$schema = array();
if ($exists_tables || $tables) {
$max = max(array_map('strlen', array_merge($exists_tables, array_keys($tables), array('12345678'))));
$format = "%s|%-{$max}s|%8s|%30s|%30s\n";
print str_repeat('-', 120) . "\n";
echo sprintf($format, 'S', 'TABLE', 'STATUS', 'FIELDS', 'KEYS');
print str_repeat('-', 120) . "\n";
foreach ($tables as $t) {
try {
$schema[$t] = $this->model->describe($t, 1);
if (in_array($t, $exists_tables)) {
$compare = $this->compareTable($schema[$t], $exists_schema[$t], $exclude_patterns);
} else {
$compare = array('s' => '+', 'c' => 'ADDED');
}
} catch (waDbException $ex) {
$compare = array('s' => '!', 'c' => 'ERROR: ' . $ex->getMessage());
}
if ($compare['s'] !== '=' || $this->getParam('view') == 'all') {
echo sprintf($format, $compare['s'], $t, $compare['c'], ifset($compare['r']['FIELDS']), ifset($compare['r']['KEYS']));
}
}
foreach ($exists_tables as $t) {
if (!isset($schema[$t])) {
$s = '-';
$c = 'DELETED';
echo sprintf($format, $s, $t, $c, '', '');
//.........这里部分代码省略.........