Created
February 9, 2022 18:08
-
-
Save dmaksimov/18dcab0e70c5968ee2a68b79abd60c98 to your computer and use it in GitHub Desktop.
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
<?php | |
declare(strict_types=1); | |
use App\Services\Views\HasViews; | |
use Symfony\Component\Finder\Finder; | |
/** | |
* Class AddViewsManager | |
*/ | |
class AddViewsManager extends \App\Upgrade | |
{ | |
use HasViews; | |
/** | |
* In production, the database is backed up before upgrades are run. Since | |
* the sent emails tables are huge, we speed up the backup process by | |
* excluding those tables from the backup by default. If this upgrade is | |
* making changes to the sent emails tables, you may choose to backup | |
* those tables. | |
* | |
* @var boolean | |
*/ | |
protected $backupSentEmails = false; | |
/** | |
* Run the upgrade | |
*/ | |
public function run() | |
{ | |
$this->migrateViewsIn(base_path('custom/views')); | |
} | |
/** | |
* Migrate all styles in a give directory. | |
* @param string $directory | |
*/ | |
private function migrateViewsIn(string $directory): void | |
{ | |
\App\Models\View::truncate(); | |
$bladeFiles = (new Finder)->in($directory)->files()->filter($this->onlyBladeFiles()); | |
foreach ($bladeFiles as $bladeFile) { | |
$name = $this->resolveViewName($bladeFile->getPathname(), $directory); | |
$bladeFileContent = file_get_contents($bladeFile->getPathname()); | |
if (!empty($bladeFileContent)) { | |
\App\Models\View::create([ | |
'name' => $name, | |
'content' => $bladeFileContent | |
]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment