fix_migration_automations_column

This commit is contained in:
2026-11-18 18:38:32 +03:30
parent 3ce2c48438
commit ce9d62ffaa
@@ -11,7 +11,7 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
if (Schema::hasTable('settings')) { if (Schema::hasTable('settings') && Schema::hasColumn('settings', 'value')) {
$rows = DB::table('settings') $rows = DB::table('settings')
->where(function ($q) { ->where(function ($q) {
$q->where('key', 'like', '%sms%') $q->where('key', 'like', '%sms%')
@@ -38,9 +38,17 @@ return new class extends Migration
} }
if (Schema::hasTable('automations')) { if (Schema::hasTable('automations')) {
$autos = DB::table('automations')->where('message', 'like', '%گرم%')->get(); $column = null;
if (Schema::hasColumn('automations', 'body')) {
$column = 'body';
} elseif (Schema::hasColumn('automations', 'message')) {
$column = 'message';
}
if ($column !== null) {
$autos = DB::table('automations')->where($column, 'like', '%گرم%')->get();
foreach ($autos as $auto) { foreach ($autos as $auto) {
$msg = (string) ($auto->message ?? ''); $msg = (string) ($auto->{$column} ?? '');
$updated = preg_replace( $updated = preg_replace(
'/(?<![\p{L}\p{N}]|کیلو|کیلو\x{200c})گرم(?=[ی\s\n\r:،.,!؟\(\)\[\]\/\-–—]|$)/u', '/(?<![\p{L}\p{N}]|کیلو|کیلو\x{200c})گرم(?=[ی\s\n\r:،.,!؟\(\)\[\]\/\-–—]|$)/u',
'کیلو$0', 'کیلو$0',
@@ -48,12 +56,31 @@ return new class extends Migration
); );
if ($updated !== null && $updated !== $msg) { if ($updated !== null && $updated !== $msg) {
DB::table('automations')->where('id', $auto->id)->update([ DB::table('automations')->where('id', $auto->id)->update([
'message' => $updated, $column => $updated,
'updated_at' => now(), 'updated_at' => now(),
]); ]);
} }
} }
} }
if (Schema::hasColumn('automations', 'title')) {
$autos = DB::table('automations')->where('title', 'like', '%گرم%')->get();
foreach ($autos as $auto) {
$title = (string) ($auto->title ?? '');
$updated = preg_replace(
'/(?<![\p{L}\p{N}]|کیلو|کیلو\x{200c})گرم(?=[ی\s\n\r:،.,!؟\(\)\[\]\/\-–—]|$)/u',
'کیلو$0',
$title
);
if ($updated !== null && $updated !== $title) {
DB::table('automations')->where('id', $auto->id)->update([
'title' => $updated,
'updated_at' => now(),
]);
}
}
}
}
} }
public function down(): void public function down(): void