-
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 #652 from portabilis/portabilis-patch-2019-09-06
[2.2] Portabilis patch 06/09/2019
- Loading branch information
Showing
134 changed files
with
2,329 additions
and
3,321 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
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,108 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Exceptions\Console\MissingSchoolCourseException; | ||
use App\Exceptions\Console\MissingSchoolGradeException; | ||
use App\Models\LegacyEnrollment; | ||
use App\Models\LegacyLevel; | ||
use App\Models\LegacySchoolClass; | ||
use App\Models\LegacySchoolCourse; | ||
use App\Models\LegacySchoolGrade; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class UpdateSchoolClassGrade extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'update:school-class-grade {schoolclass} {grade}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Atualiza a série da turma'; | ||
|
||
/** | ||
* @var LegacyLevel | ||
*/ | ||
private $grade; | ||
|
||
/** | ||
* @var LegacySchoolClass | ||
*/ | ||
private $schoolClass; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$this->grade = LegacyLevel::findOrFail($this->argument('grade')); | ||
$this->schoolClass = LegacySchoolClass::findOrFail($this->argument('schoolclass')); | ||
|
||
$this->validateSchoolGrade(); | ||
$this->validateSchoolCourse(); | ||
|
||
DB::beginTransaction(); | ||
|
||
$this->schoolClass->update([ | ||
'ref_ref_cod_serie' => $this->grade->getKey(), | ||
'ref_cod_curso' => $this->grade->course->id, | ||
]); | ||
|
||
$this->schoolClass->enrollments->map(function ($enrollment) { | ||
/** @var LegacyEnrollment $enrollment */ | ||
$enrollment->registration->update([ | ||
'ref_ref_cod_serie' => $this->grade->getKey(), | ||
'ref_cod_curso' => $this->grade->course->id, | ||
]); | ||
}); | ||
|
||
DB::commit(); | ||
} | ||
|
||
/** | ||
* Valida se existe registro em escola_serie | ||
* | ||
* @throws MissingSchoolGradeException | ||
*/ | ||
private function validateSchoolGrade() | ||
{ | ||
$existsSchoolGrade = LegacySchoolGrade::where('ref_cod_escola', $this->schoolClass->school_id) | ||
->where('ref_cod_serie', $this->grade->getKey()) | ||
->exists(); | ||
|
||
if ($existsSchoolGrade) { | ||
return; | ||
} | ||
|
||
throw new MissingSchoolGradeException($this->schoolClass->school, $this->grade); | ||
} | ||
|
||
/** | ||
* Valida se existe registro em escola_curso | ||
* | ||
* @throws MissingSchoolCourseException | ||
*/ | ||
private function validateSchoolCourse() | ||
{ | ||
$existsSchoolCourse = LegacySchoolCourse::where('ref_cod_escola', $this->schoolClass->school_id) | ||
->where('ref_cod_curso', $this->grade->course->id) | ||
->exists(); | ||
|
||
if ($existsSchoolCourse) { | ||
return; | ||
} | ||
|
||
throw new MissingSchoolCourseException($this->schoolClass->school, $this->grade->course); | ||
} | ||
|
||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace App\Exceptions\Console; | ||
|
||
use App\Models\LegacyCourse; | ||
use App\Models\LegacySchool; | ||
use DomainException; | ||
|
||
class MissingSchoolCourseException extends DomainException | ||
{ | ||
public function __construct(LegacySchool $school, LegacyCourse $course) | ||
{ | ||
$message = 'Não existe registro em escola curso para escola %s e curso %s'; | ||
|
||
$message = sprintf( | ||
$message, $school->getKey(), $course->getKey() | ||
); | ||
|
||
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,21 @@ | ||
<?php | ||
|
||
namespace App\Exceptions\Console; | ||
|
||
use App\Models\LegacyLevel; | ||
use App\Models\LegacySchool; | ||
use DomainException; | ||
|
||
class MissingSchoolGradeException extends DomainException | ||
{ | ||
public function __construct(LegacySchool $school, LegacyLevel $grade) | ||
{ | ||
$message = 'Não existe registro em escola série para escola %s e série %s'; | ||
|
||
$message = sprintf( | ||
$message, $school->getKey(), $grade->getKey() | ||
); | ||
|
||
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
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
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.