| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- /**
- * Script pour exécuter POST_userV2.php en mode test
- * en modifiant temporairement le fichier pour utiliser nos données
- */
- echo "🚀 Exécution de POST_userV2.php en mode test...\n\n";
- // Charger nos données
- $json_file = __DIR__ . '/post_user_request.json';
- $post_data = json_decode(file_get_contents($json_file), true);
- // Générer un nouveau login unique
- $timestamp = time();
- $post_data['login'] = "test.user.{$timestamp}@sipa-automobiles.fr";
- $post_data['mail'] = $post_data['login'];
- $post_data['employeeNumber'] = "TEST{$timestamp}";
- $post_data['dtContractStart'] = date('Y-m-d\TH:i:s', strtotime('+1 day'));
- $post_data['seniorityDate'] = $post_data['dtContractStart'];
- echo "📋 Données de la requête:\n";
- echo json_encode($post_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
- // Lire le script POST_userV2.php
- $script_path = __DIR__ . '/../api/user/user/POST_userV2.php';
- $script_content = file_get_contents($script_path);
- // Sauvegarder l'original
- $backup_path = $script_path . '.backup';
- if (!file_exists($backup_path)) {
- file_put_contents($backup_path, $script_content);
- echo "💾 Backup créé: {$backup_path}\n\n";
- }
- // Activer USE_TEST_DATA
- $script_content = str_replace(
- "define('USE_TEST_DATA', false);",
- "define('USE_TEST_DATA', true);",
- $script_content
- );
- // Remplacer les données de test
- $test_data_pattern = '/if \(USE_TEST_DATA\) \{[^}]*\$input = \[.*?\];/s';
- $replacement = "if (USE_TEST_DATA) {\n \$input = " . var_export($post_data, true) . ";";
- if (preg_match($test_data_pattern, $script_content)) {
- $script_content = preg_replace($test_data_pattern, $replacement, $script_content);
- } else {
- // Méthode alternative : trouver et remplacer manuellement
- $start_pos = strpos($script_content, 'if (USE_TEST_DATA) {');
- if ($start_pos !== false) {
- $end_pos = strpos($script_content, '}', $start_pos + 50);
- if ($end_pos !== false) {
- $old_block = substr($script_content, $start_pos, $end_pos - $start_pos + 1);
- $new_block = "if (USE_TEST_DATA) {\n \$input = " . var_export($post_data, true) . ";\n}";
- $script_content = str_replace($old_block, $new_block, $script_content);
- }
- }
- }
- // Sauvegarder temporairement
- file_put_contents($script_path, $script_content);
- echo "📡 Exécution du script...\n\n";
- // Capturer la sortie
- ob_start();
- include $script_path;
- $output = ob_get_clean();
- echo $output;
- // Restaurer l'original
- file_put_contents($script_path, file_get_contents($backup_path));
- echo "\n✅ Script restauré à son état original\n";
|