diff --git a/app/classes/BaseController.php b/app/classes/BaseController.php index 2abdeb4..b189451 100644 --- a/app/classes/BaseController.php +++ b/app/classes/BaseController.php @@ -248,28 +248,6 @@ protected function _highlight($var, $format = "array", $label = false) { return $string; } - /** - * format bytes to human size - * - * @param integer $bytes size in byte - * @return string size in k, m, g.. - **/ - protected function _formatBytes($bytes) { - if ($bytes < 1024) { - return $bytes; - } - if ($bytes < 1024 * 1024) { - return round($bytes/1024, 2) . "k"; - } - if ($bytes < 1024 * 1024 * 1024) { - return round($bytes/1024/1024, 2) . "m"; - } - if ($bytes < 1024 * 1024 * 1024 * 1024) { - return round($bytes/1024/1024/1024, 2) . "g"; - } - return $bytes; - } - /** * Enter description here... * diff --git a/app/controllers/collection.php b/app/controllers/collection.php index 6da63ed..4e64b71 100644 --- a/app/controllers/collection.php +++ b/app/controllers/collection.php @@ -904,7 +904,7 @@ public function doCollectionStats() { if ($ret["ok"]) { $this->stats = $ret; foreach ($this->stats as $index => $stat) { - if (is_array($stat)) { + if (is_array($stat) || is_bool($stat)) { $this->stats[$index] = $this->_highlight($stat, "json"); } } @@ -961,7 +961,7 @@ public function doCollectionRename() { $this->ret = $this->_mongo->selectDB($this->db)->execute('function (coll, newname, dropExists) { db.getCollection(coll).renameCollection(newname, dropExists);}', array( $oldname, $newname, (bool)$removeExists )); if ($this->ret["ok"]) { $this->realName = $newname; - $this->message = "Operation success."; + $this->message = "Operation success. db}&collection={$newname}\">[GO »]"; } else { $this->error = "Operation failure"; @@ -976,23 +976,20 @@ public function doCollectionProps() { $this->db = xn("db"); $this->collection = xn("collection"); - $ret = $this->_mongo->selectDB($this->db)->command(array( "collStats" => $this->collection )); - - if (!$ret["ok"]) { - exit("There is something wrong:{$ret['errmsg']}, please refresh the page to try again."); - } + $ret = $this->_mongo->selectDB($this->db)->selectCollection("system.namespaces")->findOne(array( + "name" => $this->db . "." . $this->collection + )); $this->isCapped = 0; $this->size = 0; $this->max = 0; - $options = $ret; - if (isset($options["capped"])) { - $this->isCapped = $options["capped"]; + if (isset($ret["options"]["capped"])) { + $this->isCapped = $ret["options"]["capped"]; } - if (isset($options["size"])) { - $this->size = $options["size"]; + if (isset($ret["options"]["size"])) { + $this->size = $ret["options"]["size"]; } - if (isset($options["max"])) { - $this->max = $options["max"]; + if (isset($ret["options"]["max"])) { + $this->max = $ret["options"]["max"]; } if ($this->isPost()) { $this->isCapped = xi("is_capped"); @@ -1010,7 +1007,11 @@ public function doCollectionProps() { //create new collection $db = $this->_mongo->selectDB($this->db); - $db->createCollection($this->collection, $this->isCapped, $this->size, $this->max); + MCollection::createCollection($db, $this->collection, array( + "capped" => $this->isCapped, + "size" => $this->size, + "max" => $this->max + )); //copy data to new collection if (!$this->_copyCollection($db, $bkCollection, $this->collection, true)) { diff --git a/app/controllers/db.php b/app/controllers/db.php index a585c52..cc15748 100644 --- a/app/controllers/db.php +++ b/app/controllers/db.php @@ -22,16 +22,16 @@ public function doIndex() { $ret = array_merge($ret, $db->command(array("dbstats" => 1))); $ret["diskSize"] = "-"; if (isset($ret["sizeOnDisk"])) { - $ret["diskSize"] = $this->_formatBytes($ret["sizeOnDisk"]); + $ret["diskSize"] = r_human_bytes($ret["sizeOnDisk"]); } if(isset($ret["dataSize"])) { - $ret["dataSize"] = $this->_formatBytes($ret["dataSize"]); + $ret["dataSize"] = r_human_bytes($ret["dataSize"]); } if(isset($ret["storageSize"])) { - $ret["storageSize"] = $this->_formatBytes($ret["storageSize"]); + $ret["storageSize"] = r_human_bytes($ret["storageSize"]); } if(isset($ret["indexSize"])) { - $ret["indexSize"] = $this->_formatBytes($ret["indexSize"]); + $ret["indexSize"] = r_human_bytes($ret["indexSize"]); } @@ -444,8 +444,13 @@ public function doNewCollection() { if ($this->isPost()) { $db = $this->_mongo->selectDB($this->db); - $db->createCollection($this->name, $this->isCapped, $this->size, $this->max); - $this->message = "New collection is created."; + + MCollection::createCollection($db, $this->name, array( + "capped" => $this->isCapped, + "size" => $this->size, + "max" => $this->max + )); + $this->message = "New collection is created. db}&collection={$this->name}\">[GO »]"; //add index if (!$this->isCapped) { diff --git a/app/controllers/server.php b/app/controllers/server.php index 16c0fa8..95e483e 100644 --- a/app/controllers/server.php +++ b/app/controllers/server.php @@ -6,7 +6,7 @@ class ServerController extends BaseController { /** server infomation **/ public function doIndex() { $db = $this->_mongo->selectDB("admin"); - + //command line try { $query = $db->command(array("getCmdLineOpts" => 1)); @@ -19,7 +19,7 @@ public function doIndex() { } catch (Exception $e) { $this->commandLine = ""; } - + //web server $this->webServers = array(); if (isset($_SERVER["SERVER_SOFTWARE"])) { @@ -28,9 +28,9 @@ public function doIndex() { } $this->webServers["PHP version"] = "PHP " . PHP_VERSION; $this->webServers["PHP extension"] = "mongo/" . RMongo::getVersion(); - + $this->directives = ini_get_all("mongo"); - + //build info $this->buildInfos = array(); try { @@ -40,9 +40,9 @@ public function doIndex() { $this->buildInfos = $ret; } } catch (Exception $e) { - + } - + //connection $this->connections = array( "Host" => $this->_server->mongoHost(), @@ -50,14 +50,14 @@ public function doIndex() { "Username" => "******", "Password" => "******" ); - + $this->display(); } - + /** Server Status **/ public function doStatus() { $this->status = array(); - + try { //status $db = $this->_mongo->selectDB("admin"); @@ -76,12 +76,12 @@ public function doStatus() { } } } catch (Exception $e) { - + } - + $this->display(); - } - + } + /** show databases **/ public function doDatabases() { $ret = $this->_server->listDbs(); @@ -91,34 +91,34 @@ public function doDatabases() { $ret = $mongodb->command(array("dbstats" => 1)); $ret["collections"] = count(MDb::listCollections($mongodb)); if (isset($db["sizeOnDisk"])) { - $ret["diskSize"] = $this->_formatBytes($db["sizeOnDisk"]); - $ret["dataSize"] = $this->_formatBytes($ret["dataSize"]); + $ret["diskSize"] = r_human_bytes($db["sizeOnDisk"]); + $ret["dataSize"] = r_human_bytes($ret["dataSize"]); } else { $ret["diskSize"] = "-"; $ret["dataSize"] = "-"; } - $ret["storageSize"] = $this->_formatBytes($ret["storageSize"]); - $ret["indexSize"] = $this->_formatBytes($ret["indexSize"]); + $ret["storageSize"] = r_human_bytes($ret["storageSize"]); + $ret["indexSize"] = r_human_bytes($ret["indexSize"]); $this->dbs[$index] = array_merge($this->dbs[$index], $ret); - + } $this->dbs = rock_array_sort($this->dbs, "name"); $this->display(); - } - + } + /** execute command **/ public function doCommand() { $ret = $this->_server->listDbs(); - $this->dbs = $ret["databases"]; - + $this->dbs = $ret["databases"]; + if (!$this->isPost()) { x("command", json_format("{listCommands:1}")); if (!x("db")) { x("db", "admin"); } } - + if ($this->isPost()) { $command = xn("command"); $format = x("format"); @@ -138,11 +138,11 @@ public function doCommand() { } $this->display(); } - + /** execute code **/ public function doExecute() { $ret = $this->_server->listDbs(); - $this->dbs = $ret["databases"]; + $this->dbs = $ret["databases"]; if (!$this->isPost()) { if (!x("db")) { x("db", "admin"); @@ -171,17 +171,17 @@ public function doExecute() { } $this->display(); } - + /** processlist **/ public function doProcesslist() { $this->progs = array(); - + try { - $query = $this->_mongo->selectDB("admin")->execute('function (){ + $query = $this->_mongo->selectDB("admin")->execute('function (){ return db.$cmd.sys.inprog.find({ $all:1 }).next(); }'); - - + + if ($query["ok"]) { $this->progs = $query["retval"]["inprog"]; } @@ -193,7 +193,7 @@ public function doProcesslist() { } } } catch (Exception $e) { - + } $this->display(); } @@ -210,7 +210,7 @@ public function doKillOp() { $this->ret = $this->_highlight($query, "json"); $this->display(); } - + /** create databse **/ public function doCreateDatabase() { if ($this->isPost()) { @@ -225,11 +225,11 @@ public function doCreateDatabase() { } $this->display(); } - + /** replication status **/ public function doReplication() { $this->status = array(); - + try { $ret = $this->_mongo->selectDB("local")->execute('function () { return db.getReplicationInfo(); }'); $status = isset($ret["retval"]) ? $ret["retval"] : array(); @@ -256,12 +256,12 @@ public function doReplication() { } } } catch (Exception $e) { - + } - + //slaves $this->slaves = array(); - + try { $query = $this->_mongo->selectDB("local")->selectCollection("slaves")->find(); foreach ($query as $one) { @@ -273,9 +273,9 @@ public function doReplication() { $this->slaves[] = $one; } } catch (Exception $e) { - + } - + //masters $this->masters = array(); try { @@ -291,18 +291,18 @@ public function doReplication() { $this->masters[] = $one; } } catch (Exception $e) { - + } - + //me try { $this->me = $this->_mongo->selectDB("local")->selectCollection("me")->findOne(); } catch (Exception $e) { $this->me = array(); } - + $this->display(); - } + } } ?> \ No newline at end of file diff --git a/app/funcs/functions.php b/app/funcs/functions.php index 61be26d..f694fc8 100644 --- a/app/funcs/functions.php +++ b/app/funcs/functions.php @@ -1,9 +1,9 @@ - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * Format JSON to pretty html * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * @param string $json JSON to format + * @return string */ - -// Pretty print some JSON -//modified by iwind function json_format_html($json) { $json = json_unicode_to_utf8($json); @@ -54,18 +39,6 @@ function json_format_html($json) $indent_level = 0; $in_string = false; -/* - commented out by monk.e.boy 22nd May '08 - because my web server is PHP4, and - json_* are PHP5 functions... - - $json_obj = json_decode($json); - - if($json_obj === false) - return false; - - $json = json_encode($json_obj); -*/ $len = strlen($json); for($c = 0; $c < $len; $c++) @@ -153,6 +126,32 @@ function json_format_html($json) } +/** + * PHP Integration of Open Flash Chart + * Copyright (C) 2008 John Glazebrook + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +/** + * Format JSON to pretty style + * + * @param string $json JSON to format + * @return string + */ function json_format($json) { $tab = " "; @@ -237,4 +236,30 @@ function json_format($json) return $new_json; } +/** + * Format bytes to human size + * + * @param integer $bytes Size in byte + * @param integer $precision Precision + * @return string size in k, m, g.. + */ +function r_human_bytes($bytes, $precision = 2) { + if ($bytes == 0) { + return 0; + } + if ($bytes < 1024) { + return $bytes . "B"; + } + if ($bytes < 1024 * 1024) { + return round($bytes/1024, $precision) . "k"; + } + if ($bytes < 1024 * 1024 * 1024) { + return round($bytes/1024/1024, $precision) . "m"; + } + if ($bytes < 1024 * 1024 * 1024 * 1024) { + return round($bytes/1024/1024/1024, $precision) . "g"; + } + return $bytes; +} + ?> \ No newline at end of file diff --git a/app/models/MCollection.php b/app/models/MCollection.php index f31b637..7218f59 100644 --- a/app/models/MCollection.php +++ b/app/models/MCollection.php @@ -1,7 +1,7 @@ selectCollection($collection)->findOne(); if (empty($one)) { return array(); @@ -10,7 +10,7 @@ static function fields (MongoDB $db, $collection) { self::_fieldsFromRow($fields, $one); return $fields; } - + private static function _fieldsFromRow(&$fields, $row, $prefix = null) { foreach ($row as $field => $value) { if (is_integer($field) || is_float($field)) { @@ -23,36 +23,36 @@ private static function _fieldsFromRow(&$fields, $row, $prefix = null) { } } } - + /** * If a row is GridFS row * * @param array $row record data * @return boolean */ - static function isFile(array $row) { + public static function isFile(array $row) { return isset($row["filename"]) && isset($row["chunkSize"]); } - + /** * get .chunks collection name from .files collection name * * @param string $filesCollection * @return string */ - static function chunksCollection($filesCollection) { + public static function chunksCollection($filesCollection) { return preg_replace("/\\.files$/", ".chunks", $filesCollection); } - + /** * read collection information * * @param MongoDB $db database * @param string $collection collection name */ - static function info(MongoDB $db, $collection) { + public static function info(MongoDB $db, $collection) { $ret = $db->command(array( "collStats" => $collection )); - + if (!$ret["ok"]) { exit("There is something wrong:{$ret['errmsg']}, please refresh the page to try again."); } @@ -74,6 +74,22 @@ static function info(MongoDB $db, $collection) { } return array( "capped" => $isCapped, "size" => $size, "max" => $max ); } + + /** + * Create collection + * + * @param MongoDB $db MongoDB + * @param string $name Collection name + * @param array $options Options, capped, size, max + */ + public static function createCollection(MongoDB $db, $name, array $options) { + if (RMongo::compareVersion("1.4.0") >= 0) { + $db->createCollection($name, $options); + } + else { + $db->createCollection($name, isset($options["capped"]) ? $options["capped"] : false, isset($options["size"]) ? $options["size"] : 0, isset($options["max"]) ? $options["max"] : 0); + } + } } ?> \ No newline at end of file diff --git a/themes/default/views/collection/collectionProps.php b/themes/default/views/collection/collectionProps.php index 629b073..1097f6f 100644 --- a/themes/default/views/collection/collectionProps.php +++ b/themes/default/views/collection/collectionProps.php @@ -12,16 +12,31 @@
-:
-
-:
-checked="checked"/>
-:
-
-:
-
-"/>
+ + + + + + + + + + + + + + + + + + + + + + + +
Capped Collection Options
checked="checked" />
bytes
documents
" />
-
\ No newline at end of file +
\ No newline at end of file diff --git a/themes/default/views/collection/collectionRename.php b/themes/default/views/collection/collectionRename.php index 87d9507..c2a7555 100644 --- a/themes/default/views/collection/collectionRename.php +++ b/themes/default/views/collection/collectionRename.php @@ -12,7 +12,7 @@ :

:
-"/>
+" autofocus="autofocus"/>

checked="checked" />
"/> diff --git a/themes/default/views/collection/collectionStats.php b/themes/default/views/collection/collectionStats.php index 0437b25..36db85a 100644 --- a/themes/default/views/collection/collectionStats.php +++ b/themes/default/views/collection/collectionStats.php @@ -7,13 +7,13 @@ $stat):?> - " . var_export($stat, true) . ""); + h("" . var_export($stat, true) . ""); } else { - if (in_array($name, array( "size", "storageSize", "lastExtentSize", "totalIndexSize" ))) { - $stat = round($stat/1024/1024, 2) . "m"; + if (in_array($name, array( "size", "storageSize", "lastExtentSize", "totalIndexSize", "avgObjSize" ))) { + $stat = "" . r_human_bytes($stat) . ""; } h($stat); } @@ -27,7 +27,7 @@ $stat):?> - diff --git a/themes/default/views/db/newCollection.php b/themes/default/views/db/newCollection.php index 514fdc4..b6b4ae3 100644 --- a/themes/default/views/db/newCollection.php +++ b/themes/default/views/db/newCollection.php @@ -10,13 +10,30 @@
-:
-
-:
-checked="checked" />
-:
-
-:
-
-" /> -
\ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + +
Capped Collection Options
checked="checked" />
bytes
documents
" />
+ + +

Here for more details »

\ No newline at end of file