- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 150
 
Future add data source #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            evgenybukharev
  wants to merge
  31
  commits into
  yiisoft:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
evgenybukharev:future_add_data_source
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 3 commits
      Commits
    
    
            Show all changes
          
          
            31 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      fe7b7fc
              
                Future add data source (#1)
              
              
                evgenybukharev c95f6cc
              
                add data storage
              
              
                evgenybukharev d7a8ed1
              
                add data storage
              
              
                evgenybukharev 593157b
              
                add data storage
              
              
                evgenybukharev e8a6dfb
              
                codestyle fix
              
              
                evgenybukharev f1480b0
              
                restore
              
              
                evgenybukharev d946f93
              
                Merge remote-tracking branch 'yiisoft/master'
              
              
                evgenybukharev 8c2d360
              
                fix
              
              
                evgenybukharev f464387
              
                fix
              
              
                evgenybukharev 4af6b3b
              
                fix
              
              
                evgenybukharev abbf63b
              
                fix
              
              
                evgenybukharev 8215da0
              
                Merge remote-tracking branch 'origin/master' into future_add_data_source
              
              
                evgenybukharev 5516465
              
                add yii\helpers\IpHelper
              
              
                evgenybukharev ae8afbf
              
                fix syntax error, unexpected 'class' (T_CLASS), expecting identifier …
              
              
                evgenybukharev 7ecfedc
              
                fix syntax error, unexpected 'class' (T_CLASS), expecting identifier …
              
              
                evgenybukharev f6c8f54
              
                fix syntax error, unexpected 'class' (T_CLASS), expecting identifier …
              
              
                evgenybukharev 36a7605
              
                add data storage info to CHANGELOG and README
              
              
                evgenybukharev 274a9d6
              
                recover merge bugs
              
              
                evgenybukharev a4c1775
              
                codestyle
              
              
                evgenybukharev 6ca168f
              
                recover merge bugs
              
              
                evgenybukharev d259c64
              
                add Instance::ensure
              
              
                evgenybukharev 6ea0f29
              
                refactor if/else
              
              
                evgenybukharev 9946fa2
              
                add Instance::ensure
              
              
                evgenybukharev 61b3ff0
              
                make CacheDataStorage properties
              
              
                evgenybukharev 309ddf7
              
                Update CHANGELOG.md
              
              
                samdark 0d8759b
              
                Merge remote-tracking branch 'yiisoft/master'
              
              
                evgenybukharev 72488bc
              
                Fix isset data exceptions
              
              
                evgenybukharev 98eb846
              
                Merge branch 'master' into future_add_data_source
              
              
                evgenybukharev 611eed6
              
                Merge branch 'master' into future_add_data_source
              
              
                samdark cdb69db
              
                Update CHANGELOG.md
              
              
                samdark e7d9eaf
              
                Update CHANGELOG.md
              
              
                samdark File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| <?php | ||
| /** | ||
| * @link http://www.yiiframework.com/ | ||
| * @link http://www.yiiframework.com/ | ||
| * @copyright Copyright (c) 2008 Yii Software LLC | ||
| * @license http://www.yiiframework.com/license/ | ||
| * @license http://www.yiiframework.com/license/ | ||
| */ | ||
| 
     | 
||
| namespace yii\debug; | ||
| 
        
          
        
         | 
    @@ -16,7 +16,7 @@ | |
| * The debug LogTarget is used to store logs for later use in the debugger tool | ||
| * | ||
| * @author Qiang Xue <[email protected]> | ||
| * @since 2.0 | ||
| * @since 2.0 | ||
| */ | ||
| class LogTarget extends Target | ||
| { | ||
| 
        
          
        
         | 
    @@ -32,7 +32,7 @@ class LogTarget extends Target | |
| 
     | 
||
| /** | ||
| * @param \yii\debug\Module $module | ||
| * @param array $config | ||
| * @param array $config | ||
| */ | ||
| public function __construct($module, $config = []) | ||
| { | ||
| 
        
          
        
         | 
    @@ -44,17 +44,16 @@ public function __construct($module, $config = []) | |
| /** | ||
| * Exports log messages to a specific destination. | ||
| * Child classes must implement this method. | ||
| * | ||
| * @throws \yii\base\Exception | ||
| */ | ||
| public function export() | ||
| { | ||
| $path = $this->module->dataPath; | ||
| FileHelper::createDirectory($path, $this->module->dirMode); | ||
| 
     | 
||
| $summary = $this->collectSummary(); | ||
| $dataFile = "$path/{$this->tag}.data"; | ||
| 
     | 
||
| $data = []; | ||
| $exceptions = []; | ||
| 
     | 
||
| foreach ($this->module->panels as $id => $panel) { | ||
| try { | ||
| $panelData = $panel->save(); | ||
| 
        
          
        
         | 
    @@ -70,47 +69,25 @@ public function export() | |
| $data['summary'] = $summary; | ||
| $data['exceptions'] = $exceptions; | ||
| 
     | 
||
| file_put_contents($dataFile, serialize($data)); | ||
| if ($this->module->fileMode !== null) { | ||
| @chmod($dataFile, $this->module->fileMode); | ||
| } | ||
| 
     | 
||
| $indexFile = "$path/index.data"; | ||
| $this->updateIndexFile($indexFile, $summary); | ||
| $this->module->getDataStorage()->setData($this->tag, $data); | ||
| } | ||
| 
     | 
||
| /** | ||
| * @see DefaultController | ||
| * @return array | ||
| * @see DefaultController | ||
| */ | ||
| public function loadManifest() | ||
| { | ||
| $indexFile = $this->module->dataPath . '/index.data'; | ||
| 
     | 
||
| $content = ''; | ||
| $fp = @fopen($indexFile, 'r'); | ||
| if ($fp !== false) { | ||
| @flock($fp, LOCK_SH); | ||
| $content = fread($fp, filesize($indexFile)); | ||
| @flock($fp, LOCK_UN); | ||
| fclose($fp); | ||
| } | ||
| 
     | 
||
| if ($content !== '') { | ||
| return array_reverse(unserialize($content), true); | ||
| } | ||
| 
     | 
||
| return []; | ||
| return $this->module->getDataStorage()->getDataManifest(); | ||
| } | ||
| 
     | 
||
| /** | ||
| * @see DefaultController | ||
| * @return array | ||
| * @see DefaultController | ||
| */ | ||
| public function loadTagToPanels($tag) | ||
| { | ||
| $dataFile = $this->module->dataPath . "/$tag.data"; | ||
| $data = unserialize(file_get_contents($dataFile)); | ||
| $data = $this->module->getDataStorage()->getData($tag); | ||
| $exceptions = $data['exceptions']; | ||
| foreach ($this->module->panels as $id => $panel) { | ||
| if (isset($data[$id])) { | ||
| 
        
          
        
         | 
    @@ -125,52 +102,16 @@ public function loadTagToPanels($tag) | |
| return $data; | ||
                
      
                  samdark marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| } | ||
| 
     | 
||
| /** | ||
| * Updates index file with summary log data | ||
| * | ||
| * @param string $indexFile path to index file | ||
| * @param array $summary summary log data | ||
| * @throws \yii\base\InvalidConfigException | ||
| */ | ||
| private function updateIndexFile($indexFile, $summary) | ||
| { | ||
| if (!@touch($indexFile) || ($fp = @fopen($indexFile, 'r+')) === false) { | ||
| throw new InvalidConfigException("Unable to open debug data index file: $indexFile"); | ||
| } | ||
| @flock($fp, LOCK_EX); | ||
| $manifest = ''; | ||
| while (($buffer = fgets($fp)) !== false) { | ||
| $manifest .= $buffer; | ||
| } | ||
| if (!feof($fp) || empty($manifest)) { | ||
| // error while reading index data, ignore and create new | ||
| $manifest = []; | ||
| } else { | ||
| $manifest = unserialize($manifest); | ||
| } | ||
| 
     | 
||
| $manifest[$this->tag] = $summary; | ||
| $this->gc($manifest); | ||
| 
     | 
||
| ftruncate($fp, 0); | ||
| rewind($fp); | ||
| fwrite($fp, serialize($manifest)); | ||
| 
     | 
||
| @flock($fp, LOCK_UN); | ||
| @fclose($fp); | ||
| 
     | 
||
| if ($this->module->fileMode !== null) { | ||
| @chmod($indexFile, $this->module->fileMode); | ||
| } | ||
| } | ||
| 
     | 
||
| /** | ||
| * Processes the given log messages. | ||
| * This method will filter the given messages with [[levels]] and [[categories]]. | ||
| * And if requested, it will also export the filtering result to specific medium (e.g. email). | ||
| * | ||
| * @param array $messages log messages to be processed. See [[\yii\log\Logger::messages]] for the structure | ||
| * of each message. | ||
| * @param bool $final whether this method is called at the end of the current application | ||
| * of each message. | ||
| * @param bool $final whether this method is called at the end of the current application | ||
| * | ||
| * @throws \yii\base\Exception | ||
| */ | ||
| public function collect($messages, $final) | ||
| 
        
          
        
         | 
    @@ -181,56 +122,9 @@ public function collect($messages, $final) | |
| } | ||
| } | ||
| 
     | 
||
| /** | ||
| * Removes obsolete data files | ||
| * @param array $manifest | ||
| */ | ||
| protected function gc(&$manifest) | ||
| { | ||
| if (count($manifest) > $this->module->historySize + 10) { | ||
| $n = count($manifest) - $this->module->historySize; | ||
| foreach (array_keys($manifest) as $tag) { | ||
| $file = $this->module->dataPath . "/$tag.data"; | ||
| @unlink($file); | ||
| if (isset($manifest[$tag]['mailFiles'])) { | ||
| foreach ($manifest[$tag]['mailFiles'] as $mailFile) { | ||
| @unlink(Yii::getAlias($this->module->panels['mail']->mailPath) . "/$mailFile"); | ||
| } | ||
| } | ||
| unset($manifest[$tag]); | ||
| if (--$n <= 0) { | ||
| break; | ||
| } | ||
| } | ||
| $this->removeStaleDataFiles($manifest); | ||
| } | ||
| } | ||
| 
     | 
||
| /** | ||
| * Remove staled data files i.e. files that are not in the current index file | ||
| * (may happen because of corrupted or rotated index file) | ||
| * | ||
| * @param array $manifest | ||
| * @since 2.0.11 | ||
| */ | ||
| protected function removeStaleDataFiles($manifest) | ||
| { | ||
| $storageTags = array_map( | ||
| function ($file) { | ||
| return pathinfo($file, PATHINFO_FILENAME); | ||
| }, | ||
| FileHelper::findFiles($this->module->dataPath, ['except' => ['index.data']]) | ||
| ); | ||
| 
     | 
||
| $staledTags = array_diff($storageTags, array_keys($manifest)); | ||
| 
     | 
||
| foreach ($staledTags as $tag) { | ||
| @unlink($this->module->dataPath . "/$tag.data"); | ||
| } | ||
| } | ||
| 
     | 
||
| /** | ||
| * Collects summary data of current request. | ||
| * | ||
| * @return array | ||
| */ | ||
| protected function collectSummary() | ||
| 
        
          
        
         | 
    @@ -244,7 +138,7 @@ protected function collectSummary() | |
| $summary = [ | ||
| 'tag' => $this->tag, | ||
| 'url' => $request->getAbsoluteUrl(), | ||
| 'ajax' => (int) $request->getIsAjax(), | ||
| 'ajax' => (int)$request->getIsAjax(), | ||
| 'method' => $request->getMethod(), | ||
| 'ip' => $request->getUserIP(), | ||
| 'time' => $_SERVER['REQUEST_TIME_FLOAT'], | ||
| 
        
          
        
         | 
    @@ -264,6 +158,7 @@ protected function collectSummary() | |
| /** | ||
| * Returns total sql count executed in current request. If database panel is not configured | ||
| * returns 0. | ||
| * | ||
| * @return int | ||
| */ | ||
| protected function getSqlTotalCount() | ||
| 
          
            
          
           | 
    ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.