#!/usr/bin/env python3 path = '/home/forge/app.charityright.org.uk/vendor/filament/tables/src/Table/Concerns/HasRecords.php' with open(path, 'r') as f: lines = f.readlines() new_lines = [] i = 0 while i < len(lines): line = lines[i] if 'public function getModel(): string' in line and 'getModelLabel' not in line: new_lines.append(' public function getModel(): string\n') new_lines.append(' {\n') new_lines.append(' return $this->getQuery()->getModel()::class;\n') new_lines.append(' }\n') # Skip the old method body i += 1 while i < len(lines) and lines[i].strip() != '}': i += 1 i += 1 # skip closing brace continue new_lines.append(line) i += 1 with open(path, 'w') as f: f.writelines(new_lines) print('Vendor reverted to original')