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/repo/lang/de.php b/module/repo/lang/de.php index c425ff526e..77110e47cf 100644 --- a/module/repo/lang/de.php +++ b/module/repo/lang/de.php @@ -100,7 +100,7 @@ $lang->repo->split = "Split Mark"; $lang->repo->objectRule = 'Object Rule'; $lang->repo->objectIdRule = 'Object ID Rule'; -$lang->repo->actionRule = 'Action RUle'; +$lang->repo->actionRule = 'Action Rule'; $lang->repo->manHourRule = 'Man-hour Rule'; $lang->repo->ruleUnit = "Unit"; $lang->repo->ruleSplit = "Multiple keywords are divided by ';'. For example: task multiple keywords: Task;task"; diff --git a/module/repo/lang/en.php b/module/repo/lang/en.php index c425ff526e..3e1e97b449 100644 --- a/module/repo/lang/en.php +++ b/module/repo/lang/en.php @@ -7,9 +7,9 @@ $lang->repo->createAction = 'Create Repo'; $lang->repo->edit = 'Edit'; $lang->repo->editAction = 'Edit Repo'; $lang->repo->delete = 'Delete Repo'; -$lang->repo->showSyncCommit = 'Display Synchronization'; +$lang->repo->showSyncCommit = 'Display Sync'; $lang->repo->ajaxSyncCommit = 'Interface: Ajax Sync Note'; -$lang->repo->setRules = 'Set rules'; +$lang->repo->setRules = 'Set Rules'; $lang->repo->download = 'Download File'; $lang->repo->downloadDiff = 'Download Diff'; $lang->repo->diffAction = 'Revision Diff'; @@ -90,7 +90,7 @@ $lang->repo->openedDate = 'CreatedDate'; $lang->repo->latestRevision = 'Latest Revision'; $lang->repo->actionInfo = "Add by %s in %s"; $lang->repo->changes = "Change Log"; -$lang->repo->reviewLocation = "File: %s@%s, line:%s - %s"; +$lang->repo->reviewLocation = "File: %s@%s, Line: %s - %s"; $lang->repo->commentEdit = ''; $lang->repo->commentDelete = ''; $lang->repo->allChanges = "Other Changes"; @@ -100,7 +100,7 @@ $lang->repo->split = "Split Mark"; $lang->repo->objectRule = 'Object Rule'; $lang->repo->objectIdRule = 'Object ID Rule'; -$lang->repo->actionRule = 'Action RUle'; +$lang->repo->actionRule = 'Action Rule'; $lang->repo->manHourRule = 'Man-hour Rule'; $lang->repo->ruleUnit = "Unit"; $lang->repo->ruleSplit = "Multiple keywords are divided by ';'. For example: task multiple keywords: Task;task"; @@ -119,17 +119,17 @@ $lang->repo->encodingList['utf_8'] = 'UTF-8'; $lang->repo->encodingList['gbk'] = 'GBK'; $lang->repo->scmList['Git'] = 'Git'; -$lang->repo->scmList['Subversion'] = 'Subversion'; +$lang->repo->scmList['Subversion'] = 'SVN'; $lang->repo->notice = new stdclass(); $lang->repo->notice->syncing = 'Synchronizing. Please wait ...'; $lang->repo->notice->syncComplete = 'Synchronized. Now redirecting ...'; $lang->repo->notice->syncedCount = 'The number of records synchronized is '; -$lang->repo->notice->delete = 'Are you sure delete this repo?'; +$lang->repo->notice->delete = 'Do you want to delete this repo?'; $lang->repo->notice->successDelete = 'Repository is removed.'; $lang->repo->notice->commentContent = 'Comment'; -$lang->repo->notice->deleteBug = 'Are you sure to delete this bug?'; -$lang->repo->notice->deleteComment = 'Are you sure to delete this comment?'; +$lang->repo->notice->deleteBug = 'Do you want to delete this bug?'; +$lang->repo->notice->deleteComment = 'Do you want to delete this comment?'; $lang->repo->notice->lastSyncTime = 'Last Sync:'; $lang->repo->rules = new stdclass(); diff --git a/module/repo/lang/fr.php b/module/repo/lang/fr.php index c425ff526e..77110e47cf 100644 --- a/module/repo/lang/fr.php +++ b/module/repo/lang/fr.php @@ -100,7 +100,7 @@ $lang->repo->split = "Split Mark"; $lang->repo->objectRule = 'Object Rule'; $lang->repo->objectIdRule = 'Object ID Rule'; -$lang->repo->actionRule = 'Action RUle'; +$lang->repo->actionRule = 'Action Rule'; $lang->repo->manHourRule = 'Man-hour Rule'; $lang->repo->ruleUnit = "Unit"; $lang->repo->ruleSplit = "Multiple keywords are divided by ';'. For example: task multiple keywords: Task;task";