Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/224370

Change subject: Add read and write debug functionality
......................................................................

Add read and write debug functionality

Change-Id: I867de5ce1176f8de90371c177f5e294d3b6bed4a
---
M MathObject.php
1 file changed, 72 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MathSearch 
refs/changes/70/224370/1

diff --git a/MathObject.php b/MathObject.php
index 57f161b..ec832d6 100644
--- a/MathObject.php
+++ b/MathObject.php
@@ -8,13 +8,16 @@
        protected $statusCode = 0;
        /** @var timestamp of the last modification of the database entry */
        protected $timestamp;
-       /** @var log messages generated during conversion of mathematical 
content */
+       /** @var string messages generated during conversion of mathematical 
content */
        protected $log = '';
+
+       protected $postData  = '';
        protected $anchorID = 0;
        protected $revisionID = 0;
        protected $index_timestamp = null;
        protected $dbLoadTime= 0;
        protected $mathTableName = null;
+       protected $renderingTime = 0;
 
        public static function hash2md5( $hash ){
                //TODO: make MathRenderer::dbHash2md5 public
@@ -422,4 +425,72 @@
        public function setMathTableName( $tableName ) {
                $this->mathTableName = $tableName;
        }
+
+
+       /**
+        * @return string
+        */
+       public function getPostData() {
+               return $this->postData;
+       }
+
+       /**
+        * @param string $postData
+        */
+       public function setPostData( $postData ) {
+               $this->postData = $postData;
+       }
+
+       /**
+        * @return int time in ms
+        */
+       public function getRenderingTime() {
+               return $this->renderingTime;
+       }
+
+       /**
+        * @param int|long $renderingTime either in ms or as in seconds as long
+        * @throws MWException
+        */
+       public function setRenderingTime( $renderingTime ) {
+               $type = gettype($renderingTime);
+               switch ( $type ) {
+                       case "double":
+                       case "float":
+                               $this->renderingTime = (int) ( $renderingTime * 
1000 );
+                               break;
+                       case "integer":
+                               $this->renderingTime = $renderingTime;
+                               break;
+                       default:
+                               throw new MWException(  __METHOD__ . ": does 
not support type $type" );
+               }
+       }
+
+       /**
+        * Gets an array that matches the variables of the class to the debug 
database columns
+        * @return array
+        */
+       protected function dbDebugOutArray() {
+               $out = array( 'math_inputhash' => $this->getInputHash(),
+                                         'math_log' => $this->getLog(),
+                                         'math_mode' => $this->getMode(),
+                                         'math_post' => $this->getPostData(),
+                                         'math_rederingtime' => 
$this->getRenderingTime()
+               );
+               return $out;
+       }
+
+       protected function writeDebugLog() {
+               global $wgMathDebug;
+               if ( $wgMathDebug ) {
+                       $dbw = wfGetDB( DB_MASTER );
+                       $outArray = $this->dbDebugOutArray();
+                       $method = __METHOD__;
+                       $dbw->onTransactionIdle( function () use ( $dbw, 
$outArray, $method     ) {
+                               $dbw->insert( 'mathlog', $outArray, $method );
+                       } );
+               }
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/224370
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I867de5ce1176f8de90371c177f5e294d3b6bed4a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MathSearch
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <w...@physikerwelt.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to