Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Fix deprecated warning in collection creating
Browse files Browse the repository at this point in the history
  • Loading branch information
iwind committed Jun 6, 2014
1 parent cfa2a24 commit bb92543
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 153 deletions.
22 changes: 0 additions & 22 deletions app/classes/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...
*
Expand Down
31 changes: 16 additions & 15 deletions app/controllers/collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -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. <a href=\"?action=collection.index&db={$this->db}&collection={$newname}\">[GO &raquo;]</a>";
}
else {
$this->error = "Operation failure";
Expand All @@ -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:<font color=\"red\">{$ret['errmsg']}</font>, 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");
Expand All @@ -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)) {
Expand Down
17 changes: 11 additions & 6 deletions app/controllers/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
}


Expand Down Expand Up @@ -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. <a href=\"?action=collection.index&db={$this->db}&collection={$this->name}\">[GO &raquo;]</a>";

//add index
if (!$this->isCapped) {
Expand Down
86 changes: 43 additions & 43 deletions app/controllers/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -19,7 +19,7 @@ public function doIndex() {
} catch (Exception $e) {
$this->commandLine = "";
}

//web server
$this->webServers = array();
if (isset($_SERVER["SERVER_SOFTWARE"])) {
Expand All @@ -28,9 +28,9 @@ public function doIndex() {
}
$this->webServers["<a href=\"http://www.php.net\" target=\"_blank\">PHP version</a>"] = "PHP " . PHP_VERSION;
$this->webServers["<a href=\"http://www.php.net/mongo\" target=\"_blank\">PHP extension</a>"] = "<a href=\"http://pecl.php.net/package/mongo\" target=\"_blank\">mongo</a>/" . RMongo::getVersion();

$this->directives = ini_get_all("mongo");

//build info
$this->buildInfos = array();
try {
Expand All @@ -40,24 +40,24 @@ public function doIndex() {
$this->buildInfos = $ret;
}
} catch (Exception $e) {

}

//connection
$this->connections = array(
"Host" => $this->_server->mongoHost(),
"Port" => $this->_server->mongoPort(),
"Username" => "******",
"Password" => "******"
);

$this->display();
}

/** Server Status **/
public function doStatus() {
$this->status = array();

try {
//status
$db = $this->_mongo->selectDB("admin");
Expand All @@ -76,12 +76,12 @@ public function doStatus() {
}
}
} catch (Exception $e) {

}

$this->display();
}
}

/** show databases **/
public function doDatabases() {
$ret = $this->_server->listDbs();
Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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"];
}
Expand All @@ -193,7 +193,7 @@ public function doProcesslist() {
}
}
} catch (Exception $e) {

}
$this->display();
}
Expand All @@ -210,7 +210,7 @@ public function doKillOp() {
$this->ret = $this->_highlight($query, "json");
$this->display();
}

/** create databse **/
public function doCreateDatabase() {
if ($this->isPost()) {
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -273,9 +273,9 @@ public function doReplication() {
$this->slaves[] = $one;
}
} catch (Exception $e) {

}

//masters
$this->masters = array();
try {
Expand All @@ -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();
}
}
}

?>
Loading

0 comments on commit bb92543

Please sign in to comment.