/** * 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; }
/** * [[@doctodo method_description:isDueToday]]. * * @return [[@doctodo return_type:isDueToday]] [[@doctodo return_description:isDueToday]] */ public function isDueToday() { if (empty($this->end)) { return false; } return DateHelper::isToday(DateHelper::endOfDay($this->end)); }
/** * @inheritdoc */ public function getDefaultValues() { return ['start' => Date::date("m/d/Y"), 'parent:Account::contractor' => Yii::$app->params['primaryAccount']]; }
protected function triggerStateChange(CheckEvent $event) { $payload = []; $duration = false; $previousSensorEvent = SensorEvent::find()->where(['sensor_id' => $this->model->primaryKey])->orderBy(['created' => SORT_DESC])->one(); if ($previousSensorEvent) { $durationSeconds = time() - strtotime($previousSensorEvent->created . ' UTC'); $duration = DateHelper::niceDuration($durationSeconds, 2); } $sensorEvent = new SensorEvent(); $sensorEvent->sensor_id = $this->model->primaryKey; $sensorEvent->old_state = $this->model->state; if (empty($sensorEvent->old_state)) { $sensorEvent->old_state = BaseSensor::STATE_UNCHECKED; } $payload['oldState'] = $sensorEvent->old_state; $sensorEvent->new_state = $payload['newState'] = $event->state; $sensorEvent->data = serialize($event); $sensorEvent->save(); $this->model->state = $event->state; $payload['duration'] = $duration; $payload['sensor'] = []; $payload['sensor']['id'] = $this->model->primaryKey; $payload['sensor']['system_id'] = $this->model->system_id; $payload['sensor']['name'] = $this->object->name; $payload['object']['id'] = null; $payload['object']['name'] = null; $objectId = $this->model->primaryKey; if (!empty($this->objectModel)) { $payload['object']['id'] = $this->objectModel->primaryKey; $payload['object']['name'] = $this->objectModel->descriptor; } $priority = EventType::PRIORITY_MEDIUM; if ($this->object->isCritical && $payload['oldState'] !== BaseSensor::STATE_UNCHECKED) { $priority = EventType::PRIORITY_CRITICAL; } $this->triggerBroadcastEvent('sensor_state_changed', $payload, $objectId, $priority); return true; }