diff --git a/orif/stock/Controllers/Migrate.php b/orif/stock/Controllers/Migrate.php new file mode 100644 index 00000000..4b7b62bf --- /dev/null +++ b/orif/stock/Controllers/Migrate.php @@ -0,0 +1,85 @@ +validation = \Config\Services::validation(); + $this->migrate = \Config\Services::migrations(); + + // Load required helpers + helper('form'); + + //get db instance + $this->db = \CodeIgniter\Database\Config::connect(); + } + + public function index() + { + // Display migration form + $this->display_view('\Stock\Views\migration\migration_form'); + } + + public function toLatest() + { + if (!empty($_POST)) + { + // Check the given password before doing the migration + $validationRules = [ + 'password' => 'required|min_length[10]' + ]; + + if ($this->validate($validationRules)) + { + if ($_POST['password'] == 'uzdSb8U8ZUD5h24') + { + try + { + // Migrate to latest + $this->migrate->setNamespace('Stock')->latest(); + + // Delete migration files + unlink(ROOTPATH.'orif/stock/Views/migration/migration_form.php'); + rmdir(ROOTPATH.'orif/stock/Views/migration'); + unlink(ROOTPATH.'orif/stock/Controllers/Migrate.php'); + + // Go back to homepage + return redirect()->to(base_url()); + } + catch(Exception $e) + { + // Display migration form with error message + session()->setFlashdata('migration-error', lang('migrate_lang.err_msg_migration_failed') . $e->getMessage()); + return $this->display_view('\Stock\Views\migration\migration_form'); + } + } + } + } + + // Display migration form + return $this->display_view('\Stock\Views\migration\migration_form'); + } +} \ No newline at end of file diff --git a/orif/stock/Language/fr/migrate_lang.php b/orif/stock/Language/fr/migrate_lang.php index 0fb36d0e..d585a9f1 100644 --- a/orif/stock/Language/fr/migrate_lang.php +++ b/orif/stock/Language/fr/migrate_lang.php @@ -9,16 +9,16 @@ return[ // Page titles -'title_migration' => 'Migration', +'title_migration' => 'Migration de la BD', // Buttons -'btn_migrate' => 'Migrer vers CI4', +'btn_migrate' => 'Migrer la BD', // Error messages 'err_msg_migration_failed' => 'L\'erreur suivante s\'est produite lors de la migration:

', // Other texts -'warning' => 'La migration va modifier la base de données, afin de la rendre compatible avec ci_session, le soft delete et le module user :

' - .'Ceci pouvant être dangereux pour l\'intégrité des données, elle est bloquée derrière un mot de passe.', +'warning' => 'La migration va modifier la base de données, afin de l\'adapter à la nouvelle version de l\'application.

' + .'Ceci pouvant être dangereux pour l\'intégrité des données, il est vivement recommandé de faire une sauvegarde complète de la base de données avant de lancer cette opération.', ]; \ No newline at end of file diff --git a/orif/stock/Views/migration/migration_form.php b/orif/stock/Views/migration/migration_form.php new file mode 100644 index 00000000..18a64ab7 --- /dev/null +++ b/orif/stock/Views/migration/migration_form.php @@ -0,0 +1,43 @@ + + +
+ + +
+
+

+
+
+ + + getFlashdata('migration-error'))) : ?> + + + + +
+ +
+ +
+ 'form-label']); ?> + 'form-control', 'id' => 'password' + ]); ?> + showError('password'); ?> +
+ + +
+
+ + 'btn btn-danger']); ?> +
+
+ +
\ No newline at end of file