Files
HRM-System/public/sync.php
2026-04-24 15:15:22 +08:00

59 lines
2.1 KiB
PHP

<?php
// Standalone Sync Script for Production
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
echo "Starting Sync...<br>";
// 1. Manually delete the bootstrap cache files
$cachePath = __DIR__ . '/../bootstrap/cache/';
if (is_dir($cachePath)) {
$files = ['routes-v7.php', 'config.php', 'services.php', 'packages.php', 'events.php'];
foreach ($files as $file) {
if (file_exists($cachePath . $file)) {
@unlink($cachePath . $file);
echo "Deleted cache: $file <br>";
}
}
}
// 2. Fix Storage Link
$link = __DIR__ . '/storage';
$target = __DIR__ . '/../storage/app/public';
if (!file_exists($link)) {
@symlink($target, $link);
echo "Storage link processed.<br>";
}
// 3. Bootstrap Laravel to reset password and run Artisan
try {
if (!file_exists(__DIR__ . '/../vendor/autoload.php')) {
die("Error: vendor/autoload.php not found. Did you run composer install?");
}
require __DIR__ . '/../vendor/autoload.php';
$app = require_once __DIR__ . '/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
// Reset company@example.com password
$user = \App\Models\User::where('email', 'company@example.com')->first();
if ($user) {
$user->password = \Illuminate\Support\Facades\Hash::make('password');
$user->save();
echo "<strong>SUCCESS:</strong> Password for company@example.com reset to 'password'. <br>";
}
// Clear optimize
\Artisan::call('optimize:clear');
echo "Global optimize:clear finished.<br>";
echo "<br>---<br>Done! You should now be able to login with <strong>password</strong>.";
echo "<br><br><strong>⚠️ DELETE THIS FILE (public/sync.php) FROM YOUR SERVER NOW!</strong>";
} catch (\Exception $e) {
echo "<br><strong>BOOTSTRAP ERROR:</strong> " . $e->getMessage() . "<br>";
echo "File: " . $e->getFile() . " on line " . $e->getLine();
echo "<br><br>This usually happens if your Controller files have syntax errors or if the database connection failed.";
}