commit 940c4c848c1cdf3f3fe6bc6a6995d4233dc3753f
parent c1a7d5338bc2cf9aa77b2f0a2580bfbf0d35a11a
Author: Felicitus <felicitus@felicitus.org>
Date: Fri, 27 Nov 2015 19:09:07 +0100
Parse old config file to retrieve the files path, migrate legacy images to the new images directory. Fixes #502
Diffstat:
8 files changed, 161 insertions(+), 44 deletions(-)
diff --git a/src/PartKeepr/SetupBundle/Controller/ExistingConfigParserController.php b/src/PartKeepr/SetupBundle/Controller/ExistingConfigParserController.php
@@ -1,8 +1,6 @@
<?php
namespace PartKeepr\SetupBundle\Controller;
-use PartKeepr\SetupBundle\Visitor\ConfigVisitor;
-use PartKeepr\SetupBundle\Visitor\LegacyConfigVisitor;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
@@ -11,6 +9,7 @@ class ExistingConfigParserController extends SetupController
{
/**
* @Route("/setup/parseExistingConfig")
+ * @param Request $request
*/
public function parseExistingConfigAction(Request $request)
{
@@ -112,44 +111,12 @@ class ExistingConfigParserController extends SetupController
if (array_key_exists("partkeepr.frontend.allow_password_change", $legacyConfig)) {
$config["partkeepr.auth.allow_password_change"] = $legacyConfig["partkeepr.frontend.allow_password_change"];
}
- }
-
- return $config;
- }
-
- protected function legacyConfigParser()
- {
- if (file_exists($this->getLegacyConfigPath())) {
- $parser = new \PHPParser_Parser(new \PHPParser_Lexer());
- $traverser = new \PHPParser_NodeTraverser();
- $traverser->addVisitor(new LegacyConfigVisitor());
- $statements = $parser->parse(file_get_contents($this->getLegacyConfigPath()));
- $traverser->traverse($statements);
-
- return LegacyConfigVisitor::getConfigValues();
- }
-
- return array();
- }
- protected function configParser()
- {
- if (file_exists($this->getConfigPath(false))) {
- $parser = new \PHPParser_Parser(new \PHPParser_Lexer());
- $traverser = new \PHPParser_NodeTraverser();
- $traverser->addVisitor(new ConfigVisitor());
- $statements = $parser->parse(file_get_contents($this->getConfigPath(false)));
- $traverser->traverse($statements);
-
- return ConfigVisitor::getConfigValues();
+ if (array_key_exists("partkeepr.files.path", $legacyConfig)) {
+ $config["partkeepr.filesystem.data_directory"] = $legacyConfig["partkeepr.files.path"];
+ }
}
- return array();
- }
-
- protected function getLegacyConfigPath()
- {
- return dirname(__FILE__)."/../../../../config.php";
+ return $config;
}
-
}
diff --git a/src/PartKeepr/SetupBundle/Controller/FileMigrationController.php b/src/PartKeepr/SetupBundle/Controller/FileMigrationController.php
@@ -0,0 +1,100 @@
+<?php
+namespace PartKeepr\SetupBundle\Controller;
+
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+class FileMigrationController extends SetupController
+{
+ /**
+ * Checks if there are existing userds in the database
+ * @Route("/setup/migrateFiles")
+ *
+ * @param Request $request
+ */
+ public function migrateFilesAction(Request $request)
+ {
+ $this->dumpConfig($request);
+
+ $response = $this->handleRequest($request, "/setup/_int_migrate_files_action");
+
+ return new Response($response->getContent());
+ }
+
+ /**
+ * @Route("/setup/_int_migrate_files_action")
+ */
+ public function intMigrateFilesAction()
+ {
+ $response = array(
+ "success" => true,
+ "errors" => [],
+ "message" => "No files to migrate",
+ );
+
+ $legacyConfig = $this->legacyConfigParser();
+
+ $legacyFilePath = $this->get("kernel")->getRootDir()."/../data/";
+ $legacyImagePath = $this->get("kernel")->getRootDir()."/../data/images/";
+
+ $legacyFileDirectories = array("FootprintAttachment", "PartAttachment", "ProjectAttachment");
+
+ if (array_key_exists("partkeepr.files.path", $legacyConfig)) {
+ $legacyFilePath = $legacyConfig["partkeepr.files.path"];
+ }
+
+ if (array_key_exists("partkeepr.images.path", $legacyConfig)) {
+ $legacyImagePath = $legacyConfig["partkeepr.images.path"];
+ }
+
+ $newFilesPath = $legacyFilePath."/files/";
+ $newImagesPath = $legacyFilePath."/images/";
+
+ if (!is_dir($newFilesPath)) {
+ mkdir($newFilesPath, 0777, true);
+ }
+
+
+ if (!is_dir($newImagesPath)) {
+ mkdir($newImagesPath, 0777, true);
+ }
+
+ foreach ($legacyFileDirectories as $legacyFileDirectory) {
+ $legacyMovePath = $legacyFilePath."/".$legacyFileDirectory."/";
+ $newMovePath = $legacyFilePath."/files/".$legacyFileDirectory."/";
+
+ $this->moveFiles($legacyMovePath, $newMovePath);
+ $response["message"] = "Old image directories moved";
+ }
+
+ $legacyImageDirectories = array("footprint", "iclogo", "part", "storagelocation");
+
+ foreach ($legacyImageDirectories as $legacyImageDirectory) {
+ $legacyMovePath = $legacyImagePath."/".$legacyImageDirectory."/";
+ $newMovePath = $legacyFilePath."/images/".$legacyImageDirectory."/";
+
+ $this->moveFiles($legacyMovePath, $newMovePath);
+ $response["message"] = "Old image directories moved";
+ }
+
+ return new JsonResponse($response);
+ }
+
+ public function moveFiles($source, $target)
+ {
+ $iterator = new \DirectoryIterator($source);
+
+ if (!is_dir($target)) {
+ mkdir($target, 0777, true);
+ }
+
+ foreach ($iterator as $file) {
+ if (!$file->isDot()) {
+ rename($file->getPathName(), $target."/".$file->getFilename());
+ }
+ }
+ }
+
+}
diff --git a/src/PartKeepr/SetupBundle/Controller/SetupController.php b/src/PartKeepr/SetupBundle/Controller/SetupController.php
@@ -2,10 +2,9 @@
namespace PartKeepr\SetupBundle\Controller;
use Doctrine\DBAL\Exception\DriverException;
-use Symfony\Bundle\FrameworkBundle\Console\Application;
+use PartKeepr\SetupBundle\Visitor\ConfigVisitor;
+use PartKeepr\SetupBundle\Visitor\LegacyConfigVisitor;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-use Symfony\Component\Console\Input\ArrayInput;
-use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -43,6 +42,7 @@ class SetupController extends Controller
/**
* @Route("/setup/testConnectivity")
+ * @param Request $request
*/
public function testConnectivityAction(Request $request)
{
@@ -55,6 +55,7 @@ class SetupController extends Controller
/**
* @Route("/setup/saveConfig")
+ * @param Request $request
*/
public function saveConfigAction(Request $request)
{
@@ -243,4 +244,39 @@ class SetupController extends Controller
return dirname(__FILE__)."/../../../../app/config/".$filename;
}
+ protected function legacyConfigParser()
+ {
+ if (file_exists($this->getLegacyConfigPath())) {
+ $parser = new \PHPParser_Parser(new \PHPParser_Lexer());
+ $traverser = new \PHPParser_NodeTraverser();
+ $traverser->addVisitor(new LegacyConfigVisitor());
+ $statements = $parser->parse(file_get_contents($this->getLegacyConfigPath()));
+ $traverser->traverse($statements);
+
+ return LegacyConfigVisitor::getConfigValues();
+ }
+
+ return array();
+ }
+
+ protected function configParser()
+ {
+ if (file_exists($this->getConfigPath(false))) {
+ $parser = new \PHPParser_Parser(new \PHPParser_Lexer());
+ $traverser = new \PHPParser_NodeTraverser();
+ $traverser->addVisitor(new ConfigVisitor());
+ $statements = $parser->parse(file_get_contents($this->getConfigPath(false)));
+ $traverser->traverse($statements);
+
+ return ConfigVisitor::getConfigValues();
+ }
+
+ return array();
+ }
+
+ protected function getLegacyConfigPath()
+ {
+ return dirname(__FILE__)."/../../../../config.php";
+ }
+
}
diff --git a/src/PartKeepr/SetupBundle/Resources/config/routing.yml b/src/PartKeepr/SetupBundle/Resources/config/routing.yml
@@ -45,3 +45,7 @@ _setup_parseconfig:
_setup_existingusers:
resource: "@PartKeeprSetupBundle/Controller/ExistingUserSetupController.php"
type: annotation
+
+_setup_filemigration:
+ resource: "@PartKeeprSetupBundle/Controller/FileMigrationController.php"
+ type: annotation
diff --git a/web/setup/index.html b/web/setup/index.html
@@ -53,6 +53,7 @@
<script type="text/javascript" src="js/SetupSteps/SiPrefixSetup.js"></script>
<script type="text/javascript" src="js/SetupSteps/UnitSetup.js"></script>
<script type="text/javascript" src="js/SetupSteps/FootprintSetup.js"></script>
+ <script type="text/javascript" src="js/SetupSteps/FileMigrationSetup.js"></script>
<script type="text/javascript" src="js/PartKeeprSetup.js"></script>
</head>
diff --git a/web/setup/js/Cards/DatabaseSetupCard.js b/web/setup/js/Cards/DatabaseSetupCard.js
@@ -8,7 +8,7 @@ Ext.define('PartKeeprSetup.DatabaseSetupCard', {
extend: 'PartKeeprSetup.AbstractTestCard',
cardMessage: "PartKeepr is now being set-up.",
- breadCrumbTitle: 'Setup',
+ breadCrumbTitle: 'Setup (1/2)',
rerunTestText: "Re-run setup",
/**
* Sets up the tests
diff --git a/web/setup/js/Cards/UserSetupCard.js b/web/setup/js/Cards/UserSetupCard.js
@@ -4,8 +4,7 @@
Ext.define('PartKeeprSetup.UserSetupCard', {
extend: 'PartKeeprSetup.AbstractTestCard',
- cardMessage: "Admin user is being created",
- breadCrumbTitle: 'User Setup',
+ breadCrumbTitle: 'Setup (2/2)',
rerunTestText: "Re-run setup",
/**
* Sets up the tests
@@ -14,6 +13,7 @@ Ext.define('PartKeeprSetup.UserSetupCard', {
{
this.tests.push(new PartKeeprSetup.AdminUserSetup());
this.tests.push(new PartKeeprSetup.ConfigSetup());
+ this.tests.push(new PartKeeprSetup.FileMigrationSetup());
this.tests.push(new PartKeeprSetup.WarmupCacheSetup());
}
});
diff --git a/web/setup/js/SetupSteps/FileMigrationSetup.js b/web/setup/js/SetupSteps/FileMigrationSetup.js
@@ -0,0 +1,9 @@
+/**
+ * Moves legacy directories
+ */
+Ext.define('PartKeeprSetup.FileMigrationSetup', {
+ extend: 'PartKeeprSetup.AbstractTest',
+ action: 'migrateFiles',
+ name: "Legacy Files",
+ message: "Moving legacy files",
+});