From 0550fc07051ba7a5e3142b2965fe4402aa532d04 Mon Sep 17 00:00:00 2001 From: MythUp <105284202+MythUp@users.noreply.github.com> Date: Sat, 28 Mar 2026 09:13:26 +0100 Subject: [PATCH 1/9] Add manifest.json --- manifest.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 manifest.json diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..8687249 --- /dev/null +++ b/manifest.json @@ -0,0 +1,11 @@ +{ + "project_name": "BookFind", + "version": "3.4.1", + "type": "php", + "launcher": { + "compatible": true, + "connection_types": ["ftp", "sql"], + "requires_sql": true, + "notes": "Infos utiles pour le déploiement" + } +} \ No newline at end of file From 3a9ff7d6dfc559fccfb67523bd53eacc9564d927 Mon Sep 17 00:00:00 2001 From: MythUp <105284202+MythUp@users.noreply.github.com> Date: Sat, 28 Mar 2026 16:44:10 +0100 Subject: [PATCH 2/9] Update manifest.json --- manifest.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 8687249..bd93ec3 100644 --- a/manifest.json +++ b/manifest.json @@ -4,8 +4,13 @@ "type": "php", "launcher": { "compatible": true, - "connection_types": ["ftp", "sql"], + "connection_types": ["ftp"], "requires_sql": true, - "notes": "Infos utiles pour le déploiement" + "notes": "Infos utiles pour le déploiement", + "requires_sql": true, + "sql_schema_path": "actions/bookfind.sql", + "ignore": [ + "actions/bookfind.sql" + ], } } \ No newline at end of file From bab3f82e4722d73d49fed60e8244358c94b24e0e Mon Sep 17 00:00:00 2001 From: MythUp <105284202+MythUp@users.noreply.github.com> Date: Sat, 28 Mar 2026 16:45:10 +0100 Subject: [PATCH 3/9] Update manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index bd93ec3..6dfd3f0 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "type": "php", "launcher": { "compatible": true, - "connection_types": ["ftp"], + "connection_types": ["ftp", "sql"], "requires_sql": true, "notes": "Infos utiles pour le déploiement", "requires_sql": true, From bdf8bcc251315fdf67d99cafc072c54033675d17 Mon Sep 17 00:00:00 2001 From: MythUp <105284202+MythUp@users.noreply.github.com> Date: Sat, 28 Mar 2026 16:53:35 +0100 Subject: [PATCH 4/9] Update manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 6dfd3f0..df6813a 100644 --- a/manifest.json +++ b/manifest.json @@ -11,6 +11,6 @@ "sql_schema_path": "actions/bookfind.sql", "ignore": [ "actions/bookfind.sql" - ], + ] } } \ No newline at end of file From d913c522c64777c0214f12cd2316847ce110f871 Mon Sep 17 00:00:00 2001 From: Alban Muller <105284202+MythUp@users.noreply.github.com> Date: Sun, 29 Mar 2026 16:11:26 +0200 Subject: [PATCH 5/9] Update manifest.json --- manifest.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index df6813a..8755a5c 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,6 @@ "launcher": { "compatible": true, "connection_types": ["ftp", "sql"], - "requires_sql": true, "notes": "Infos utiles pour le déploiement", "requires_sql": true, "sql_schema_path": "actions/bookfind.sql", @@ -13,4 +12,4 @@ "actions/bookfind.sql" ] } -} \ No newline at end of file +} From 0d6cb0c5e2c55232747f0bb2c8cc0a6c1de6c5ea Mon Sep 17 00:00:00 2001 From: MythUp <105284202+MythUp@users.noreply.github.com> Date: Sun, 29 Mar 2026 16:11:26 +0200 Subject: [PATCH 6/9] Update manifest.json --- manifest.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index df6813a..8755a5c 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,6 @@ "launcher": { "compatible": true, "connection_types": ["ftp", "sql"], - "requires_sql": true, "notes": "Infos utiles pour le déploiement", "requires_sql": true, "sql_schema_path": "actions/bookfind.sql", @@ -13,4 +12,4 @@ "actions/bookfind.sql" ] } -} \ No newline at end of file +} From 17b78da1b825d634e7ae92ba20ff3f49e4f2c8f9 Mon Sep 17 00:00:00 2001 From: MythUp <105284202+MythUp@users.noreply.github.com> Date: Mon, 30 Mar 2026 18:25:22 +0200 Subject: [PATCH 7/9] Improve database import --- actions/bookfind.sql | 2 - configuration.php | 123 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 107 insertions(+), 18 deletions(-) diff --git a/actions/bookfind.sql b/actions/bookfind.sql index 9aef06e..2c897a0 100644 --- a/actions/bookfind.sql +++ b/actions/bookfind.sql @@ -20,8 +20,6 @@ SET time_zone = "+00:00"; -- -- Database: `bookfind` -- -CREATE DATABASE IF NOT EXISTS `bookfind` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; -USE `bookfind`; -- -------------------------------------------------------- diff --git a/configuration.php b/configuration.php index 2135324..b843e2d 100644 --- a/configuration.php +++ b/configuration.php @@ -72,9 +72,23 @@
- +
+ +
+
+ + +
+
+ + +
@@ -90,10 +104,30 @@ $dbname = $_POST['dbname']; $filePath = 'actions/database.php'; $fileContent = file_get_contents($filePath); - $fileContent = preg_replace("/\\\$dbname = '';/", "\$dbname = '$dbname';", $fileContent); + $fileContent = preg_replace_callback('/\\$dbname\s*=\s*\'[^\']*\';/', function($m) use ($dbname) { + return '$dbname = ' . var_export($dbname, true) . ';'; + }, $fileContent); file_put_contents($filePath, $fileContent); - unlink('actions/bookfind.sql'); - echo '
Enregistré avec succès ! Recharger la page.
'; + include 'actions/database.php'; + $sqlFilePath = 'actions/bookfind.sql'; + if (file_exists($sqlFilePath)) { + $sql = file_get_contents($sqlFilePath); + $sql = preg_replace('/CREATE DATABASE\s+IF NOT EXISTS.*?;|CREATE DATABASE.*?;|USE `.*?`;/is', '', $sql); + $queries = array_filter(array_map('trim', explode(';', $sql))); + foreach ($queries as $query) { + if (!empty($query)) { + try { + $bdd->exec($query); + } catch (Exception $e) { + echo '
Erreur d\'exécution SQL : ' . htmlspecialchars($e->getMessage()) . '
'; + } + } + } + unlink($sqlFilePath); + echo '
Tables importées. Recharger la page.
'; + } else { + echo '
Fichier SQL introuvable.
'; + } } else { echo '
Identifiants MySQL manquants. Remplissez d\'abord le formulaire plus haut.
'; } @@ -101,27 +135,84 @@ if (isset($_POST['import'])) { if (!empty($host) && !empty($username)) { + // Si l'utilisateur demande d'importer uniquement les tables + if (!empty($_POST['onlyTables'])) { + $dbnameInput = !empty($_POST['dbname_import']) ? trim($_POST['dbname_import']) : 'bookfind'; + $filePath = 'actions/database.php'; + $fileContent = file_get_contents($filePath); + $fileContent = preg_replace_callback('/\\$dbname\s*=\s*\'[^\']*\';/', function($m) use ($dbnameInput) { + return '$dbname = ' . var_export($dbnameInput, true) . ';'; + }, $fileContent); + file_put_contents($filePath, $fileContent); + // Reconnecter sur la base fournie + include 'actions/database.php'; + $sqlFilePath = 'actions/bookfind.sql'; + if (file_exists($sqlFilePath)) { + $sql = file_get_contents($sqlFilePath); + $cleanSql = preg_replace('/CREATE DATABASE\\s+IF NOT EXISTS.*?;|CREATE DATABASE.*?;|USE `.*?`;/is', '', $sql); + $queries = array_filter(array_map('trim', explode(';', $cleanSql))); + foreach ($queries as $query) { + if (!empty($query)) { + try { + $bdd->exec($query); + } catch (Exception $e) { + echo '
Erreur d\'exécution SQL : ' . htmlspecialchars($e->getMessage()) . '
'; + } + } + } + unlink($sqlFilePath); + echo '
Tables importées. Recharger la page.
'; + } else { + echo '
Fichier SQL introuvable.
'; + } + // Fin du flux d'import uniquement des tables + goto end_import; + } + $filePath = 'actions/database.php'; $fileContent = file_get_contents($filePath); - $fileContent = preg_replace("/\\\$dbname = '';/", "\$dbname = 'bookfind';", $fileContent); + $fileContent = preg_replace_callback('/\\$dbname\s*=\s*\'[^\']*\';/', function($m) { + return '$dbname = ' . var_export('bookfind', true) . ';'; + }, $fileContent); file_put_contents($filePath, $fileContent); $sqlFilePath = 'actions/bookfind.sql'; - $sql = file_get_contents($sqlFilePath); - $bdd->exec('CREATE DATABASE bookfind'); - $queries = array_filter(array_map('trim', explode(';', $sql))); - foreach ($queries as $query) { - if (!empty($query)) { - if ($bdd->query($query) === false) { - echo '
Erreur d\'exécution SQL.
'; + if (file_exists($sqlFilePath)) { + $sql = file_get_contents($sqlFilePath); + // Créer la base sans se connecter à une base inexistante + try { + $tmpDsn = 'mysql:host=' . $host . ';charset=utf8'; + $tmpPdo = new PDO($tmpDsn, $username, $password); + $tmpPdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $tmpPdo->exec('CREATE DATABASE IF NOT EXISTS `bookfind` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'); + } catch (Exception $e) { + echo '
Impossible de créer la base : ' . htmlspecialchars($e->getMessage()) . '
'; + // On arrête ici + goto end_import; + } + // Recharger la config pour se connecter sur la nouvelle base + include 'actions/database.php'; + // Retirer les éventuelles lignes CREATE DATABASE / USE du dump avant exécution + $cleanSql = preg_replace('/CREATE DATABASE\\s+IF NOT EXISTS.*?;|CREATE DATABASE.*?;|USE `.*?`;/is', '', $sql); + $queries = array_filter(array_map('trim', explode(';', $cleanSql))); + foreach ($queries as $query) { + if (!empty($query)) { + try { + $bdd->exec($query); + } catch (Exception $e) { + echo '
Erreur d\'exécution SQL : ' . htmlspecialchars($e->getMessage()) . '
'; + } } } + unlink($sqlFilePath); + echo '
Base de données importée. Recharger la page.
'; + } else { + echo '
Fichier SQL introuvable.
'; } - unlink('actions/bookfind.sql'); - echo '
Base de données importée. Recharger la page.
'; } else { echo '
Identifiants MySQL manquants. Remplissez d\'abord le formulaire plus haut.
'; } } + end_import: ?>
From 12bcded5e0548ca54e9160d613a8dcbf1dd15122 Mon Sep 17 00:00:00 2001 From: MythUp <105284202+MythUp@users.noreply.github.com> Date: Mon, 30 Mar 2026 18:25:22 +0200 Subject: [PATCH 8/9] Improve database import --- actions/bookfind.sql | 2 - configuration.php | 123 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 107 insertions(+), 18 deletions(-) diff --git a/actions/bookfind.sql b/actions/bookfind.sql index 9aef06e..2c897a0 100644 --- a/actions/bookfind.sql +++ b/actions/bookfind.sql @@ -20,8 +20,6 @@ SET time_zone = "+00:00"; -- -- Database: `bookfind` -- -CREATE DATABASE IF NOT EXISTS `bookfind` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; -USE `bookfind`; -- -------------------------------------------------------- diff --git a/configuration.php b/configuration.php index 2135324..b843e2d 100644 --- a/configuration.php +++ b/configuration.php @@ -72,9 +72,23 @@
- +
+ +
+
+ + +
+
+ + +
@@ -90,10 +104,30 @@ $dbname = $_POST['dbname']; $filePath = 'actions/database.php'; $fileContent = file_get_contents($filePath); - $fileContent = preg_replace("/\\\$dbname = '';/", "\$dbname = '$dbname';", $fileContent); + $fileContent = preg_replace_callback('/\\$dbname\s*=\s*\'[^\']*\';/', function($m) use ($dbname) { + return '$dbname = ' . var_export($dbname, true) . ';'; + }, $fileContent); file_put_contents($filePath, $fileContent); - unlink('actions/bookfind.sql'); - echo '
Enregistré avec succès ! Recharger la page.
'; + include 'actions/database.php'; + $sqlFilePath = 'actions/bookfind.sql'; + if (file_exists($sqlFilePath)) { + $sql = file_get_contents($sqlFilePath); + $sql = preg_replace('/CREATE DATABASE\s+IF NOT EXISTS.*?;|CREATE DATABASE.*?;|USE `.*?`;/is', '', $sql); + $queries = array_filter(array_map('trim', explode(';', $sql))); + foreach ($queries as $query) { + if (!empty($query)) { + try { + $bdd->exec($query); + } catch (Exception $e) { + echo '
Erreur d\'exécution SQL : ' . htmlspecialchars($e->getMessage()) . '
'; + } + } + } + unlink($sqlFilePath); + echo '
Tables importées. Recharger la page.
'; + } else { + echo '
Fichier SQL introuvable.
'; + } } else { echo '
Identifiants MySQL manquants. Remplissez d\'abord le formulaire plus haut.
'; } @@ -101,27 +135,84 @@ if (isset($_POST['import'])) { if (!empty($host) && !empty($username)) { + // Si l'utilisateur demande d'importer uniquement les tables + if (!empty($_POST['onlyTables'])) { + $dbnameInput = !empty($_POST['dbname_import']) ? trim($_POST['dbname_import']) : 'bookfind'; + $filePath = 'actions/database.php'; + $fileContent = file_get_contents($filePath); + $fileContent = preg_replace_callback('/\\$dbname\s*=\s*\'[^\']*\';/', function($m) use ($dbnameInput) { + return '$dbname = ' . var_export($dbnameInput, true) . ';'; + }, $fileContent); + file_put_contents($filePath, $fileContent); + // Reconnecter sur la base fournie + include 'actions/database.php'; + $sqlFilePath = 'actions/bookfind.sql'; + if (file_exists($sqlFilePath)) { + $sql = file_get_contents($sqlFilePath); + $cleanSql = preg_replace('/CREATE DATABASE\\s+IF NOT EXISTS.*?;|CREATE DATABASE.*?;|USE `.*?`;/is', '', $sql); + $queries = array_filter(array_map('trim', explode(';', $cleanSql))); + foreach ($queries as $query) { + if (!empty($query)) { + try { + $bdd->exec($query); + } catch (Exception $e) { + echo '
Erreur d\'exécution SQL : ' . htmlspecialchars($e->getMessage()) . '
'; + } + } + } + unlink($sqlFilePath); + echo '
Tables importées. Recharger la page.
'; + } else { + echo '
Fichier SQL introuvable.
'; + } + // Fin du flux d'import uniquement des tables + goto end_import; + } + $filePath = 'actions/database.php'; $fileContent = file_get_contents($filePath); - $fileContent = preg_replace("/\\\$dbname = '';/", "\$dbname = 'bookfind';", $fileContent); + $fileContent = preg_replace_callback('/\\$dbname\s*=\s*\'[^\']*\';/', function($m) { + return '$dbname = ' . var_export('bookfind', true) . ';'; + }, $fileContent); file_put_contents($filePath, $fileContent); $sqlFilePath = 'actions/bookfind.sql'; - $sql = file_get_contents($sqlFilePath); - $bdd->exec('CREATE DATABASE bookfind'); - $queries = array_filter(array_map('trim', explode(';', $sql))); - foreach ($queries as $query) { - if (!empty($query)) { - if ($bdd->query($query) === false) { - echo '
Erreur d\'exécution SQL.
'; + if (file_exists($sqlFilePath)) { + $sql = file_get_contents($sqlFilePath); + // Créer la base sans se connecter à une base inexistante + try { + $tmpDsn = 'mysql:host=' . $host . ';charset=utf8'; + $tmpPdo = new PDO($tmpDsn, $username, $password); + $tmpPdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $tmpPdo->exec('CREATE DATABASE IF NOT EXISTS `bookfind` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'); + } catch (Exception $e) { + echo '
Impossible de créer la base : ' . htmlspecialchars($e->getMessage()) . '
'; + // On arrête ici + goto end_import; + } + // Recharger la config pour se connecter sur la nouvelle base + include 'actions/database.php'; + // Retirer les éventuelles lignes CREATE DATABASE / USE du dump avant exécution + $cleanSql = preg_replace('/CREATE DATABASE\\s+IF NOT EXISTS.*?;|CREATE DATABASE.*?;|USE `.*?`;/is', '', $sql); + $queries = array_filter(array_map('trim', explode(';', $cleanSql))); + foreach ($queries as $query) { + if (!empty($query)) { + try { + $bdd->exec($query); + } catch (Exception $e) { + echo '
Erreur d\'exécution SQL : ' . htmlspecialchars($e->getMessage()) . '
'; + } } } + unlink($sqlFilePath); + echo '
Base de données importée. Recharger la page.
'; + } else { + echo '
Fichier SQL introuvable.
'; } - unlink('actions/bookfind.sql'); - echo '
Base de données importée. Recharger la page.
'; } else { echo '
Identifiants MySQL manquants. Remplissez d\'abord le formulaire plus haut.
'; } } + end_import: ?>
From 1af24825ce01563939ee9203dce69cca1b86e82d Mon Sep 17 00:00:00 2001 From: Alban Muller <105284202+MythUp@users.noreply.github.com> Date: Mon, 18 May 2026 18:56:19 +0200 Subject: [PATCH 9/9] Update manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 8755a5c..7e63d00 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "launcher": { "compatible": true, "connection_types": ["ftp", "sql"], - "notes": "Infos utiles pour le déploiement", + "notes": "Il faut mettre les informations de connexions pour la base de données dans database.php", "requires_sql": true, "sql_schema_path": "actions/bookfind.sql", "ignore": [