You've already forked Epicnabbo-Catalogus-Updated-Daily
78 lines
2.3 KiB
PHP
78 lines
2.3 KiB
PHP
<?php
|
|
|
|
use App\Services\HousekeepingPermissionsService;
|
|
use App\Services\PermissionsService;
|
|
use App\Services\SettingsService;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Support\Str;
|
|
|
|
if (! function_exists('setting')) {
|
|
function setting(string $setting): string
|
|
{
|
|
return resolve(SettingsService::class)->getOrDefault($setting);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('hasPermission')) {
|
|
function hasPermission(string $permission): string
|
|
{
|
|
return resolve(PermissionsService::class)->getOrDefault($permission);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('hasHousekeepingPermission')) {
|
|
function hasHousekeepingPermission(string $permission): string
|
|
{
|
|
return resolve(HousekeepingPermissionsService::class)->getOrDefault($permission);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('strLimit')) {
|
|
function strLimit(string $string, int $limit, string $replacement = '...'): string
|
|
{
|
|
return Str::limit($string, $limit, $replacement);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('findMigration')) {
|
|
function findMigration(string $tableName): string
|
|
{
|
|
foreach (glob(database_path('migrations/*.php')) as $filename) {
|
|
$content = file_get_contents($filename);
|
|
if ($content !== false && str_contains($content, "Schema::create('$tableName'")) {
|
|
return basename($filename);
|
|
}
|
|
}
|
|
|
|
return '';
|
|
}
|
|
}
|
|
|
|
if (! function_exists('columnExists')) {
|
|
function columnExists(string $table, string $column): bool
|
|
{
|
|
return Schema::hasColumn($table, $column);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('dropForeignKeyIfExists')) {
|
|
function dropForeignKeyIfExists(string $table, string $column): void
|
|
{
|
|
$connection = Schema::getConnection();
|
|
$tableWithPrefix = $connection->getTablePrefix() . $table;
|
|
|
|
$foreignKeys = collect($connection->select('SELECT CONSTRAINT_NAME
|
|
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
|
WHERE TABLE_SCHEMA = DATABASE()
|
|
AND TABLE_NAME = ?
|
|
AND COLUMN_NAME = ?', [$tableWithPrefix, $column]))
|
|
->pluck('CONSTRAINT_NAME');
|
|
|
|
foreach ($foreignKeys as $foreignKey) {
|
|
if (! empty($foreignKey)) {
|
|
$connection->statement("ALTER TABLE {$table} DROP FOREIGN KEY {$foreignKey}");
|
|
}
|
|
}
|
|
}
|
|
}
|