-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #693 from portabilis/portabilis-patch-2019-01-03
[2.2] Portabilis patch 03/01/2019
- Loading branch information
Showing
119 changed files
with
10,591 additions
and
2,770 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Exceptions\Educacenso; | ||
|
||
use RuntimeException; | ||
|
||
class NotImplementedYear extends RuntimeException | ||
{ | ||
public function __construct($year) | ||
{ | ||
$message = sprintf('A importação do ano %s não foi implementada', $year); | ||
|
||
parent::__construct($message); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Educacenso; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\EducacensoImport; | ||
use App\Process; | ||
use App\Services\Educacenso\HandleFileService; | ||
use App\Services\Educacenso\ImportService; | ||
use App\Services\Educacenso\ImportServiceFactory; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\View\View; | ||
|
||
class ImportController extends Controller | ||
{ | ||
public function import(Request $request) | ||
{ | ||
$file = $request->file('arquivo'); | ||
|
||
$yearImportService = ImportServiceFactory::createImportService($request->get('ano')); | ||
|
||
$importFileService = new HandleFileService($yearImportService, Auth::user()); | ||
$importFileService->handleFile($file); | ||
|
||
return redirect()->route('educacenso.history'); | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* @return View | ||
*/ | ||
public function index(Request $request) | ||
{ | ||
$this->breadcrumb('Historico de importações', [ | ||
url('intranet/educar_index.php') => 'Escola', | ||
]); | ||
|
||
$this->menu(Process::EDUCACENSO_IMPORT_HISTORY); | ||
|
||
$imports = EducacensoImport::orderBy('created_at', 'desc')->get(); | ||
|
||
return view('educacenso.import.index', compact('imports')); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\EducacensoImport as EducacensoImportModel; | ||
use App\Services\Educacenso\ImportServiceFactory; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Support\Facades\DB; | ||
use Throwable; | ||
|
||
class EducacensoImportJob implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
/** | ||
* @var EducacensoImportModel | ||
*/ | ||
private $educacensoImport; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $importArray; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $databaseConnection; | ||
|
||
public $timeout = 600; | ||
|
||
/** | ||
* Create a new job instance. | ||
* | ||
* @param EducacensoImportModel $educacensoImport | ||
* @param $importArray | ||
* @param string $databaseConnection | ||
*/ | ||
public function __construct(EducacensoImportModel $educacensoImport, $importArray, $databaseConnection) | ||
{ | ||
$this->educacensoImport = $educacensoImport; | ||
$this->importArray = $importArray; | ||
$this->databaseConnection = $databaseConnection; | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
* | ||
* @return void | ||
* @throws Throwable | ||
*/ | ||
public function handle() | ||
{ | ||
DB::setDefaultConnection($this->databaseConnection); | ||
DB::beginTransaction(); | ||
|
||
try { | ||
$importService = ImportServiceFactory::createImportService($this->educacensoImport->year); | ||
$importService->import($this->importArray, $this->educacensoImport->user); | ||
} catch (Throwable $e) { | ||
DB::rollBack(); | ||
throw $e; | ||
} | ||
|
||
$educacensoImport = $this->educacensoImport; | ||
$educacensoImport->finished = true; | ||
$educacensoImport->save(); | ||
|
||
DB::commit(); | ||
} | ||
} |
This file contains 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.