예제 #1
0
 /**
  * @inheritdoc
  */
 public static function parseInstructions()
 {
     $instructions = parent::parseInstructions();
     $instructions['type'] = function ($instructions) {
         if (count($instructions) >= 2) {
             $placementType = array_shift($instructions);
             $placementItem = Yii::$app->collectors['types']->getOne($placementType);
             if (isset($placementItem)) {
                 $placementItem = $placementItem->object;
             }
             while (!empty($placementItem) && is_object($placementItem) && !empty($instructions)) {
                 $nextInstruction = array_shift($instructions);
                 if (isset($placementItem->{$nextInstruction})) {
                     $placementItem = $placementItem->{$nextInstruction};
                 } else {
                     $placementItem = null;
                 }
             }
             if (is_null($placementItem)) {
                 return;
             }
             return (string) $placementItem;
         }
     };
     return $instructions;
 }
예제 #2
0
 /**
  * Get data package.
  *
  * @return [[@doctodo return_type:getDataPackage]] [[@doctodo return_description:getDataPackage]]
  */
 public function getDataPackage()
 {
     $p = [];
     $p['_'] = [];
     $p['_']['url'] = Url::to(['admin/interface/view-log', 'id' => $this->id, 'package' => 1]);
     $p['_']['id'] = $this->id;
     $p['_']['started'] = isset($this->started) ? date("F d, Y g:i:sa", strtotime($this->started)) : false;
     $p['_']['ended'] = isset($this->ended) ? date("F d, Y g:i:sa", strtotime($this->ended)) : false;
     $p['_']['duration'] = $this->duration;
     $p['_']['status'] = $this->status;
     if ($this->status === 'running' && $this->statusLog->paused) {
         $p['_']['status'] = 'paused';
     }
     $p['_']['estimatedTimeRemaining'] = Date::niceDuration($this->estimateTimeRemaining);
     $p['_']['log_status'] = 'fine';
     $p['_']['menu'] = [];
     $isMostRecent = $this->isMostRecent;
     if ($isMostRecent) {
         if ($this->status === 'success' && !$this->statusLog->cleaned) {
         } elseif ($this->status !== 'running') {
             $p['_']['menu'][] = ['label' => 'Run Again', 'url' => Url::to(['admin/interface/run', 'id' => $this->data_interface_id]), 'attributes' => ['data-handler' => 'background'], 'class' => 'btn-warning'];
         }
     }
     if ($this->statusLog->hasError) {
         $p['_']['log_status'] = 'error';
     } elseif ($this->statusLog->hasWarning) {
         $p['_']['log_status'] = 'warning';
     }
     $p['_']['last_update'] = $this->last_update;
     $p['_']['peak_memory'] = StringHelper::humanFilesize($this->statusLog->peakMemoryUsage);
     $p['progress'] = ['total' => $this->statusLog->progressTotal, 'done' => $this->statusLog->progressDone];
     if (isset($this->statusLog->ended)) {
         $p['progress']['duration'] = Date::shortDuration($this->statusLog->ended - $this->statusLog->started);
     }
     $p['tasks'] = [];
     foreach ($this->statusLog->tasks as $id => $task) {
         $p['tasks'][$id] = $task->package;
     }
     $p['messages'] = [];
     $lasttime = $started = $this->statusLog->started;
     foreach ($this->statusLog->messages as $key => $message) {
         $key = $key . '-' . substr(md5($key), 0, 5);
         $timestamp = (double) $message['time'];
         $duration = $timestamp - $lasttime;
         $lasttime = $timestamp;
         $fromStart = $timestamp - $started;
         $p['messages'][$key] = ['message' => $message['message'], 'duration' => Date::shortDuration($duration), 'fromStart' => Date::shortDuration($fromStart), 'level' => $message['level'], 'data' => $message['data'], 'memory' => StringHelper::humanFilesize($message['memory'])];
     }
     $p['output'] = $this->statusLog->commandOutput;
     return $p;
 }
예제 #3
0
 /**
  * @inheritdoc
  */
 public function getMenuItems($model, $key, $index)
 {
     $base = parent::getMenuItems($model, $key, $index);
     $base['map'] = ['icon' => 'fa fa-globe', 'label' => 'View map', 'url' => StringHelper::parseText(Yii::$app->params['helperUrls']['map'], ['object' => $model]), 'linkOptions' => ['target' => '_blank']];
     return $base;
 }