Example #1
0
function db_execute($query, $fetchStyle = PDO::FETCH_BOTH)
{
    DebugInfo::resetClock();
    $result = ORM::get_db()->query($query, $fetchStyle);
    DebugInfo::stopClock("Low-level query: {$query}");
    return $result;
}
Example #2
0
 static function getDebugInfo()
 {
     $data = DebugInfo::getDebugInfo();
     if (!$data['enabled']) {
         return '';
     }
     SmartyWrap::assign('debug_messages', $data['messages']);
     SmartyWrap::assign('debug_runningTimeMillis', $data['runningTimeMillis']);
     SmartyWrap::assign('debug_ormQueryLog', $data['ormQueryLog']);
     return SmartyWrap::fetch('bits/debugInfo.tpl');
 }
Example #3
0
function util_initEverything()
{
    // smarty < session_start/end : smarty caches the person's nickname.
    util_defineRootPath();
    util_defineWwwRoot();
    util_requireOtherFiles();
    util_defineConstants();
    db_init();
    session_init();
    mc_init();
    FlashMessage::restoreFromSession();
    SmartyWrap::init();
    DebugInfo::init();
}
Example #4
0
 /**
  * This validator method checks if srcid is a valid crash report ID or
  * debug info ID. 
  */
 public function checkSrcId()
 {
     if ($this->type == ProcessingError::TYPE_CRASH_REPORT_ERROR) {
         $crashReport = CrashReport::model()->find('id=' . $this->srcid);
         if ($crashReport === Null) {
             $this->addError('srcid', 'SrcID must be a valid crash report ID.');
             return false;
         }
     } else {
         if ($this->type == ProcessingError::TYPE_DEBUG_INFO_ERROR) {
             $debugInfo = DebugInfo::model()->find('id=' . $this->srcid);
             if ($debugInfo === Null) {
                 $this->addError('srcid', 'SrcID must be a valid debug info ID.');
                 return false;
             }
         }
     }
     return true;
 }
Example #5
0
 /**
  * Saves an entry into the log table
  * @access public
  * @return boolean
  **/
 public function logData()
 {
     //If we decide to put the logged data into a table, then call $this->insert()
     if (!$this->query) {
         return false;
     }
     try {
         $f = fopen(Config::get('global.logPath'), 'at');
     } catch (Exception $e) {
         try {
             $f = fopen(Config::get('global.logPath'), 'wt');
         } catch (Exception $e) {
             throw new Exception('Error trying to access the log file', -1, $e);
         }
     }
     $date = date('Y-m-d H:i:s');
     $millis = DebugInfo::getRunningTimeInMillis();
     $line = "[{$this->query}]\t[{$this->queryBeforeRedirect}]\t{$this->searchType}\t{$this->registeredUser}\t{$this->skin}\t" . "{$this->preferences}\t{$this->resultCount}\t{$this->resultList}\t{$this->redirect}\t{$date}\t{$millis}\n";
     fwrite($f, $line);
     fclose($f);
 }
Example #6
0
 public static function searchFullText($words, $hasDiacritics, $sourceId)
 {
     $field = $hasDiacritics ? 'formNoAccent' : 'formUtf8General';
     $intersection = null;
     $stopWords = array();
     $lmMap = array();
     foreach ($words as $word) {
         // Get all LexemModels generating this form
         $lms = Model::factory('LexemModel')->table_alias('L')->select('L.id')->distinct()->join('InflectedForm', 'I.lexemModelId = L.id', 'I')->where("I.{$field}", $word)->find_many();
         $lmIds = util_objectProperty($lms, 'id');
         $lmMap[] = $lmIds;
         // Get the FullTextIndex records for each LexemModels. Note that the FTI excludes stop words.
         $defIds = FullTextIndex::loadDefinitionIdsForLexemModels($lmIds, $sourceId);
         // Determine whether the word is a stop word.
         if (empty($defIds)) {
             $isStopWord = Model::factory('InflectedForm')->table_alias('I')->join('LexemModel', 'I.lexemModelId = LM.id', 'LM')->join('Lexem', 'LM.lexemId = L.id', 'L')->where("I.{$field}", $word)->where('L.stopWord', 1)->count();
         } else {
             $isStopWord = false;
         }
         if ($isStopWord) {
             $stopWords[] = $word;
         } else {
             $intersection = $intersection === null ? $defIds : util_intersectArrays($intersection, $defIds);
         }
     }
     if (empty($intersection)) {
         // This can happen when the query is all stopwords or the source selection produces no results
         return array(array(), $stopWords);
     }
     if (count($words) == 1) {
         // For single-word queries, skip the ordering part.
         // We could sort the definitions by lexicon, but it is very expensive.
         return array($intersection, $stopWords);
     }
     // Now compute a score for every definition
     DebugInfo::resetClock();
     $positionMap = FullTextIndex::loadPositionsByLexemIdsDefinitionIds($lmMap, $intersection);
     $shortestIntervals = array();
     foreach ($intersection as $defId) {
         $shortestIntervals[] = util_findSnippet($positionMap[$defId]);
     }
     if ($intersection) {
         array_multisort($shortestIntervals, $intersection);
     }
     DebugInfo::stopClock("Computed score for every definition");
     return array($intersection, $stopWords);
 }
Example #7
0
 /**
  * Imports debug info files for certain project version.
  * @param string $dirName  Directory name.
  * @param string $projectId Project ID.
  * @param string $projVer  Project version.
  * @return integer count of debug info files imported; or -1 on error.
  */
 private function importDebugInfo($dirName, $projectId, $projVerId)
 {
     //echo 'Importing debug info files from dir: '.$dirName.'\n';
     // Get file list in the directory
     $fileList = scandir($dirName);
     if ($fileList == false) {
         Yii::log('Directory name is invalid: ' . $dirName, 'error');
         return -1;
     }
     // Walk through files
     foreach ($fileList as $file) {
         // Get abs path
         $path = $dirName . '/' . $file;
         // Strip file parts
         $path_parts = pathinfo($path);
         if ($file != '.' && $file != '..' && is_file($path) && strtolower($path_parts['extension']) == 'pdb') {
             //echo 'Importing debug info file: '.$path.'\n';
             // Create new AR record
             $debugInfo = new DebugInfo();
             $debugInfo->project_id = $projectId;
             $debugInfo->guid = 'tmp_' . MiscHelpers::GUID();
             $debugInfo->fileAttachment = new CUploadedFile($file, $path, 'application/zip', filesize($path), '');
             // The following is to copy attachment file correctly.
             $debugInfo->fileAttachmentIsUploaded = false;
             // Save changes to database
             if (!$debugInfo->save()) {
                 Yii::log('Could not import debug info file:' . $path, 'error');
             } else {
                 $this->_importedDebugInfoCount++;
             }
         }
     }
     // Done
     return $this->_importedDebugInfoCount;
 }
Example #8
0
 /**
  * Returns count of debug info files in this project.
  * @param integer  $totalFileSize Total file size in bytes.
  * @param integer $percentOfDiskQuota Percent of disk quita.
  * @return integer file count.
  */
 public function getDebugInfoCount(&$totalFileSize, &$percentOfDiskQuota)
 {
     // Find all debug info files belonging to this project and having
     // $appver application version.
     $criteria = new CDbCriteria();
     $criteria->compare('project_id', $this->id, false, 'AND');
     $debugInfoFiles = DebugInfo::model()->findAll($criteria);
     // Calculate count of debug info
     $count = count($debugInfoFiles);
     // Calculate total file size
     $totalFileSize = 0;
     foreach ($debugInfoFiles as $debugInfo) {
         $totalFileSize += $debugInfo->filesize;
     }
     // Calc percent of disk quota
     if ($this->debug_info_files_disc_quota <= 0) {
         $percentOfDiskQuota = -1;
     } else {
         $percentOfDiskQuota = 100 * $totalFileSize / ($this->debug_info_files_disc_quota * 1024 * 1024);
     }
     // Return file count
     return $count;
 }
 public static function searchFullText($words, $hasDiacritics)
 {
     $intersection = null;
     $matchingLexems = array();
     foreach ($words as $word) {
         $lexems = Lexem::searchInflectedForms($word, $hasDiacritics);
         $lexemIds = array();
         foreach ($lexems as $lexem) {
             $lexemIds[] = $lexem->id;
         }
         $matchingLexems[] = $lexemIds;
     }
     foreach ($words as $i => $word) {
         // Load all the definitions for any possible lexem for this word.
         $lexemIds = $matchingLexems[$i];
         $defIds = FullTextIndex::loadDefinitionIdsForLexems($lexemIds);
         DebugInfo::resetClock();
         $intersection = $intersection === null ? $defIds : util_intersectArrays($intersection, $defIds);
         DebugInfo::stopClock("Intersected with lexems for {$word}");
     }
     if ($intersection === null) {
         // This can happen when the query is all stopwords
         $intersection = array();
     }
     $shortestInvervals = array();
     DebugInfo::resetClock();
     // Now compute a score for every definition
     foreach ($intersection as $defId) {
         // Compute the position matrix (for every word, load all the matching
         // positions)
         $p = array();
         foreach ($matchingLexems as $lexemIds) {
             $p[] = FullTextIndex::loadPositionsByLexemIdsDefinitionId($lexemIds, $defId);
         }
         $shortestIntervals[] = util_findSnippet($p);
     }
     if ($intersection) {
         array_multisort($shortestIntervals, $intersection);
     }
     DebugInfo::stopClock("Computed score for every definition");
     return $intersection;
 }
Example #10
0
 public static function disable()
 {
     self::$enabled = false;
 }
Example #11
0
 /**
  * Generates a debug info upload statistics for current project and
  * desired time period.
  * @param type $w Image width.
  * @param type $h Image height.
  * @param type $period Time period (7, 30 or 365).
  * @return void
  */
 public static function generateDebugInfoUploadStat($w, $h, $period, $file = null)
 {
     if (!is_numeric($w) || $w <= 0 || $w > 1024) {
         throw new CHttpException(403, 'Invalid parameter');
     }
     if (!is_numeric($h) || $h <= 0 || $h > 960) {
         throw new CHttpException(403, 'Invalid parameter');
     }
     if (!is_numeric($period) || $period <= 0 || $period > 365) {
         throw new CHttpException(403, 'Invalid parameter');
     }
     // Get current project info
     $curProjectId = Yii::app()->user->getCurProjectId();
     // Prepare data
     $data = array();
     $tomorrow = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"));
     $finishDate = $tomorrow - 1;
     $curDate = $finishDate;
     $dateFrom = $curDate;
     while ($finishDate - $curDate < $period * 24 * 60 * 60) {
         // Calc the beginning of time interval
         if ($period > 30) {
             $dateFrom = mktime(0, 0, 0, date("m", $curDate) - 1, date("d", $curDate), date("Y", $curDate));
         } else {
             if ($period > 7) {
                 $dateFrom = mktime(0, 0, 0, date("m", $curDate), date("d", $curDate) - 6, date("Y", $curDate));
             } else {
                 $dateFrom = mktime(0, 0, 0, date("m", $curDate), date("d", $curDate), date("Y", $curDate));
             }
         }
         // Get count of crash reports received within the period
         $criteria = new CDbCriteria();
         $criteria->compare('project_id', $curProjectId);
         $criteria->addBetweenCondition('dateuploaded', $dateFrom, $curDate);
         $count = DebugInfo::model()->count($criteria);
         // Add an item to data
         $item = array($period > 30 ? date('M y', $curDate) : date('j M', $curDate) => $count);
         $data = $item + $data;
         // Next time interval
         $curDate = $dateFrom - 1;
     }
     $graph = new ezcGraphLineChart();
     $graph->palette = new ezcGraphPaletteEzBlue();
     $graph->data['Versions'] = new ezcGraphArrayDataSet($data);
     $majorStep = round(max($data));
     if ($majorStep == 0) {
         $majorStep = 1;
     }
     $graph->yAxis->majorStep = $majorStep;
     $graph->yAxis->minorStep = $graph->yAxis->majorStep / 5;
     $graph->xAxis->labelCount = 30;
     $graph->options->fillLines = 210;
     $graph->legend = false;
     $graph->legend->position = ezcGraph::RIGHT;
     $graph->options->font->name = 'Tahoma';
     $graph->options->font->maxFontSize = 12;
     $graph->options->font->minFontSize = 1;
     if ($file === null) {
         $graph->renderToOutput($w, $h);
     } else {
         $graph->render($w, $h, $file);
     }
 }
            if (!array_key_exists($word, $ifMap)) {
                cacheWordForm($word);
            }
            if (array_key_exists($word, $ifMap)) {
                $lexemList = preg_split('/,/', $ifMap[$word]);
                for ($i = 0; $i < count($lexemList); $i += 2) {
                    fwrite($handle, $lexemList[$i] . "\t" . $lexemList[$i + 1] . "\t" . $dbRow[0] . "\t" . $position . "\n");
                    $indexSize++;
                }
            } else {
                // print "Not found: $word\n";
            }
        }
    }
    if (++$defsSeen % 10000 == 0) {
        $runTime = DebugInfo::getRunningTimeInMillis() / 1000;
        $speed = round($defsSeen / $runTime);
        log_scriptLog("{$defsSeen} of {$numDefs} definitions indexed ({$speed} defs/sec). " . "Word map has " . count($ifMap) . " entries. " . "Memory used: " . round(memory_get_usage() / 1048576, 1) . " MB.");
    }
}
fclose($handle);
log_scriptLog("{$defsSeen} of {$numDefs} definitions indexed.");
log_scriptLog("Index size: {$indexSize} entries.");
OS::executeAndAssert("chmod 666 {$fileName}");
log_scriptLog("Importing file {$fileName} into table FullTextIndex");
db_executeFromOS("load data local infile '{$fileName}' into table FullTextIndex");
util_deleteFile($fileName);
if (!Lock::release(LOCK_FULL_TEXT_INDEX)) {
    log_scriptLog('WARNING: could not release lock!');
}
log_scriptLog('rebuildFullTextIndex.php completed successfully ' . '(against all odds)');
Example #13
0
 public function testGenerateDebugInfoUploadStat7()
 {
     // Create temp file for output
     $outFile = tempnam(Yii::app()->getRuntimePath(), "test");
     // Generate an image for one year debug info statistics
     DebugInfo::generateDebugInfoUploadStat(320, 240, 7, $outFile);
     // Ensure the image exists
     $this->assertTrue(file_exists($outFile));
     // Ensure image size is not 0
     $this->assertTrue(filesize($outFile) > 0);
     // Delete image
     unlink($outFile);
 }
<?php

require_once "../phplib/util.php";
setlocale(LC_ALL, "ro_RO.utf8");
DebugInfo::disable();
$locVersion = util_getRequestParameter('locVersion');
$modelType = util_getRequestParameter('modelType');
$modelNumber = util_getRequestParameter('modelNumber');
$locVersions = pref_getLocVersions();
if ($locVersion && $modelType && $modelNumber) {
    smarty_assign('selectedLocVersion', $locVersion);
    smarty_assign('selectedModelType', $modelType);
    smarty_assign('selectedModelNumber', $modelNumber);
    LocVersion::changeDatabase($locVersion);
    if ($modelNumber == -1) {
        $modelsToDisplay = FlexModel::loadByType($modelType);
    } else {
        $modelsToDisplay = array(Model::factory('FlexModel')->where('modelType', $modelType)->where('number', $modelNumber)->find_one());
    }
    $lexems = array();
    $paradigms = array();
    foreach ($modelsToDisplay as $m) {
        // Load by canonical model, so if $modelType is V, look for a lexem with type V or VT.
        $l = Model::factory('Lexem')->select('Lexem.*')->join('ModelType', 'modelType = code')->where('canonical', $modelType)->where('modelNumber', $m->number)->where('form', $m->exponent)->limit(1)->find_one();
        if ($l) {
            $paradigm = getExistingForms($l->id, $locVersion);
        } else {
            $l = Lexem::create($m->exponent, $modelType, $m->number, '');
            $l->isLoc = true;
            $paradigm = getNewForms($l, $locVersion);
        }
Example #15
0
function smarty_function_getDebugInfo($params, &$smarty)
{
    return DebugInfo::getDebugInfo();
}
Example #16
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = DebugInfo::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #17
0
 private function deletePendingDebugInfoFiles()
 {
     // Add a message to log
     Yii::log("Checking for debug info records marked for deletion...", "info");
     // Get debug info files that have status 'Pending Delete'
     $criteria = new CDbCriteria();
     $criteria->select = '*';
     $criteria->condition = 'status=' . DebugInfo::STATUS_PENDING_DELETE;
     $criteria->limit = 20;
     $debugInfoFiles = DebugInfo::model()->findAll($criteria);
     if ($debugInfoFiles == Null) {
         Yii::log('There are no debug info files waiting for deletion', 'info');
     } else {
         Yii::log('Found ' . count($debugInfoFiles) . ' debug info file(s) ready for deletion', 'info');
     }
     foreach ($debugInfoFiles as $debugInfo) {
         // Determine path to debug info file
         $fileName = $debugInfo->getLocalFilePath();
         // Format daemon command
         $command = 'assync dumper --delete-debug-info "' . $fileName . '"';
         // Execute the command
         $responce = "";
         $retCode = Yii::app()->daemon->execCommand($command, $responce);
         if ($retCode != 0) {
             Yii::log('Error executing command ' . $command . ', response = ' . $responce, 'error');
             continue;
         }
         // Check responce and get command ID from server responce
         $matches = array();
         $check = preg_match('#Assync command \\{([0-9]{1,6}.[0-9]{1,9})\\} has been added to the request queue.#', $responce, $matches);
         if (!$check || !isset($matches[1])) {
             Yii::log('Unexpected response from command ' . $command . ', responce = ' . $responce, 'error');
             continue;
         }
         // Begin DB transaction
         $transaction = Yii::app()->db->beginTransaction();
         try {
             // Create a new operation record in {{operation}} table.
             $op = new Operation();
             $op->status = Operation::STATUS_STARTED;
             $op->timestamp = time();
             $op->srcid = $debugInfo->id;
             $op->cmdid = $matches[1];
             $op->optype = Operation::OPTYPE_DELETE_DEBUG_INFO;
             $op->operand1 = $fileName;
             if (!$op->save()) {
                 throw new Exception('Could not save an operation record');
             }
             // Update existing debug info record in {{debuginfo}} table.
             $debugInfo->status = DebugInfo::STATUS_DELETE_IN_PROGRESS;
             if (!$debugInfo->save()) {
                 //$errors = $crashReport->getErrors();
                 //print_r($errors);
                 throw new Exception('Could not save a debug info record ');
             }
             // Commit transaction
             $transaction->commit();
         } catch (Exception $e) {
             // Roll back transaction
             $transaction->rollBack();
             // Add an error message to log
             Yii::log('An exception caught: ' . $e->getMessage(), "error");
         }
     }
     Yii::log("Finished checking for debug info files ready for deletion.", "info");
 }