From 155cf6aeea9ba7ecbc39face6442d3ce1b03ad8e Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Wed, 4 Jun 2014 14:27:03 +0200 Subject: Add webinterface with functionallity --- management-interface/lib/db/mongo.php | 92 +++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 management-interface/lib/db/mongo.php (limited to 'management-interface/lib/db/mongo.php') diff --git a/management-interface/lib/db/mongo.php b/management-interface/lib/db/mongo.php new file mode 100644 index 0000000..833f160 --- /dev/null +++ b/management-interface/lib/db/mongo.php @@ -0,0 +1,92 @@ +dsn; + } + + /** + * Return UUID + * @return string + **/ + function uuid() { + return $this->uuid; + } + + /** + * Return MongoDB profiler results + * @return string + **/ + function log() { + $cursor=$this->selectcollection('system.profile')->find(); + foreach (iterator_to_array($cursor) as $frame) + if (!preg_match('/\.system\..+$/',$frame['ns'])) + $this->log.=date('r',$frame['ts']->sec).' ('. + sprintf('%.1f',$frame['millis']).'ms) '. + $frame['ns'].' ['.$frame['op'].'] '. + (empty($frame['query'])? + '':json_encode($frame['query'])). + (empty($frame['command'])? + '':json_encode($frame['command'])). + PHP_EOL; + return $this->log; + } + + /** + * Intercept native call to re-enable profiler + * @return int + **/ + function drop() { + $out=parent::drop(); + $this->setprofilinglevel(2); + return $out; + } + + /** + * Instantiate class + * @param $dsn string + * @param $dbname string + * @param $options array + **/ + function __construct($dsn,$dbname,array $options=NULL) { + $this->uuid=\Base::instance()->hash($this->dsn=$dsn); + $class=class_exists('\MongoClient')?'\MongoClient':'\Mongo'; + parent::__construct(new $class($dsn,$options?:array()),$dbname); + $this->setprofilinglevel(2); + } + +} -- cgit v1.2.3-55-g7522