mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 19:53:44 +00:00
Fixed tests, added migration stuff, added default user.
This commit is contained in:
@@ -1,7 +1,94 @@
|
||||
<?php
|
||||
|
||||
use Firefly\Helper\Migration\MigrationHelperInterface as MHI;
|
||||
|
||||
class MigrationController extends BaseController
|
||||
{
|
||||
protected $migration;
|
||||
|
||||
public function __construct(MHI $migration)
|
||||
{
|
||||
$this->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()
|
||||
{
|
||||
|
@@ -16,6 +16,7 @@ class DatabaseSeeder extends Seeder
|
||||
$this->call('TransactionCurrencySeeder');
|
||||
$this->call('TransactionTypeSeeder');
|
||||
$this->call('ComponentTypeSeeder');
|
||||
$this->call('DefaultUserSeeder');
|
||||
}
|
||||
|
||||
}
|
||||
|
27
app/database/seeds/DefaultUserSeeder.php
Normal file
27
app/database/seeds/DefaultUserSeeder.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sander
|
||||
* Date: 03/07/14
|
||||
* Time: 21:06
|
||||
*/
|
||||
class DefaultUserSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
DB::table('users')->delete();
|
||||
|
||||
User::create(
|
||||
[
|
||||
'email' => 's@nder.be',
|
||||
'password' => Hash::make('sander'),
|
||||
'verification' => null,
|
||||
'reset' => null,
|
||||
'remember_token' => null,
|
||||
'migrated' => false
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
41
app/lib/Firefly/Helper/Migration/MigrationHelper.php
Normal file
41
app/lib/Firefly/Helper/Migration/MigrationHelper.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sander
|
||||
* Date: 03/07/14
|
||||
* Time: 21:34
|
||||
*/
|
||||
|
||||
namespace Firefly\Helper\Migration;
|
||||
|
||||
|
||||
class MigrationHelper implements MigrationHelperInterface
|
||||
{
|
||||
protected $path;
|
||||
protected $JSON;
|
||||
|
||||
public function loadFile($path)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sander
|
||||
* Date: 03/07/14
|
||||
* Time: 21:33
|
||||
*/
|
||||
|
||||
namespace Firefly\Helper\Migration;
|
||||
|
||||
|
||||
interface MigrationHelperInterface
|
||||
{
|
||||
public function loadFile($path);
|
||||
|
||||
public function validFile();
|
||||
|
||||
}
|
@@ -10,8 +10,13 @@ class HomeControllerTest extends TestCase
|
||||
public function testIndex()
|
||||
{
|
||||
// mock:
|
||||
View::shouldReceive('make')->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', '/');
|
||||
|
Reference in New Issue
Block a user