diff --git a/Makefile b/Makefile index b53a1c6e0d..a040894b5b 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,7 @@ zentaoxx: cp -r xuan/xxb/module/client zentaoxx/module/ cp -r xuan/xxb/module/license zentaoxx/module/ cp -r xuan/xxb/module/owt zentaoxx/module/ + cp xuan/xxb/apischeme.json zentaoxx/ mkdir -p zentaoxx/module/common/view cp -r xuan/xxb/module/common/view/header.modal.html.php zentaoxx/module/common/view cp -r xuan/xxb/module/common/view/marked.html.php zentaoxx/module/common/view diff --git a/framework/base/router.class.php b/framework/base/router.class.php index ed768a633a..10604d95a2 100644 --- a/framework/base/router.class.php +++ b/framework/base/router.class.php @@ -1378,7 +1378,7 @@ class baseRouter if(empty($extFiles) and empty($hookFiles)) return $mainModelFile; /* 计算合并之后的modelFile路径。Compute the merged model file path. */ - $extModelPrefix = ($siteExtended and !empty($this->siteCode)) ? $this->siteCode{0} . DS . $this->siteCode : ''; + $extModelPrefix = ($siteExtended and !empty($this->siteCode)) ? $this->siteCode[0] . DS . $this->siteCode : ''; $mergedModelDir = $this->getTmpRoot() . 'model' . DS . ($extModelPrefix ? $extModelPrefix . DS : ''); $mergedModelFile = $mergedModelDir . $moduleName . '.php'; if(!is_dir($mergedModelDir)) mkdir($mergedModelDir, 0755, true); diff --git a/lib/purifier/HTMLPurifier/ChildDef/Custom.php b/lib/purifier/HTMLPurifier/ChildDef/Custom.php index 1047cd8e8b..cc84d89908 100644 --- a/lib/purifier/HTMLPurifier/ChildDef/Custom.php +++ b/lib/purifier/HTMLPurifier/ChildDef/Custom.php @@ -45,7 +45,7 @@ class HTMLPurifier_ChildDef_Custom extends HTMLPurifier_ChildDef protected function _compileRegex() { $raw = str_replace(' ', '', $this->dtd_regex); - if ($raw{0} != '(') { + if ($raw[0] != '(') { $raw = "($raw)"; } $el = '[#a-zA-Z0-9_.-]+'; diff --git a/lib/purifier/HTMLPurifier/TagTransform/Font.php b/lib/purifier/HTMLPurifier/TagTransform/Font.php index 2a186515e2..99e01658cc 100644 --- a/lib/purifier/HTMLPurifier/TagTransform/Font.php +++ b/lib/purifier/HTMLPurifier/TagTransform/Font.php @@ -75,7 +75,7 @@ class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform if (isset($attr['size'])) { // normalize large numbers if ($attr['size'] !== '') { - if ($attr['size']{0} == '+' || $attr['size']{0} == '-') { + if ($attr['size'][0] == '+' || $attr['size'][0] == '-') { $size = (int)$attr['size']; if ($size < -2) { $attr['size'] = '-2'; diff --git a/lib/scm/gitrepo.class.php b/lib/scm/gitrepo.class.php index 2478569f16..304c9dbce3 100644 --- a/lib/scm/gitrepo.class.php +++ b/lib/scm/gitrepo.class.php @@ -124,7 +124,7 @@ class GitRepo $branches = array(); foreach($list as $localBranch) { - if($localBranch{0} == '*') $localBranch = substr($localBranch, 1); + if($localBranch[0] == '*') $localBranch = substr($localBranch, 1); $localBranch = trim($localBranch); if(empty($localBranch))continue; @@ -216,7 +216,7 @@ class GitRepo foreach($list as $line) { if(empty($line)) continue; - if($line{0} == '^') $line = substr($line, 1); + if($line[0] == '^') $line = substr($line, 1); preg_match('/^([0-9a-f]{39,40})\s.*\((\S+)\s+([\d-]+)\s(.*)\s(\d+)\)(.*)$/U', $line, $matches); if(isset($matches[1]) and $matches[1] != $revision) @@ -385,7 +385,7 @@ class GitRepo $line = $lines[$i]; if(strpos($line, '\ No newline at end of file') === 0)continue; - $sign = empty($line) ? '' : $line{0}; + $sign = empty($line) ? '' : $line[0]; if($sign == '-' and $newFile) $sign = '+'; $type = $sign != '-' ? $sign == '+' ? 'new' : 'all' : 'old'; if($sign == '-' || $sign == '+') diff --git a/lib/scm/subversion.class.php b/lib/scm/subversion.class.php index 02e80e8efa..5eb5b3a63f 100644 --- a/lib/scm/subversion.class.php +++ b/lib/scm/subversion.class.php @@ -447,7 +447,7 @@ class Subversion $line = $lines[$i]; if(strpos($line, '\ No newline at end of file') === 0)continue; - $sign = empty($line) ? '' : $line{0}; + $sign = empty($line) ? '' : $line[0]; $type = $sign != '-' ? $sign == '+' ? 'new' : 'all' : 'old'; if($sign == '-' || $sign == '+') $line = substr_replace($line, ' ', 1, 0); diff --git a/lib/zdb/zdb.class.php b/lib/zdb/zdb.class.php index d70f4526f9..1a5cceca37 100644 --- a/lib/zdb/zdb.class.php +++ b/lib/zdb/zdb.class.php @@ -12,16 +12,16 @@ class zdb { /** - * dbh - * - * @var object + * dbh + * + * @var object * @access public */ public $dbh; /** - * Construct - * + * Construct + * * @access public * @return void */ @@ -33,33 +33,159 @@ class zdb /** * Get all tables. - * + * + * @param string $type if type is 'base', just get base table. * @access public * @return array */ - public function getAllTables() + public function getAllTables($type = 'base') { global $config; $allTables = array(); $stmt = $this->dbh->query("show full tables"); - while($table = $stmt->fetch(PDO::FETCH_ASSOC)) + while($table = $stmt->fetch(PDO::FETCH_ASSOC)) { $tableType = strtolower($table['Table_type']); - if($tableType != 'base table') continue; + if($type == 'base' and $tableType != 'base table') continue; $tableName = $table["Tables_in_{$config->db->name}"]; - $allTables[$tableName] = 'table'; + $allTables[$tableName] = $tableType == 'base table' ? 'table' : $tableType; } return $allTables; } /** - * Dump db. - * - * @param string $fileName - * @param array $tables + * Get table fields. + * + * @param string $table + * @access public + * @return array + */ + public function getTableFields($table) + { + try + { + $this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); + $sql = "DESC $table"; + $rawFields = $this->dbh->query($sql)->fetchAll(); + $this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); + } + catch (PDOException $e) + { + global $dao; + $dao->sqlError($e); + } + + $fields = array(); + foreach($rawFields as $field) $fields[$field->field] = $field; + + return $fields; + } + + /** + * Diff current table fields with a fields array. + * + * @param string $table + * @param array $fields + * @access public + * @return array + */ + public function diffTable($table, $fields) + { + $tableFields = $this->getTableFields($table); + + $diff = array_udiff_assoc($fields, $tableFields, + function($a, $b) + { + return (array)$a == (array)$b ? 0 : 1; + } + ); + + return $diff; + } + + /** + * Add a column to a table, or modify a existing column. + * + * @param string $table + * @param object $column + * @param boolean $add if true, add $column as a new column, otherwise modify a existing column to $column. + * @access public + * @return object + */ + public function updateColumn($table, $column, $add = true) + { + $return = new stdclass(); + $return->result = true; + $return->error = ''; + + $query = "ALTER TABLE `$table` " . ($add ? 'ADD' : 'MODIFY COLUMN') . " `$column->field` $column->type" . ($column->null == 'NO' ? ' NOT NULL' : '') . (is_null($column->default) ? '' : " DEFAULT '$column->default'") . (empty($column->extra) ? '' : " $column->extra") . ';'; + + try + { + $this->dbh->exec($query); + return $return; + } + catch(PDOException $e) + { + $return->result = false; + $return->error = $e->getMessage(); + $return->sql = $query; + return $return; + } + } + + /** + * Create a table with fields. + * + * @param string $name + * @param array $fields + * @access public + * @return object + */ + public function createTable($name, $fields) + { + $return = new stdclass(); + $return->result = true; + $return->error = ''; + $createTableQuery = "CREATE TABLE `$name` ("; + + foreach($fields as $field) + { + $createColumnQuery = "`$field->field` $field->type" . ($field->null == 'NO' ? ' NOT NULL' : '') . (is_null($field->default) ? '' : " DEFAULT '$field->default'") . (empty($field->extra) ? '' : " $field->extra") . ", "; + if(!empty($field->key)) + { + if($field->key === 'PRI') $createColumnQuery .= "PRIMARY KEY (`{$field->field}`), "; + if($field->key === 'MUL') $createColumnQuery .= "KEY `{$field->field}` (`{$field->field}`), "; + if($field->key === 'UNI') $createColumnQuery .= "UNIQUE KEY `{$field->field}` (`{$field->field}`), "; + } + $createTableQuery .= $createColumnQuery; + } + + $createTableQuery = rtrim($createTableQuery, ', '); + $createTableQuery .= ") ENGINE=MyISAM DEFAULT CHARSET=utf8;"; + + try + { + $this->dbh->exec($createTableQuery); + return $return; + } + catch(PDOException $e) + { + $return->result = false; + $return->error = $e->getMessage(); + $return->sql = $createTableQuery; + return $return; + } + } + + /** + * Dump db. + * + * @param string $fileName + * @param array $tables * @access public * @return object */ @@ -139,10 +265,11 @@ class zdb } /** - * Import DB - * + * Import DB + * + * @param string $fileName * @access public - * @return object; + * @return object */ public function import($fileName) { @@ -210,10 +337,10 @@ class zdb /** * Get schema SQL. - * - * @param string $table + * + * @param string $table * @access public - * @return string + * @return object */ public function getSchemaSQL($table, $type = 'table') { diff --git a/module/common/model.php b/module/common/model.php index 81d73d047f..d7e3093493 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -254,7 +254,7 @@ class commonModel extends model { echo '