diff --git a/src/Command/Migrations/ImportPartKeeprCommand.php b/src/Command/Migrations/ImportPartKeeprCommand.php index 22ac1ef3..b81286f9 100644 --- a/src/Command/Migrations/ImportPartKeeprCommand.php +++ b/src/Command/Migrations/ImportPartKeeprCommand.php @@ -86,6 +86,12 @@ class ImportPartKeeprCommand extends Command $xml = file_get_contents($input_path); $data = $this->xml_converter->convertMySQLDumpXMLDataToArrayStructure($xml); + if (!$this->importHelper->checkVersion($data)) { + $db_version = $this->importHelper->getDatabaseSchemaVersion($data); + $io->error('The version of the imported database is not supported! (Version: '.$db_version.')'); + return 1; + } + //Import the mandatory data $this->doImport($io, $data); diff --git a/src/Services/ImportExportSystem/PartKeeprImporter/PKImportHelper.php b/src/Services/ImportExportSystem/PartKeeprImporter/PKImportHelper.php index 632bcd39..3a1ae3c4 100644 --- a/src/Services/ImportExportSystem/PartKeeprImporter/PKImportHelper.php +++ b/src/Services/ImportExportSystem/PartKeeprImporter/PKImportHelper.php @@ -47,4 +47,28 @@ class PKImportHelper $purger = new ResetAutoIncrementORMPurger($this->em, ['users', '"users"', 'groups', '"groups"', 'u2f_keys', 'internal', 'migration_versions']); $purger->purge(); } + + /** + * Extracts the current database schema version from the PartKeepr XML dump. + * @param array $data + * @return string + */ + public function getDatabaseSchemaVersion(array $data): string + { + if (!isset($data['schemaversions'])) { + throw new \RuntimeException('Could not find schema version in XML dump!'); + } + + return end($data['schemaversions'])['version']; + } + + /** + * Checks that the database schema of the PartKeepr XML dump is compatible with the importer + * @param array $data + * @return bool True if the schema is compatible, false otherwise + */ + public function checkVersion(array $data): bool + { + return $this->getDatabaseSchemaVersion($data) === '20170601175559'; + } } \ No newline at end of file