Some basic cleaning up.

This commit is contained in:
Sander Dorigo
2014-07-04 11:39:21 +02:00
parent 6bdaafbf72
commit c3254c2351
6 changed files with 95 additions and 36 deletions

View File

@@ -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;
}
}
}
}

View File

@@ -15,4 +15,6 @@ interface MigrationHelperInterface
public function validFile();
public function migrate();
}