mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-27 16:56:46 -06:00
Some basic cleaning up.
This commit is contained in:
parent
6bdaafbf72
commit
c3254c2351
@ -2,7 +2,8 @@
|
||||
|
||||
//use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
|
||||
class AccountController extends \BaseController {
|
||||
class AccountController extends \BaseController
|
||||
{
|
||||
|
||||
// public function __construct(ARI $accounts) {
|
||||
// $this->accounts = $accounts;
|
||||
@ -19,18 +20,15 @@ class AccountController extends \BaseController {
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Show the form for creating a new resource.
|
||||
// *
|
||||
// * @return Response
|
||||
// */
|
||||
// public function create()
|
||||
// {
|
||||
// if($this->accounts->count() == 0) {
|
||||
// return View::make('accounts.create-first-time');
|
||||
// }
|
||||
// return View::make('accounts');
|
||||
// }
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return View::make('accounts.create');
|
||||
}
|
||||
//
|
||||
//
|
||||
// /**
|
||||
|
@ -13,4 +13,4 @@ class HomeController extends BaseController {
|
||||
$count = $this->accounts->count();
|
||||
return View::make('index')->with('count',$count);
|
||||
}
|
||||
}
|
||||
}
|
@ -30,6 +30,8 @@ class MigrationController extends BaseController
|
||||
if (!$this->migration->validFile()) {
|
||||
return View::make('error')->with('message', 'Invalid JSON content.');
|
||||
}
|
||||
$this->migration->migrate();
|
||||
return 'busy!';
|
||||
}
|
||||
|
||||
// then, start migrating!
|
||||
|
@ -13,6 +13,7 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
{
|
||||
protected $path;
|
||||
protected $JSON;
|
||||
protected $map = [];
|
||||
|
||||
public function loadFile($path)
|
||||
{
|
||||
@ -22,20 +23,49 @@ class MigrationHelper implements MigrationHelperInterface
|
||||
public function validFile()
|
||||
{
|
||||
// file does not exist:
|
||||
if(!file_exists($this->path)) {
|
||||
if (!file_exists($this->path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// load the content:
|
||||
$content = file_get_contents($this->path);
|
||||
if($content === false) {
|
||||
if ($content === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// parse the content
|
||||
$this->JSON = json_decode($content);
|
||||
if(is_null($this->JSON)) {
|
||||
if (is_null($this->JSON)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function migrate()
|
||||
{
|
||||
|
||||
// create the accounts:
|
||||
$this->_createAccounts();
|
||||
}
|
||||
|
||||
protected function _createAccounts()
|
||||
{
|
||||
|
||||
$accounts = App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
|
||||
foreach ($this->JSON->accounts as $entry) {
|
||||
// create account:
|
||||
if ($entry->openingbalance == 0) {
|
||||
$account = $accounts->store(['name' => $entry->name]);
|
||||
} else {
|
||||
$account = $accounts->storeWithInitialBalance(
|
||||
['name' => $entry->name],
|
||||
new Carbon($entry->openingbalancedate),
|
||||
floatval($entry->openingbalance)
|
||||
);
|
||||
}
|
||||
if ($account) {
|
||||
$this->map['accounts'][$entry->id] = $account->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -15,4 +15,6 @@ interface MigrationHelperInterface
|
||||
|
||||
public function validFile();
|
||||
|
||||
public function migrate();
|
||||
|
||||
}
|
@ -1,24 +1,51 @@
|
||||
<?php
|
||||
|
||||
// basic home views:
|
||||
Route::get('/', ['uses' => 'HomeController@index','as' => 'index','before' => 'auth']);
|
||||
// protected routes:
|
||||
Route::group(['before' => 'auth'], function () {
|
||||
|
||||
// login, register, logout:
|
||||
Route::get('/login',['uses' => 'UserController@login','as' => 'login','before' => 'guest']);
|
||||
Route::get('/register',['uses' => 'UserController@register','as' => 'register','before' => 'guest']);
|
||||
Route::get('/verify/{verification}',['uses' => 'UserController@verify','as' => 'verify','before' => 'guest']);
|
||||
Route::get('/reset/{reset}',['uses' => 'UserController@reset','as' => 'reset','before' => 'guest']);
|
||||
Route::get('/logout',['uses' => 'UserController@logout','as' => 'logout','before' => 'auth']);
|
||||
Route::get('/remindme',['uses' => 'UserController@remindme','as' => 'remindme','before' => 'guest']);
|
||||
Route::post('/login',['uses' => 'UserController@postLogin','before' => 'csrf|guest']);
|
||||
Route::post('/register',['uses' => 'UserController@postRegister','before' => 'csrf|guest']);
|
||||
Route::post('/remindme',['uses' => 'UserController@postRemindme','before' => 'csrf|guest']);
|
||||
// home controller
|
||||
Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index']);
|
||||
|
||||
// profile (after login / logout)
|
||||
Route::get('/profile',['uses' => 'ProfileController@index','as' => 'profile','before' => 'auth']);
|
||||
Route::get('/profile/change-password',['uses' => 'ProfileController@changePassword','as' => 'change-password','before' => 'auth']);
|
||||
Route::post('/profile/change-password',['uses' => 'ProfileController@postChangePassword','before' => 'csrf|auth']);
|
||||
// user controller
|
||||
Route::get('/logout', ['uses' => 'UserController@logout', 'as' => 'logout']);
|
||||
|
||||
// migrate controller:
|
||||
Route::get('/migrate',['uses' => 'MigrationController@index','as' => 'migrate','before' => 'auth']);
|
||||
Route::post('/migrate',['uses' => 'MigrationController@postIndex','before' => 'csrf|auth']);
|
||||
//profile controller
|
||||
Route::get('/profile', ['uses' => 'ProfileController@index', 'as' => 'profile']);
|
||||
Route::get('/profile/change-password',['uses' => 'ProfileController@changePassword', 'as' => 'change-password']);
|
||||
|
||||
// migration controller
|
||||
Route::get('/migrate', ['uses' => 'MigrationController@index', 'as' => 'migrate']);
|
||||
}
|
||||
);
|
||||
|
||||
// protected + csrf routes
|
||||
Route::group(['before' => 'csrf|auth'], function () {
|
||||
// profile controller
|
||||
Route::post('/profile/change-password', ['uses' => 'ProfileController@postChangePassword']);
|
||||
|
||||
// migration controller
|
||||
Route::post('/migrate', ['uses' => 'MigrationController@postIndex']);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// guest routes:
|
||||
Route::group(['before' => 'csrf|auth'], function () {
|
||||
// user controller
|
||||
Route::get('/login', ['uses' => 'UserController@login', 'as' => 'login']);
|
||||
Route::get('/register', ['uses' => 'UserController@register', 'as' => 'register']);
|
||||
Route::get('/verify/{verification}', ['uses' => 'UserController@verify', 'as' => 'verify']);
|
||||
Route::get('/reset/{reset}', ['uses' => 'UserController@reset', 'as' => 'reset']);
|
||||
Route::get('/remindme', ['uses' => 'UserController@remindme', 'as' => 'remindme']);
|
||||
}
|
||||
);
|
||||
|
||||
// guest + csrf routes:
|
||||
Route::group(['before' => 'csrf|guest'], function () {
|
||||
|
||||
// user controller
|
||||
Route::post('/login', ['uses' => 'UserController@postLogin']);
|
||||
Route::post('/register', ['uses' => 'UserController@postRegister']);
|
||||
Route::post('/remindme', ['uses' => 'UserController@postRemindme']);
|
||||
}
|
||||
);
|
Loading…
Reference in New Issue
Block a user