Merge branch 'release/4.6.3'

This commit is contained in:
James Cole
2017-07-23 10:01:48 +02:00
202 changed files with 5300 additions and 1827 deletions

View File

@@ -311,6 +311,9 @@ class Amount
$coloured = false;
$format = '<span class="text-info">%s</span>';
}
if ($transaction->transaction_type_type === TransactionType::OPENING_BALANCE) {
$amount = strval($transaction->transaction_amount);
}
$currency = new TransactionCurrency;
$currency->symbol = $transaction->transaction_currency_symbol;

View File

@@ -18,7 +18,6 @@ use Cache;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection;
use Log;
use Preferences as Prefs;
/**
@@ -75,7 +74,7 @@ class CacheProperties
*/
public function has(): bool
{
if (getenv('APP_ENV') == 'testing') {
if (getenv('APP_ENV') === 'testing') {
return false;
}
$this->md5();
@@ -119,8 +118,6 @@ class CacheProperties
$this->md5 .= json_encode($property);
}
Log::debug(sprintf('Cache string is %s', $this->md5));
$this->md5 = md5($this->md5);
Log::debug(sprintf('Cache MD5 is %s', $this->md5));
}
}

View File

@@ -92,7 +92,9 @@ class Map implements ConfigurationInterface
}
foreach ($this->data as $index => $entry) {
$this->data[$index]['values'] = array_unique($this->data[$index]['values']);
asort($this->data[$index]['values']);
}
// save number of rows, thus number of steps, in job:
$steps = $rowIndex * 5;
$extended = $this->job->extended_status;

View File

@@ -135,7 +135,7 @@ class Roles implements ConfigurationInterface
$count = $config['column-count'];
for ($i = 0; $i < $count; $i++) {
$role = $config['column-roles'][$i] ?? '_ignore';
$mapping = $config['column-do-mapping'][$i] ?? false;
$mapping = $config['column-do-mapping'][$i] ?? false;
if ($role === '_ignore' && $mapping === true) {
$mapping = false;
@@ -160,7 +160,7 @@ class Roles implements ConfigurationInterface
$count = $config['column-count'];
$toBeMapped = 0;
for ($i = 0; $i < $count; $i++) {
$mapping = $config['column-do-mapping'][$i] ?? false;
$mapping = $config['column-do-mapping'][$i] ?? false;
if ($mapping === true) {
$toBeMapped++;
}

View File

@@ -96,7 +96,7 @@ class Navigation
// if the range is custom, the end of the period
// is another X days (x is the difference between start)
// and end added to $theCurrentEnd
if ($repeatFreq == 'custom') {
if ($repeatFreq === 'custom') {
/** @var Carbon $tStart */
$tStart = session('start', Carbon::now()->startOfMonth());
/** @var Carbon $tEnd */
@@ -393,7 +393,7 @@ class Navigation
return $date;
}
if ($repeatFreq == 'half-year' || $repeatFreq == '6M') {
if ($repeatFreq === 'half-year' || $repeatFreq === '6M') {
$month = $date->month;
$date->startOfYear();
if ($month >= 7) {
@@ -496,7 +496,7 @@ class Navigation
return $end;
}
if ($range == '6M') {
if ($range === '6M') {
if ($start->month >= 7) {
$end->endOfYear();
@@ -532,7 +532,7 @@ class Navigation
return $start;
}
if ($range == '6M') {
if ($range === '6M') {
if ($start->month >= 7) {
$start->startOfYear()->addMonths(6);

View File

@@ -86,17 +86,17 @@ class Modifier
case 'date':
case 'on':
$res = self::sameDate($transaction->date, $modifier['value']);
Log::debug(sprintf('Date is %s? %s', $modifier['value'], var_export($res, true)));
Log::debug(sprintf('Date same as %s? %s', $modifier['value'], var_export($res, true)));
break;
case 'date_before':
case 'before':
$res = self::dateBefore($transaction->date, $modifier['value']);
Log::debug(sprintf('Date is %s? %s', $modifier['value'], var_export($res, true)));
Log::debug(sprintf('Date before %s? %s', $modifier['value'], var_export($res, true)));
break;
case 'date_after':
case 'after':
$res = self::dateAfter($transaction->date, $modifier['value']);
Log::debug(sprintf('Date is %s? %s', $modifier['value'], var_export($res, true)));
Log::debug(sprintf('Date before %s? %s', $modifier['value'], var_export($res, true)));
break;
}

View File

@@ -17,11 +17,6 @@ namespace FireflyIII\Support\Search;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\User;
use Illuminate\Support\Collection;
@@ -98,112 +93,20 @@ class Search implements SearchInterface
}
}
/**
* @return Collection
*/
public function searchAccounts(): Collection
{
$words = $this->words;
$accounts = $this->user->accounts()
->accountTypeIn([AccountType::DEFAULT, AccountType::ASSET, AccountType::EXPENSE, AccountType::REVENUE, AccountType::BENEFICIARY])
->get(['accounts.*']);
/** @var Collection $result */
$result = $accounts->filter(
function (Account $account) use ($words) {
if ($this->strpos_arr(strtolower($account->name), $words)) {
return $account;
}
return false;
}
);
$result = $result->slice(0, $this->limit);
return $result;
}
/**
* @return Collection
*/
public function searchBudgets(): Collection
{
/** @var Collection $set */
$set = auth()->user()->budgets()->get();
$words = $this->words;
/** @var Collection $result */
$result = $set->filter(
function (Budget $budget) use ($words) {
if ($this->strpos_arr(strtolower($budget->name), $words)) {
return $budget;
}
return false;
}
);
$result = $result->slice(0, $this->limit);
return $result;
}
/**
* @return Collection
*/
public function searchCategories(): Collection
{
$words = $this->words;
$categories = $this->user->categories()->get();
/** @var Collection $result */
$result = $categories->filter(
function (Category $category) use ($words) {
if ($this->strpos_arr(strtolower($category->name), $words)) {
return $category;
}
return false;
}
);
$result = $result->slice(0, $this->limit);
return $result;
}
/**
* @return Collection
*/
public function searchTags(): Collection
{
$words = $this->words;
$tags = $this->user->tags()->get();
/** @var Collection $result */
$result = $tags->filter(
function (Tag $tag) use ($words) {
if ($this->strpos_arr(strtolower($tag->tag), $words)) {
return $tag;
}
return false;
}
);
$result = $result->slice(0, $this->limit);
return $result;
}
/**
* @return Collection
*/
public function searchTransactions(): Collection
{
Log::debug('Start of searchTransactions()');
$pageSize = 100;
$processed = 0;
$page = 1;
$result = new Collection();
$startTime = microtime(true);
do {
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setUser($this->user);
$collector->setAllAssetAccounts()->setLimit($pageSize)->setPage($page);
if ($this->hasModifiers()) {
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
@@ -247,7 +150,11 @@ class Search implements SearchInterface
Log::debug(sprintf('reachedEndOfList: %s', var_export($reachedEndOfList, true)));
Log::debug(sprintf('foundEnough: %s', var_export($foundEnough, true)));
} while (!$reachedEndOfList && !$foundEnough);
// break at some point so the script does not crash:
$currentTime = microtime(true) - $startTime;
Log::debug(sprintf('Have been running for %f seconds.', $currentTime));
} while (!$reachedEndOfList && !$foundEnough && $currentTime <= 30);
$result = $result->slice(0, $this->limit);

View File

@@ -38,25 +38,6 @@ interface SearchInterface
*/
public function parseQuery(string $query);
/**
* @return Collection
*/
public function searchAccounts(): Collection;
/**
* @return Collection
*/
public function searchBudgets(): Collection;
/**
* @return Collection
*/
public function searchCategories(): Collection;
/**
* @return Collection
*/
public function searchTags(): Collection;
/**
* @return Collection

View File

@@ -19,6 +19,7 @@ use Crypt;
use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Collection;
/**
@@ -345,4 +346,20 @@ class Steam
return $amount;
}
/**
* @param $value
*
* @return mixed
*/
public function tryDecrypt($value)
{
try {
$value = Crypt::decrypt($value);
} catch (DecryptException $e) {
// do not care.
}
return $value;
}
}

View File

@@ -110,7 +110,7 @@ class General extends Twig_Extension
$what = $args[2]; // name of the route.
$activeWhat = $context['what'] ?? false;
if ($what == $activeWhat && !(strpos(Route::getCurrentRoute()->getName(), $route) === false)) {
if ($what === $activeWhat && !(strpos(Route::getCurrentRoute()->getName(), $route) === false)) {
return 'active';
}
@@ -132,7 +132,7 @@ class General extends Twig_Extension
$args = func_get_args();
$route = $args[0]; // name of the route.
if (Route::getCurrentRoute()->getName() == $route) {
if (Route::getCurrentRoute()->getName() === $route) {
return 'active';
}

View File

@@ -51,7 +51,7 @@ class Journal extends Twig_Extension
$array = [];
/** @var Account $entry */
foreach ($list as $entry) {
if ($entry->accountType->type == AccountType::CASH) {
if ($entry->accountType->type === AccountType::CASH) {
$array[] = '<span class="text-success">(cash)</span>';
continue;
}
@@ -123,7 +123,7 @@ class Journal extends Twig_Extension
$array = [];
/** @var Account $entry */
foreach ($list as $entry) {
if ($entry->accountType->type == 'Cash account') {
if ($entry->accountType->type === AccountType::CASH) {
$array[] = '<span class="text-success">(cash)</span>';
continue;
}

View File

@@ -70,7 +70,7 @@ class Rule extends Twig_Extension
$ruleTriggers = array_keys(Config::get('firefly.rule-triggers'));
$possibleTriggers = [];
foreach ($ruleTriggers as $key) {
if ($key != 'user_action') {
if ($key !== 'user_action') {
$possibleTriggers[$key] = trans('firefly.rule_trigger_' . $key . '_choice');
}
}