예제 #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.');
     }
 }
예제 #2
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']);
         }
     }
 }
예제 #3
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);
             }
         }
     }
 }