Ejemplo n.º 1
0
 /**
  * Finds the Logreport model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Logreport the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Logreport::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 2
0
 public function search($params)
 {
     $query = Logreport::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['logreport_id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(Proc::WhereConstruct($this, 'logreport_id'));
     $query->andFilterWhere(Proc::WhereConstruct($this, 'logreport_executetime', Proc::Time));
     $query->andFilterWhere(Proc::WhereConstruct($this, 'logreport_date', Proc::Date));
     $query->andFilterWhere(Proc::WhereConstruct($this, 'logreport_errors'));
     $query->andFilterWhere(Proc::WhereConstruct($this, 'logreport_updates'));
     $query->andFilterWhere(Proc::WhereConstruct($this, 'logreport_additions'));
     $query->andFilterWhere(Proc::WhereConstruct($this, 'logreport_amount'));
     $query->andFilterWhere(Proc::WhereConstruct($this, 'logreport_missed'));
     $query->andFilterWhere(Proc::WhereConstruct($this, 'logreport_memoryused'));
     return $dataProvider;
 }
Ejemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdlogreport()
 {
     return $this->hasOne(Logreport::className(), ['logreport_id' => 'id_logreport'])->from(['idlogreport' => Logreport::tableName()]);
 }
Ejemplo n.º 4
0
 /**
  * Выполняем удаление отчетов, если превышен лимит количества хранящихся отчетов.
  * @throws Exception
  */
 public function Execute()
 {
     foreach ($this->getNeedDeleteReports() as $Row) {
         $Transaction = Yii::$app->db->beginTransaction();
         try {
             Traflog::deleteAll(['id_logreport' => $Row['logreport_id']]);
             Matlog::deleteAll(['id_logreport' => $Row['logreport_id']]);
             Employeelog::deleteAll(['id_logreport' => $Row['logreport_id']]);
             Logreport::findOne($Row['logreport_id'])->delete();
             $FileRoot = 'importreports/Отчет импорта в систему Фрегат N' . $Row['logreport_id'] . '.xlsx';
             if (DIRECTORY_SEPARATOR !== '/') {
                 $FileRoot = mb_convert_encoding($FileRoot, 'Windows-1251', 'UTF-8');
             }
             unlink($FileRoot);
             $Transaction->commit();
         } catch (Exception $e) {
             $Transaction->rollBack();
             throw new Exception($e->getMessage() . ' logreport_id = ' . $Row['logreport_id']);
         }
     }
 }
Ejemplo n.º 5
0
 private static function DeleteOldReports()
 {
     $countreports = Importconfig::findOne(1);
     if (!empty($countreports)) {
         $files = glob('importreports/*.xlsx');
         if (count($files) > $countreports->logreport_reportcount) {
             $ToDelete = Logreport::find()->select(['logreport_id'])->orderBy(['logreport_id' => SORT_ASC])->limit(count($files) - $countreports->logreport_reportcount)->asArray()->all();
         }
         if (!empty($ToDelete)) {
             foreach ($ToDelete as $row) {
                 Traflog::deleteAll(['id_logreport' => $row['logreport_id']]);
                 Matlog::deleteAll(['id_logreport' => $row['logreport_id']]);
                 Employeelog::deleteAll(['id_logreport' => $row['logreport_id']]);
                 Logreport::findOne($row['logreport_id'])->delete();
                 $fileroot = 'importreports/Отчет импорта в систему Фрегат N' . $row['logreport_id'] . '.xlsx';
                 if (DIRECTORY_SEPARATOR !== '/') {
                     $fileroot = mb_convert_encoding($fileroot, 'Windows-1251', 'UTF-8');
                 }
                 unlink($fileroot);
             }
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * @return bool
  */
 protected function isChanged()
 {
     $Field = $this->getMaxFileLastDate();
     if (!$Field) {
         return false;
     }
     if (empty(Logreport::find()->count()) || $this->getDebug()) {
         return true;
     }
     $fileLastDateFromDB = Logreport::find()->max($Field);
     if (empty($fileLastDateFromDB)) {
         return false;
     }
     return strtotime($this->fileLastDate) > strtotime($fileLastDateFromDB);
 }