Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Extra large code cleanup.
James Colec4312c0b1111
diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.phpindex dd0a6979c0..c4aa08799a 100644--- a/app/Http/Controllers/PiggyBankController.php+++ b/app/Http/Controllers/PiggyBankController.php@@ -141,7 +141,7 @@ class PiggyBankController extends Controllerpublic function index(AccountRepositoryInterface $repository){/** @var Collection $piggyBanks */- $piggyBanks = Auth::user()->piggyBanks()->where('repeats', 0)->orderBy('order', 'ASC')->get();+ $piggyBanks = Auth::user()->piggyBanks()->orderBy('order', 'ASC')->get();$accounts = [];/** @var PiggyBank $piggyBank */@@ -298,7 +298,6 @@ class PiggyBankController extends Controllerpublic function store(PiggyBankFormRequest $request, PiggyBankRepositoryInterface $repository){$piggyBankData = [- 'repeats' => false,'name' => $request->get('name'),'startdate' => new Carbon,'account_id' => intval($request->get('account_id')),@@ -330,7 +329,6 @@ class PiggyBankController extends Controllerpublic function update(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository, PiggyBankFormRequest $request){$piggyBankData = [- 'repeats' => false,'name' => $request->get('name'),'startdate' => is_null($piggyBank->startdate) ? $piggyBank->created_at : $piggyBank->startdate,'account_id' => intval($request->get('account_id')),diff --git a/app/Http/Middleware/PiggyBanks.php b/app/Http/Middleware/PiggyBanks.phpindex fc2c40aa39..35b90281a0 100644--- a/app/Http/Middleware/PiggyBanks.php+++ b/app/Http/Middleware/PiggyBanks.php@@ -55,7 +55,6 @@ class PiggyBanks/** @var Collection $set */$set = $this->auth->user()->piggybanks()->leftJoin('piggy_bank_repetitions', 'piggy_banks.id', '=', 'piggy_bank_repetitions.piggy_bank_id')- ->where('piggy_banks.repeats', 0)->whereNull('piggy_bank_repetitions.id')->get(['piggy_banks.id', 'piggy_banks.startdate', 'piggy_banks.targetdate']);if ($set->count() > 0) {@@ -70,68 +69,6 @@ class PiggyBanks}}unset($partialPiggy, $set, $repetition);-- // get repeating piggy banks without a repetition for current time frame.- /** @var Collection $set */- $set = $this->auth->user()->piggybanks()->leftJoin(- 'piggy_bank_repetitions', function (JoinClause $join) {- $join->on('piggy_bank_repetitions.piggy_bank_id', '=', 'piggy_banks.id')- ->where('piggy_bank_repetitions.targetdate', '>=', Session::get('start')->format('Y-m-d'))- ->where('piggy_bank_repetitions.startdate', '<=', Session::get('end')->format('Y-m-d'));- }- )- ->where('repeats', 1)- ->whereNull('piggy_bank_repetitions.id')- ->get(['piggy_banks.*']);-- // these piggy banks are missing a repetition. start looping and create them!- if ($set->count() > 0) {- /** @var PiggyBank $piggyBank */- foreach ($set as $piggyBank) {- $start = clone $piggyBank->startdate;- $end = clone $piggyBank->targetdate;- $max = clone $piggyBank->targetdate;-- // first loop: start date to target date.- // then, continue looping until end is > today- while ($start <= $max) {- // first loop fixes this date. or should fix it.- $max = new Carbon;-- echo '[#' . $piggyBank->id . ', from: ' . $start->format('Y-m-d.') . ' to ' . $end->format('Y-m-d.') . ']';- // create stuff. Or at least, try:- $repetition = $piggyBank->piggyBankRepetitions()->onDates($start, $end)->first();- if (!$repetition) {- $repetition = new PiggyBankRepetition;- $repetition->piggyBank()->associate($piggyBank);- $repetition->startdate = $start;- $repetition->targetdate = $end;- $repetition->currentamount = 0;- // it might exist, catch:- $repetition->save();- }-- // start where end 'ended':- $start = clone $end;- // move end.- $end = Navigation::addPeriod($end, $piggyBank->rep_length, 0);-- }--- // first repetition: from original start to original target.- $repetition = new PiggyBankRepetition;- $repetition->piggyBank()->associate($piggyBank);- $repetition->startdate = is_null($piggyBank->startdate) ? null : $piggyBank->startdate;- $repetition->targetdate = is_null($piggyBank->targetdate) ? null : $piggyBank->targetdate;- $repetition->currentamount = 0;- // it might exist, catch:-- // then, loop from original target up to now.- }- }--}return $next($request);diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.phpindex a9b704f4b3..bd3c6780f5 100644--- a/app/Http/Requests/AccountFormRequest.php+++ b/app/Http/Requests/AccountFormRequest.php@@ -32,11 +32,14 @@ class AccountFormRequest extends Request$types = join(',', array_keys(Config::get('firefly.subTitlesByIdentifier')));$nameRule = 'required|between:1,100|uniqueAccountForUser';+ $idRule = '';if (Account::find(Input::get('id'))) {- $nameRule = 'required|between:1,100|belongsToUser:accounts|uniqueForUser:' . Input::get('id');+ $idRule = 'belongsToUser:accounts';+ $nameRule = 'required|between:1,100|uniqueAccountForUser:' . Input::get('id');}return [+ 'id' => $idRule,'name' => $nameRule,'openingBalance' => 'numeric','openingBalanceDate' => 'date',diff --git a/app/Http/Requests/PiggyBankFormRequest.php b/app/Http/Requests/PiggyBankFormRequest.phpindex 795246c1b8..2c9a668807 100644--- a/app/Http/Requests/PiggyBankFormRequest.php+++ b/app/Http/Requests/PiggyBankFormRequest.php@@ -35,27 +35,14 @@ class PiggyBankFormRequest extends Request$nameRule = 'required|between:1,255';}- if (intval(Input::get('repeats')) == 1) {- $targetDateRule = 'required|date|after:' . date('Y-m-d');- // switch on rep_every, make sure it's not too far away.- if (!is_null(Input::get('rep_length'))) {- $end = Navigation::addPeriod(new Carbon, Input::get('rep_length'), 0);- $targetDateRule .= '|before:' . $end->format('Y-m-d');- }- }-$rules = [- 'repeats' => 'required|boolean','name' => $nameRule,'account_id' => 'required|belongsToUser:accounts','targetamount' => 'required|min:0.01','amount_currency_id' => 'exists:transaction_currencies,id','startdate' => 'date','targetdate' => $targetDateRule,- 'rep_length' => 'in:day,week,quarter,month,year',- 'rep_every' => 'integer|min:0|max:31',- 'rep_times' => 'integer|min:0|max:99','reminder' => 'in:day,week,quarter,month,year','reminder_skip' => 'integer|min:0|max:99','remind_me' => 'boolean|piggyBankReminder',diff --git a/app/Http/routes.php b/app/Http/routes.phpindex 685009ac92..bc4c4fba3a 100644--- a/app/Http/routes.php+++ b/app/Http/routes.php@@ -107,7 +107,7 @@ Route::bind(where('piggy_banks.id', $value)->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id)- ->where('repeats', 0)->first(['piggy_banks.*']);+ ->first(['piggy_banks.*']);}return null;diff --git a/app/Models/Account.php b/app/Models/Account.phpindex 0b77b81bbb..2d4934b005 100644--- a/app/Models/Account.php+++ b/app/Models/Account.php@@ -15,6 +15,7 @@ class Account extends Model{use SoftDeletes, ValidatingTrait;+ protected $fillable = ['user_id', 'account_type_id', 'name', 'active'];protected $rules= ['user_id' => 'required|exists:users,id',@@ -23,7 +24,29 @@ class Account extends Model'active' => 'required|boolean'];- protected $fillable = ['user_id', 'account_type_id', 'name', 'active'];+ /**+ * @return \Illuminate\Database\Eloquent\Relations\HasMany+ */+ public function accountMeta()+ {+ return $this->hasMany('FireflyIII\Models\AccountMeta');+ }++ /**+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo+ */+ public function accountType()+ {+ return $this->belongsTo('FireflyIII\Models\AccountType');+ }++ /**+ * @return array+ */+ public function getDates()+ {+ return ['created_at', 'updated_at', 'deleted_at'];+ }/*** @param $fieldName@@ -42,57 +65,52 @@ class Account extends Model}- /**- * @param $value- *- * @return string- */- public function getNameAttribute($value)- {- if ($this->encrypted) {- return Crypt::decrypt($value);- }- // @codeCoverageIgnoreStart- return $value;- // @codeCoverageIgnoreEnd- }/*** @return \Illuminate\Database\Eloquent\Relations\HasMany*/- public function accountMeta()+ public function piggyBanks(){- return $this->hasMany('FireflyIII\Models\AccountMeta');+ return $this->hasMany('FireflyIII\Models\PiggyBank');}/**- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo+ * @param EloquentBuilder $query+ * @param array $types*/- public function accountType()+ public function scopeAccountTypeIn(EloquentBuilder $query, array $types){- return $this->belongsTo('FireflyIII\Models\AccountType');+ if (is_null($this->joinedAccountTypes)) {+ $query->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id');+ $this->joinedAccountTypes = true;+ }+ $query->whereIn('account_types.type', $types);}/**- * @return array+ * @param $value*/- public function getDates()+ public function setNameAttribute($value){- return ['created_at', 'updated_at', 'deleted_at'];+ $this->attributes['name'] = Crypt::encrypt($value);+ $this->attributes['encrypted'] = true;}-/**- * @param EloquentBuilder $query- * @param array $types+ * @param $value+ *+ * @return string*/- public function scopeAccountTypeIn(EloquentBuilder $query, array $types)+ public function getNameAttribute($value){- if (is_null($this->joinedAccountTypes)) {- $query->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id');- $this->joinedAccountTypes = true;++ if (intval($this->encrypted) == 1) {+ return Crypt::decrypt($value);}- $query->whereIn('account_types.type', $types);++ // @codeCoverageIgnoreStart+ return $value;+ // @codeCoverageIgnoreEnd}/**@@ -111,12 +129,4 @@ class Account extends Modelreturn $this->belongsTo('FireflyIII\User');}- /**- * @return \Illuminate\Database\Eloquent\Relations\HasMany- */- public function piggyBanks()- {- return $this->hasMany('FireflyIII\Models\PiggyBank');- }-}diff --git a/app/Models/Bill.php b/app/Models/Bill.phpindex 62beebef2d..d181e616c3 100644--- a/app/Models/Bill.php+++ b/app/Models/Bill.php@@ -1,5 +1,6 @@<?php namespace FireflyIII\Models;+use Crypt;use Illuminate\Database\Eloquent\Model;/**@@ -10,7 +11,8 @@ use Illuminate\Database\Eloquent\Model;class Bill extends Model{- protected $fillable = ['name', 'match', 'amount_min', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',];+ protected $fillable+ = ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',];/*** @return array@@ -20,6 +22,58 @@ class Bill extends Modelreturn ['created_at', 'updated_at', 'date'];}+ /**+ * @param $value+ *+ * @return string+ */+ public function getMatchAttribute($value)+ {++ if (intval($this->match_encrypted) == 1) {+ return Crypt::decrypt($value);+ }++ // @codeCoverageIgnoreStart+ return $value;+ // @codeCoverageIgnoreEnd+ }++ /**+ * @param $value+ *+ * @return string+ */+ public function getNameAttribute($value)+ {++ if (intval($this->name_encrypted) == 1) {+ return Crypt::decrypt($value);+ }++ // @codeCoverageIgnoreStart+ return $value;+ // @codeCoverageIgnoreEnd+ }++ /**+ * @param $value+ */+ public function setMatchAttribute($value)+ {+ $this->attributes['match'] = Crypt::encrypt($value);+ $this->attributes['match_encrypted'] = true;+ }++ /**+ * @param $value+ */+ public function setNameAttribute($value)+ {+ $this->attributes['name'] = Crypt::encrypt($value);+ $this->attributes['name_encrypted'] = true;+ }+/*** @return \Illuminate\Database\Eloquent\Relations\HasMany*/diff --git a/app/Models/Budget.php b/app/Models/Budget.phpindex b07c11b830..61d059a11f 100644--- a/app/Models/Budget.php+++ b/app/Models/Budget.php@@ -2,6 +2,7 @@use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\SoftDeletes;+use Crypt;/*** Class Budget@@ -55,5 +56,30 @@ class Budget extends Modelreturn $this->belongsTo('FireflyIII\User');}+ /**+ * @param $value+ */+ public function setNameAttribute($value)+ {+ $this->attributes['name'] = Crypt::encrypt($value);+ $this->attributes['encrypted'] = true;+ }+ /**+ * @param $value+ *+ * @return string+ */+ public function getNameAttribute($value)+ {++ if (intval($this->encrypted) == 1) {+ return Crypt::decrypt($value);+ }++ // @codeCoverageIgnoreStart+ return $value;+ // @codeCoverageIgnoreEnd+ }+}diff --git a/app/Models/Category.php b/app/Models/Category.phpindex 37f12c7ca8..539f889378 100644--- a/app/Models/Category.php+++ b/app/Models/Category.php@@ -2,7 +2,7 @@use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\SoftDeletes;-+use Crypt;/*** Class Category*@@ -38,4 +38,29 @@ class Category extends Modelreturn $this->belongsTo('FireflyIII\User');}+ /**+ * @param $value+ */+ public function setNameAttribute($value)+ {+ $this->attributes['name'] = Crypt::encrypt($value);+ $this->attributes['encrypted'] = true;+ }+ /**+ * @param $value+ *+ * @return string+ */+ public function getNameAttribute($value)+ {++ if (intval($this->encrypted) == 1) {+ return Crypt::decrypt($value);+ }++ // @codeCoverageIgnoreStart+ return $value;+ // @codeCoverageIgnoreEnd+ }+}diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.phpindex b46c34cd3d..c81ef28b71 100644--- a/app/Models/PiggyBank.php+++ b/app/Models/PiggyBank.php@@ -1,10 +1,8 @@<?php namespace FireflyIII\Models;-use Carbon\Carbon;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\SoftDeletes;-use Log;-+use Crypt;/*** Class PiggyBank*@@ -15,8 +13,7 @@ class PiggyBank extends Modeluse SoftDeletes;protected $fillable- = ['repeats', 'name', 'account_id', 'rep_every', 'rep_times', 'reminder_skip', 'targetamount', 'startdate', 'targetdate', 'reminder', 'remind_me',- 'rep_length'];+ = ['name', 'account_id', 'reminder_skip', 'targetamount', 'startdate', 'targetdate', 'reminder', 'remind_me'];/*** @return \Illuminate\Database\Eloquent\Relations\BelongsTo@@ -37,14 +34,10 @@ class PiggyBank extends Modelreturn $this->currentRep;}// repeating piggy banks are no longer supported.- if (intval($this->repeats) === 0) {- $rep = $this->piggyBankRepetitions()->first(['piggy_bank_repetitions.*']);- $this->currentRep = $rep;+ $rep = $this->piggyBankRepetitions()->first(['piggy_bank_repetitions.*']);+ $this->currentRep = $rep;- return $rep;- } else {- Log::error('Tried to work with a piggy bank with a repeats=1 value! (id is ' . $this->id . ')');- }+ return $rep;}@@ -90,4 +83,29 @@ class PiggyBank extends Model{return $this->morphMany('FireflyIII\Models\Reminder', 'remindersable');}++ /**+ * @param $value+ */+ public function setNameAttribute($value)+ {+ $this->attributes['name'] = Crypt::encrypt($value);+ $this->attributes['encrypted'] = true;+ }+ /**+ * @param $value+ *+ * @return string+ */+ public function getNameAttribute($value)+ {++ if (intval($this->encrypted) == 1) {+ return Crypt::decrypt($value);+ }++ // @codeCoverageIgnoreStart+ return $value;+ // @codeCoverageIgnoreEnd+ }}diff --git a/app/Models/Reminder.php b/app/Models/Reminder.phpindex 7a39b59a54..62c053d765 100644--- a/app/Models/Reminder.php+++ b/app/Models/Reminder.php@@ -3,7 +3,7 @@use Carbon\Carbon;use Illuminate\Database\Eloquent\Builder as EloquentBuilder;use Illuminate\Database\Eloquent\Model;-+use Crypt;/*** Class Reminder*@@ -40,6 +40,9 @@ class Reminder extends Model*/public function getMetadataAttribute($value){+ if (intval($this->encrypted) == 1) {+ return json_decode(Crypt::decrypt($value));+ }return json_decode($value);}@@ -86,7 +89,8 @@ class Reminder extends Model*/public function setMetadataAttribute($value){- $this->attributes['metadata'] = json_encode($value);+ $this->attributes['encrypted'] = true;+ $this->attributes['metadata'] = Crypt::encrypt(json_encode($value));}/**diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.phpindex 9eaa117622..fb381ba1c1 100644--- a/app/Repositories/PiggyBank/PiggyBankRepository.php+++ b/app/Repositories/PiggyBank/PiggyBankRepository.php@@ -153,9 +153,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface$piggyBank->targetdate = $data['targetdate'];$piggyBank->reminder = $data['reminder'];$piggyBank->startdate = $data['startdate'];- $piggyBank->rep_length = isset($data['rep_length']) ? $data['rep_length'] : null;- $piggyBank->rep_every = isset($data['rep_every']) ? $data['rep_every'] : null;- $piggyBank->rep_times = isset($data['rep_times']) ? $data['rep_times'] : null;$piggyBank->remind_me = isset($data['remind_me']) && $data['remind_me'] == '1' ? 1 : 0;$piggyBank->save();diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.phpindex 8ee5399b65..a44c139adb 100644--- a/app/Validation/FireflyValidator.php+++ b/app/Validation/FireflyValidator.php@@ -2,14 +2,18 @@namespace FireflyIII\Validation;+use App;use Auth;use Carbon\Carbon;use Config;use DB;+use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;+use Illuminate\Contracts\Encryption\DecryptException;use Illuminate\Validation\Validator;-use Input;use Navigation;+use Crypt;+use Log;/*** Class FireflyValidator@@ -28,6 +32,7 @@ class FireflyValidator extends Validator*/public function validateBelongsToUser($attribute, $value, $parameters){+$count = DB::table($parameters[0])->where('user_id', Auth::user()->id)->where('id', $value)->count();if ($count == 1) {return true;@@ -79,44 +84,105 @@ class FireflyValidator extends Validator*/public function validateUniqueAccountForUser($attribute, $value, $parameters){- // get account type from data, we must have this:- $validTypes = array_keys(Config::get('firefly.subTitlesByIdentifier'));+ $type = null;- $type = isset($this->data['what']) && in_array($this->data['what'], $validTypes) ? $this->data['what'] : null;- // some fallback:- if (is_null($type)) {- $type = in_array(Input::get('what'), $validTypes) ? Input::get('what') : null;- }- // still null?- if (is_null($type)) {- // find by other field:- $type = isset($this->data['account_type_id']) ? $this->data['account_type_id'] : 0;- $dbType = AccountType::find($type);- } else {- $longType = Config::get('firefly.accountTypeByIdentifier.' . $type);- $dbType = AccountType::whereType($longType)->first();- }+ /**+ * Switch on different cases on which this method can respond:+ */+ $hasWhat = isset($this->data['what']);+ $hasAccountId = isset($this->data['account_type_id']) && isset($this->data['name']);- if (is_null($dbType)) {- return false;+ if ($hasWhat) {++ $search = Config::get('firefly.accountTypeByIdentifier.' . $this->data['what']);+ $type = AccountType::whereType($search)->first();+ // this field can be used to find the exact type, and continue.+ }+ if($hasAccountId) {+ $type = AccountType::find($this->data['account_type_id']);}- // user id?- $userId = Auth::check() ? Auth::user()->id : $this->data['user_id'];+ /**+ * Try to decrypt data just in case:+ */+ try {+ $value = Crypt::decrypt($value);+ } catch(DecryptException $e) {}- $query = DB::table('accounts')->where('name', $value)->where('account_type_id', $dbType->id)->where('user_id', $userId);- if (isset($parameters[0])) {- $query->where('id', '!=', $parameters[0]);+ if (is_null($type)) {+ Log::error('Could not determine type of account to validate.');+ return false;}- $count = $query->count();- if ($count == 0) {- return true;+ // get all accounts with this type, and find the name.+ $userId = Auth::check() ? Auth::user()->id : 0;+ $set = Account::where('account_type_id', $type->id)->where('user_id', $userId)->get();+ /** @var Account $entry */+ foreach ($set as $entry) {+ if ($entry->name == $value) {+ return false;+ }}- return false;+ return true;+ // exit;+ //+ //+ // // get account type from data, we must have this:+ // $validTypes = array_keys(Config::get('firefly.subTitlesByIdentifier'));+ // $dbType = null;+ // $type = isset($this->data['what']) && in_array($this->data['what'], $validTypes) ? $this->data['what'] : null;+ // // some fallback:+ // if (is_null($type)) {+ // $type = in_array(Input::get('what'), $validTypes) ? Input::get('what') : null;+ //+ // }+ //+ // // still null?+ // if (is_null($type)) {+ // // find by other field:+ // $findType = isset($this->data['account_type_id']) ? $this->data['account_type_id'] : 0;+ // $dbType = AccountType::find($findType);+ // $type = $findType == 0 ? null : $findType;+ // }+ // // STILL null?+ //+ // if (is_null($type) && isset($this->data['id'])) {+ // // check ID thingie+ // $dbAccount = Account::find($this->data['id']);+ // if (!$dbAccount) {+ // Log::error('False because $dbAccount does not exist.');+ //+ // return false;+ // }+ // $dbType = AccountType::find($dbAccount->account_type_id);+ // } else {+ // $dbType = AccountType::whereType()+ // }+ //+ // if (is_null($dbType)) {+ // Log::error('False because $dbType is null.');+ //+ // return false;+ // }+ //+ // // user id?+ // $userId = Auth::check() ? Auth::user()->id : $this->data['user_id'];+ //+ // $query = DB::table('accounts')->where('name', $value)->where('account_type_id', $dbType->id)->where('user_id', $userId);+ //+ // if (isset($parameters[0])) {+ // $query->where('id', '!=', $parameters[0]);+ // }+ // $count = $query->count();+ // if ($count == 0) {+ //+ // return true;+ // }+ //+ // return false;}diff --git a/database/migrations/2014_12_13_190730_changes_for_v321.php b/database/migrations/2014_12_13_190730_changes_for_v321.phpindex 84a59ab82b..9b4c82db98 100644--- a/database/migrations/2014_12_13_190730_changes_for_v321.php+++ b/database/migrations/2014_12_13_190730_changes_for_v321.php@@ -1,8 +1,8 @@<?phpuse FireflyIII\Models\Budget;-use FireflyIII\Models\Category;use FireflyIII\Models\BudgetLimit;+use FireflyIII\Models\Category;use FireflyIII\Models\Component;use Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;diff --git a/database/migrations/2015_02_27_210653_changes_for_v332.php b/database/migrations/2015_02_27_210653_changes_for_v332.phpindex 41d651d0cc..bbf876afd4 100644--- a/database/migrations/2015_02_27_210653_changes_for_v332.php+++ b/database/migrations/2015_02_27_210653_changes_for_v332.php@@ -1,20 +1,31 @@<?php-use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;/*** Class ChangesForV332*/-class ChangesForV332 extends Migration {+class ChangesForV332 extends Migration+{++ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {+ //+ }- /**- * Run the migrations.- *- * @return void- */- public function up()- {+ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up()+ {Schema::table('accounts', function (Blueprint $table) {@@ -33,14 +44,4 @@ class ChangesForV332 extends Migration {}- /**- * Reverse the migrations.- *- * @return void- */- public function down()- {- //- }-}diff --git a/database/migrations/2015_03_27_061038_changes_for_v333.php b/database/migrations/2015_03_27_061038_changes_for_v333.phpindex 3b8b2e81e0..75bc20bcad 100644--- a/database/migrations/2015_03_27_061038_changes_for_v333.php+++ b/database/migrations/2015_03_27_061038_changes_for_v333.php@@ -1,33 +1,34 @@<?php-use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;-class ChangesForV333 extends Migration {+class ChangesForV333 extends Migration+{- /**- * Run the migrations.- *- * @return void- */- public function up()- {+ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {+ //+ }++ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up()+ {Schema::table('transaction_journals', function (Blueprint $table) {- $table->smallInteger('order',false,true)->default(0);+ $table->smallInteger('order', false, true)->default(0);});- }-- /**- * Reverse the migrations.- *- * @return void- */- public function down()- {- //- }+ }}diff --git a/database/migrations/2015_03_29_174140_changes_for_336.php b/database/migrations/2015_03_29_174140_changes_for_336.phpdeleted file mode 100644index a1681111be..0000000000--- a/database/migrations/2015_03_29_174140_changes_for_336.php+++ /dev/null@@ -1,33 +0,0 @@-<?php--use Illuminate\Database\Schema\Blueprint;-use Illuminate\Database\Migrations\Migration;--class ChangesFor336 extends Migration {-- /**- * Run the migrations.- *- * @return void- */- public function up()- {- Schema::table(- 'budgets', function (Blueprint $table) {- $table->smallInteger('active',false,true)->default(1);-- }- );- }-- /**- * Reverse the migrations.- *- * @return void- */- public function down()- {- //- }--}diff --git a/database/migrations/2015_03_29_174140_changes_for_v336.php b/database/migrations/2015_03_29_174140_changes_for_v336.phpnew file mode 100644index 0000000000..90deaddfbb--- /dev/null+++ b/database/migrations/2015_03_29_174140_changes_for_v336.php@@ -0,0 +1,184 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;++/**+ * Class ChangesForV336+ */+class ChangesForV336 extends Migration+{++ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {+ //+ }++ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up()+ {++ /**+ * ACCOUNTS+ */+ // change field to be cryptable.+ Schema::table(+ 'accounts', function (Blueprint $table) {+ // drop foreign key:+ $table->dropForeign('accounts_user_id_foreign');++ // drop unique:+ $table->dropUnique('accounts_user_id_account_type_id_name_unique');+ }+ );++ Schema::table(+ 'accounts', function (Blueprint $table) {+ $table->text('name')->change();+ $table->foreign('user_id', 'account_user_id')->references('id')->on('users')->onDelete('cascade');+ }+ );++ /**+ * BUDGETS+ */+ // add active/inactive and encrypt.+ Schema::table(+ 'budgets', function (Blueprint $table) {+ $table->smallInteger('active', false, true)->default(1);+ $table->smallInteger('encrypted', false, true)->default(0);++ // drop foreign key:+ $table->dropForeign('budgets_user_id_foreign');++ // drop unique:+ $table->dropUnique('budgets_user_id_name_unique');++ }+ );+ Schema::table(+ 'budgets', function (Blueprint $table) {+ $table->text('name')->change();+ $table->foreign('user_id', 'budget_user_id')->references('id')->on('users')->onDelete('cascade');+ }+ );+++ /**+ * BILLS+ */+ // change field to be cryptable.+ Schema::table(+ 'bills', function (Blueprint $table) {+ // drop foreign key:+ $table->dropForeign('bills_uid_for');++ // drop unique:+ $table->dropUnique('uid_name_unique');+ }+ );++ Schema::table(+ 'bills', function (Blueprint $table) {+ // raw query:++ DB::insert('ALTER TABLE `bills` CHANGE `name` `name` TEXT NOT NULL');+ DB::insert('ALTER TABLE `bills` CHANGE `match` `match` TEXT NOT NULL');+ $table->smallInteger('name_encrypted', false, true)->default(0);+ $table->smallInteger('match_encrypted', false, true)->default(0);+ $table->foreign('user_id', 'bill_user_id')->references('id')->on('users')->onDelete('cascade');+ }+ );++ /**+ * CATEGORIES+ */+ Schema::table(+ 'categories', function (Blueprint $table) {+ $table->smallInteger('encrypted', false, true)->default(0);++ // drop foreign key:+ $table->dropForeign('categories_user_id_foreign');++ // drop unique:+ $table->dropUnique('categories_user_id_name_unique');++ }+ );+ Schema::table(+ 'categories', function (Blueprint $table) {+ $table->text('name')->change();+ $table->foreign('user_id', 'category_user_id')->references('id')->on('users')->onDelete('cascade');+ }+ );++ /**+ * PIGGY BANKS+ */+ Schema::table(+ 'piggy_banks', function (Blueprint $table) {+ $table->smallInteger('encrypted', false, true)->default(0);++ // drop foreign:+ $table->dropForeign('piggybanks_account_id_foreign');++ // drop unique:+ $table->dropUnique('piggybanks_account_id_name_unique');++ }+ );+ Schema::table(+ 'piggy_banks', function (Blueprint $table) {+ DB::insert('ALTER TABLE `piggy_banks` CHANGE `name` `name` TEXT NOT NULL');+ $table->dropColumn(['repeats', 'rep_length', 'rep_every', 'rep_times']);++ // create index again:+ $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');+ }+ );++ /**+ * REMINDERS+ */+ Schema::table(+ 'reminders', function (Blueprint $table) {+ $table->smallInteger('encrypted', false, true)->default(0);+++ }+ );++ //+ // Schema::table(+ // 'categories', function (Blueprint $table) {+ // $table->smallInteger('encrypted', false, true)->default(0);+ // $table->text('name')->change();+ // }+ // );+ //+ // Schema::table(+ // 'piggy_banks', function (Blueprint $table) {+ // $table->smallInteger('encrypted', false, true)->default(0);+ // $table->text('name')->change();+ // $table->dropColumn(['repeats', 'rep_length', 'rep_every', 'rep_times']);+ // }+ // );+ // Schema::table(+ // 'reminders', function (Blueprint $table) {+ // $table->smallInteger('encrypted', false, true)->default(0);+ // }+ // );+++ }++}diff --git a/database/seeds/TestDataSeeder.php b/database/seeds/TestDataSeeder.phpindex 62ee9465bb..37fdb22004 100644--- a/database/seeds/TestDataSeeder.php+++ b/database/seeds/TestDataSeeder.php@@ -257,10 +257,6 @@ class TestDataSeeder extends Seeder'targetamount' => 2000,'startdate' => $this->som,'targetdate' => null,- 'repeats' => 0,- 'rep_length' => null,- 'rep_every' => 0,- 'rep_times' => null,'reminder' => null,'reminder_skip' => 0,'remind_me' => 0,@@ -278,10 +274,6 @@ class TestDataSeeder extends Seeder'targetamount' => 2000,'startdate' => $this->som,'targetdate' => $end,- 'repeats' => 0,- 'rep_length' => null,- 'rep_every' => 0,- 'rep_times' => null,'reminder' => null,'reminder_skip' => 0,'remind_me' => 0,@@ -307,10 +299,6 @@ class TestDataSeeder extends Seeder'targetamount' => 1000,'startdate' => $this->som,'targetdate' => $nextYear,- 'repeats' => 0,- 'rep_length' => null,- 'rep_every' => 0,- 'rep_times' => null,'reminder' => $entry,'reminder_skip' => 0,'remind_me' => 1,@@ -324,10 +312,6 @@ class TestDataSeeder extends Seeder'targetamount' => 1000,'startdate' => $this->som,'targetdate' => null,- 'repeats' => 0,- 'rep_length' => null,- 'rep_every' => 0,- 'rep_times' => null,'reminder' => $entry,'reminder_skip' => 0,'remind_me' => 1,