diff --git a/app/controllers/MigrationController.php b/app/controllers/MigrationController.php index 025b93412e..7e40a9b7b1 100644 --- a/app/controllers/MigrationController.php +++ b/app/controllers/MigrationController.php @@ -1,7 +1,94 @@ migration = $migration; + + } + + public function index() + { + return View::make('migrate.index'); + } + + public function postIndex() + { + if (Input::hasFile('exportFile')) { + + // get content: + $file = Input::file('exportFile'); + $path = $file->getRealPath(); + + $this->migration->loadFile($path); + + if (!$this->migration->validFile()) { + return View::make('error')->with('message', 'Invalid JSON content.'); + } + } + + // then, start migrating! + + +// +// +// // map old and new id's. +// $map = [ +// 'accounts' => [], +// 'beneficiaries' => [], +// ]; +// +// // get the account types we need +// $beneficiaryAT = AccountType::where('description', 'Beneficiary account')->first(); +// +// // save all accounts: +// foreach ($JSON->accounts as $entry) { +// // create account: +// if ($entry->openingbalance == 0) { +// $account = $this->accounts->store(['name' => $entry->name]); +// } else { +// $account = $this->accounts->storeWithInitialBalance( +// ['name' => $entry->name], +// new Carbon($entry->openingbalancedate), +// floatval($entry->openingbalance) +// ); +// } +// $map['accounts'][$entry->id] = $account->id; +// } +// unset($entry); +// +// // save all components: +// foreach ($JSON->components as $entry) { +// switch ($entry->type->type) { +// case 'beneficiary': +// // create new account for beneficiary: +// $account = $this->accounts->store(['name' => $entry->name]); +// $map['beneficiaries'][$entry->id] = $account; +// break; +// case 'category': +// // create new component for category: +//// $account = $this->accounts->store(['name' => $entry->name]); +//// $map['beneficiaries'][$entry->id] = $account; +// break; +// } +// } +// unset($JSON->accounts); +// +// +// var_dump($JSON); +// var_dump($map); +// +// exit; +// } +// + return View::make('error')->with('message', 'No file found.'); + } + /* public function index() { diff --git a/app/database/seeds/DatabaseSeeder.php b/app/database/seeds/DatabaseSeeder.php index c45bdcb0b9..e4af46af43 100644 --- a/app/database/seeds/DatabaseSeeder.php +++ b/app/database/seeds/DatabaseSeeder.php @@ -16,6 +16,7 @@ class DatabaseSeeder extends Seeder $this->call('TransactionCurrencySeeder'); $this->call('TransactionTypeSeeder'); $this->call('ComponentTypeSeeder'); + $this->call('DefaultUserSeeder'); } } diff --git a/app/database/seeds/DefaultUserSeeder.php b/app/database/seeds/DefaultUserSeeder.php new file mode 100644 index 0000000000..f8cebf254d --- /dev/null +++ b/app/database/seeds/DefaultUserSeeder.php @@ -0,0 +1,27 @@ +delete(); + + User::create( + [ + 'email' => 's@nder.be', + 'password' => Hash::make('sander'), + 'verification' => null, + 'reset' => null, + 'remember_token' => null, + 'migrated' => false + ] + ); + } + +} \ No newline at end of file diff --git a/app/lib/Firefly/Helper/Migration/MigrationHelper.php b/app/lib/Firefly/Helper/Migration/MigrationHelper.php new file mode 100644 index 0000000000..06941dfcec --- /dev/null +++ b/app/lib/Firefly/Helper/Migration/MigrationHelper.php @@ -0,0 +1,41 @@ +path = $path; + } + + public function validFile() + { + // file does not exist: + if(!file_exists($this->path)) { + return false; + } + + // load the content: + $content = file_get_contents($this->path); + if($content === false) { + return false; + } + + // parse the content + $this->JSON = json_decode($content); + if(is_null($this->JSON)) { + return false; + } + } +} \ No newline at end of file diff --git a/app/lib/Firefly/Helper/Migration/MigrationHelperInterface.php b/app/lib/Firefly/Helper/Migration/MigrationHelperInterface.php new file mode 100644 index 0000000000..867a6da119 --- /dev/null +++ b/app/lib/Firefly/Helper/Migration/MigrationHelperInterface.php @@ -0,0 +1,18 @@ +with('index'); + View::shouldReceive('make')->with('index')->once()->andReturn(\Mockery::self()) + ->shouldReceive('with')->once() // Pass a 'with' parameter + ->with('count', 0) + ; Auth::shouldReceive('check')->andReturn(true); + $accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface'); + $accounts->shouldReceive('count')->andReturn(0); // call $this->call('GET', '/');