123 lines
3.9 KiB
Markdown
123 lines
3.9 KiB
Markdown
# مُصادَق — ملخص كود المشروع الكامل
|
|
|
|
هذا الملف يحتوي على كافة ملفات المصدر للمشروع مجمعة لتسهيل المراجعة.
|
|
|
|
## الملف: `migrate.php`
|
|
|
|
```php
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
require_once __DIR__ . '/../app/Core/helpers.php';
|
|
|
|
use App\Core\{Application, Database};
|
|
|
|
// Initialize app to load .env and configs
|
|
$app = new Application(dirname(__DIR__));
|
|
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
|
|
echo "🗄️ Musadaq Migration Tool\n";
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
|
|
|
|
try {
|
|
$db = Database::getInstance();
|
|
|
|
// Create migrations table if not exists
|
|
$db->exec("CREATE TABLE IF NOT EXISTS migrations (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
migration VARCHAR(255) NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
|
|
|
|
$stmt = $db->query("SELECT migration FROM migrations");
|
|
$executed = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
$migrationsDir = dirname(__DIR__) . '/database/migrations';
|
|
$files = glob($migrationsDir . '/*.sql');
|
|
sort($files); // Ensure order
|
|
|
|
$count = 0;
|
|
foreach ($files as $file) {
|
|
$name = basename($file);
|
|
if (!in_array($name, $executed)) {
|
|
echo "🚀 Running: $name... ";
|
|
|
|
$sql = file_get_contents($file);
|
|
|
|
// Execute the SQL. Since it might contain multiple statements,
|
|
// and PDO::exec doesn't always handle them well in one go
|
|
// depending on the driver, we'll try to run it.
|
|
$db->exec($sql);
|
|
|
|
$stmt = $db->prepare("INSERT INTO migrations (migration) VALUES (?)");
|
|
$stmt->execute([$name]);
|
|
|
|
echo "✅ Done\n";
|
|
$count++;
|
|
}
|
|
}
|
|
|
|
if ($count === 0) {
|
|
echo "✨ Nothing to migrate. Database is up to date.\n";
|
|
} else {
|
|
echo "🎉 Migrations completed successfully ($count ran).\n";
|
|
}
|
|
} catch (Exception $e) {
|
|
echo "❌ Error: " . $e->getMessage() . "\n";
|
|
exit(1);
|
|
}
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
|
|
|
|
```
|
|
|
|
---
|
|
|
|
## الملف: `seed.php`
|
|
|
|
```php
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use App\Core\{Application, Database};
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
$app = new Application(dirname(__DIR__));
|
|
$db = Database::getInstance();
|
|
|
|
echo "🌱 Seeding initial data...\n";
|
|
|
|
try {
|
|
// 1. Create Tenant
|
|
$tenantId = Uuid::uuid4()->toString();
|
|
$db->prepare("INSERT INTO tenants (id, name, email, status) VALUES (?, ?, ?, 'active')")
|
|
->execute([$tenantId, 'شركة انطلاق للحلول الرقمية', 'admin@intaleqapp.com']);
|
|
|
|
// 2. Create Super Admin User
|
|
$userId = Uuid::uuid4()->toString();
|
|
$passwordHash = password_hash('Musadaq@2026', PASSWORD_ARGON2ID);
|
|
|
|
$db->prepare("INSERT INTO users (id, tenant_id, name, email, password_hash, role, is_active) VALUES (?, ?, ?, ?, ?, 'super_admin', 1)")
|
|
->execute([$userId, $tenantId, 'Hamza Admin', 'admin@musadaq.app', $passwordHash]);
|
|
|
|
// 3. Create initial subscription
|
|
$db->prepare("INSERT INTO subscriptions (tenant_id, plan, max_companies, max_invoices_per_month, max_users) VALUES (?, 'pro', 10, 500, 5)")
|
|
->execute([$tenantId]);
|
|
|
|
echo "✅ Success! You can now log in with:\n";
|
|
echo "📧 Email: admin@musadaq.app\n";
|
|
echo "🔑 Password: Musadaq@2026\n";
|
|
|
|
} catch (\Throwable $e) {
|
|
echo "❌ Error: " . $e->getMessage() . "\n";
|
|
}
|
|
|
|
```
|
|
|
|
---
|
|
|