mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-11 09:29:34 +00:00
Fix code quality with rector [skip ci]
This commit is contained in:
@@ -224,7 +224,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $set->each(
|
||||
static function (Attachment $attachment) use ($disk) { // @phpstan-ignore-line
|
||||
static function (Attachment $attachment) use ($disk): Attachment { // @phpstan-ignore-line
|
||||
$notes = $attachment->notes()->first();
|
||||
$attachment->file_exists = $disk->exists($attachment->fileName());
|
||||
$attachment->notes_text = null !== $notes ? $notes->text : '';
|
||||
@@ -414,7 +414,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
|
||||
public function getMetaValue(Account $account, string $field): ?string
|
||||
{
|
||||
$result = $account->accountMeta->filter(
|
||||
static fn (AccountMeta $meta) => strtolower($meta->name) === strtolower($field)
|
||||
static fn (AccountMeta $meta): bool => strtolower($meta->name) === strtolower($field)
|
||||
);
|
||||
if (0 === $result->count()) {
|
||||
return null;
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\Attachment;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\AttachmentFactory;
|
||||
@@ -78,7 +79,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface, UserGroupIn
|
||||
try {
|
||||
$unencryptedContent = Crypt::decrypt($encryptedContent); // verified
|
||||
} catch (DecryptException $e) {
|
||||
app('log')->debug(sprintf('Could not decrypt attachment #%d but this is fine: %s', $attachment->id, $e->getMessage()));
|
||||
Log::debug(sprintf('Could not decrypt attachment #%d but this is fine: %s', $attachment->id, $e->getMessage()));
|
||||
$unencryptedContent = $encryptedContent;
|
||||
}
|
||||
}
|
||||
@@ -161,7 +162,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface, UserGroupIn
|
||||
try {
|
||||
$dbNote->delete();
|
||||
} catch (LogicException $e) {
|
||||
app('log')->error($e->getMessage());
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
|
||||
if (null !== $billId) {
|
||||
$searchResult = $this->find($billId);
|
||||
if ($searchResult instanceof Bill) {
|
||||
app('log')->debug(sprintf('Found bill based on #%d, will return it.', $billId));
|
||||
Log::debug(sprintf('Found bill based on #%d, will return it.', $billId));
|
||||
|
||||
return $searchResult;
|
||||
}
|
||||
@@ -129,12 +129,12 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
|
||||
if (null !== $billName) {
|
||||
$searchResult = $this->findByName($billName);
|
||||
if ($searchResult instanceof Bill) {
|
||||
app('log')->debug(sprintf('Found bill based on "%s", will return it.', $billName));
|
||||
Log::debug(sprintf('Found bill based on "%s", will return it.', $billName));
|
||||
|
||||
return $searchResult;
|
||||
}
|
||||
}
|
||||
app('log')->debug('Found no bill in findBill()');
|
||||
Log::debug('Found no bill in findBill()');
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $set->each(
|
||||
static function (Attachment $attachment) use ($disk) { // @phpstan-ignore-line
|
||||
static function (Attachment $attachment) use ($disk): Attachment { // @phpstan-ignore-line
|
||||
$notes = $attachment->notes()->first();
|
||||
$attachment->file_exists = $disk->exists($attachment->fileName());
|
||||
$attachment->notes_text = null !== $notes ? $notes->text : '';
|
||||
@@ -307,7 +307,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
|
||||
*/
|
||||
public function getPaidDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
// app('log')->debug('Now in getPaidDatesInRange()');
|
||||
// \Illuminate\Support\Facades\Log::debug('Now in getPaidDatesInRange()');
|
||||
|
||||
Log::debug(sprintf('Search for linked journals between %s and %s', $start->toW3cString(), $end->toW3cString()));
|
||||
|
||||
@@ -440,7 +440,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
|
||||
$journal = $bill->user->transactionJournals()->find((int) $transaction['transaction_journal_id']);
|
||||
$journal->bill_id = $bill->id;
|
||||
$journal->save();
|
||||
app('log')->debug(sprintf('Linked journal #%d to bill #%d', $journal->id, $bill->id));
|
||||
Log::debug(sprintf('Linked journal #%d to bill #%d', $journal->id, $bill->id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,12 +459,12 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
|
||||
// find the most recent date for this bill NOT in the future. Cache this date:
|
||||
$start = clone $bill->date;
|
||||
$start->startOfDay();
|
||||
app('log')->debug('nextExpectedMatch: Start is '.$start->format('Y-m-d'));
|
||||
Log::debug('nextExpectedMatch: Start is '.$start->format('Y-m-d'));
|
||||
|
||||
while ($start < $date) {
|
||||
app('log')->debug(sprintf('$start (%s) < $date (%s)', $start->format('Y-m-d H:i:s'), $date->format('Y-m-d H:i:s')));
|
||||
Log::debug(sprintf('$start (%s) < $date (%s)', $start->format('Y-m-d H:i:s'), $date->format('Y-m-d H:i:s')));
|
||||
$start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
app('log')->debug('Start is now '.$start->format('Y-m-d H:i:s'));
|
||||
Log::debug('Start is now '.$start->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
@@ -475,12 +475,12 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
|
||||
|
||||
if ($journalCount > 0) {
|
||||
// this period had in fact a bill. The new start is the current end, and we create a new end.
|
||||
app('log')->debug(sprintf('Journal count is %d, so start becomes %s', $journalCount, $end->format('Y-m-d')));
|
||||
Log::debug(sprintf('Journal count is %d, so start becomes %s', $journalCount, $end->format('Y-m-d')));
|
||||
$start = clone $end;
|
||||
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
}
|
||||
app('log')->debug('nextExpectedMatch: Final start is '.$start->format('Y-m-d'));
|
||||
app('log')->debug('nextExpectedMatch: Matching end is '.$end->format('Y-m-d'));
|
||||
Log::debug('nextExpectedMatch: Final start is '.$start->format('Y-m-d'));
|
||||
Log::debug('nextExpectedMatch: Matching end is '.$end->format('Y-m-d'));
|
||||
|
||||
$cache->store($start);
|
||||
|
||||
@@ -597,7 +597,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
|
||||
|
||||
public function sumUnpaidInRange(Carbon $start, Carbon $end): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in sumUnpaidInRange("%s", "%s")', $start->format('Y-m-d'), $end->format('Y-m-d')));
|
||||
Log::debug(sprintf('Now in sumUnpaidInRange("%s", "%s")', $start->format('Y-m-d'), $end->format('Y-m-d')));
|
||||
$bills = $this->getActiveBills();
|
||||
$return = [];
|
||||
$convertToPrimary = Amount::convertToPrimary($this->user);
|
||||
@@ -605,12 +605,12 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
|
||||
|
||||
/** @var Bill $bill */
|
||||
foreach ($bills as $bill) {
|
||||
// app('log')->debug(sprintf('Processing bill #%d ("%s")', $bill->id, $bill->name));
|
||||
// \Illuminate\Support\Facades\Log::debug(sprintf('Processing bill #%d ("%s")', $bill->id, $bill->name));
|
||||
$dates = $this->getPayDatesInRange($bill, $start, $end);
|
||||
$count = $bill->transactionJournals()->after($start)->before($end)->count();
|
||||
$total = $dates->count() - $count;
|
||||
// app('log')->debug(sprintf('Pay dates: %d, count: %d, left: %d', $dates->count(), $count, $total));
|
||||
// app('log')->debug('dates', $dates->toArray());
|
||||
// \Illuminate\Support\Facades\Log::debug(sprintf('Pay dates: %d, count: %d, left: %d', $dates->count(), $count, $total));
|
||||
// \Illuminate\Support\Facades\Log::debug('dates', $dates->toArray());
|
||||
|
||||
$minField = $convertToPrimary && $bill->transactionCurrency->id !== $primary->id ? 'native_amount_min' : 'amount_min';
|
||||
$maxField = $convertToPrimary && $bill->transactionCurrency->id !== $primary->id ? 'native_amount_max' : 'amount_max';
|
||||
@@ -642,21 +642,21 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
|
||||
{
|
||||
$set = new Collection();
|
||||
$currentStart = clone $start;
|
||||
// app('log')->debug(sprintf('Now at bill "%s" (%s)', $bill->name, $bill->repeat_freq));
|
||||
// app('log')->debug(sprintf('First currentstart is %s', $currentStart->format('Y-m-d')));
|
||||
// \Illuminate\Support\Facades\Log::debug(sprintf('Now at bill "%s" (%s)', $bill->name, $bill->repeat_freq));
|
||||
// \Illuminate\Support\Facades\Log::debug(sprintf('First currentstart is %s', $currentStart->format('Y-m-d')));
|
||||
|
||||
while ($currentStart <= $end) {
|
||||
// app('log')->debug(sprintf('Currentstart is now %s.', $currentStart->format('Y-m-d')));
|
||||
// \Illuminate\Support\Facades\Log::debug(sprintf('Currentstart is now %s.', $currentStart->format('Y-m-d')));
|
||||
$nextExpectedMatch = $this->nextDateMatch($bill, $currentStart);
|
||||
// app('log')->debug(sprintf('Next Date match after %s is %s', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
|
||||
// \Illuminate\Support\Facades\Log::debug(sprintf('Next Date match after %s is %s', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
|
||||
if ($nextExpectedMatch > $end) {// If nextExpectedMatch is after end, we continue
|
||||
break;
|
||||
}
|
||||
$set->push(clone $nextExpectedMatch);
|
||||
// app('log')->debug(sprintf('Now %d dates in set.', $set->count()));
|
||||
// \Illuminate\Support\Facades\Log::debug(sprintf('Now %d dates in set.', $set->count()));
|
||||
$nextExpectedMatch->addDay();
|
||||
|
||||
// app('log')->debug(sprintf('Currentstart (%s) has become %s.', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
|
||||
// \Illuminate\Support\Facades\Log::debug(sprintf('Currentstart (%s) has become %s.', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
|
||||
|
||||
$currentStart = clone $nextExpectedMatch;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
|
||||
$end = $availableBudget->end_date->format('Y-m-d');
|
||||
$key = sprintf('%s-%s-%s', $availableBudget->transaction_currency_id, $start, $end);
|
||||
if (array_key_exists($key, $exists)) {
|
||||
app('log')->debug(sprintf('Found duplicate AB: %s %s, %s-%s. Has been deleted', $availableBudget->transaction_currency_id, $availableBudget->amount, $start, $end));
|
||||
Log::debug(sprintf('Found duplicate AB: %s %s, %s-%s. Has been deleted', $availableBudget->transaction_currency_id, $availableBudget->amount, $start, $end));
|
||||
$availableBudget->delete();
|
||||
}
|
||||
$exists[$key] = true;
|
||||
|
||||
@@ -130,7 +130,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
|
||||
public function getAllBudgetLimitsByCurrency(TransactionCurrency $currency, ?Carbon $start = null, ?Carbon $end = null): Collection
|
||||
{
|
||||
return $this->getAllBudgetLimits($start, $end)->filter(
|
||||
static fn (BudgetLimit $budgetLimit) => $budgetLimit->transaction_currency_id === $currency->id
|
||||
static fn (BudgetLimit $budgetLimit): bool => $budgetLimit->transaction_currency_id === $currency->id
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -307,7 +307,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
$autoBudget = $this->getAutoBudget($budget);
|
||||
|
||||
// first things first: delete when no longer required:
|
||||
$autoBudgetType = array_key_exists('auto_budget_type', $data) ? $data['auto_budget_type'] : null;
|
||||
$autoBudgetType = $data['auto_budget_type'] ?? null;
|
||||
|
||||
if (0 === $autoBudgetType && $autoBudget instanceof AutoBudget) {
|
||||
// delete!
|
||||
@@ -534,7 +534,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $set->each(
|
||||
static function (Attachment $attachment) use ($disk) { // @phpstan-ignore-line
|
||||
static function (Attachment $attachment) use ($disk): Attachment { // @phpstan-ignore-line
|
||||
$notes = $attachment->notes()->first();
|
||||
$attachment->file_exists = $disk->exists($attachment->fileName());
|
||||
$attachment->notes_text = null !== $notes ? $notes->text : '';
|
||||
|
||||
@@ -54,7 +54,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
|
||||
*/
|
||||
public function budgetedPerDay(Budget $budget): string
|
||||
{
|
||||
app('log')->debug(sprintf('Now with budget #%d "%s"', $budget->id, $budget->name));
|
||||
Log::debug(sprintf('Now with budget #%d "%s"', $budget->id, $budget->name));
|
||||
$total = '0';
|
||||
$count = 0;
|
||||
foreach ($budget->budgetlimits as $limit) {
|
||||
@@ -64,13 +64,13 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
|
||||
$perDay = bcdiv((string) $amount, (string) $diff);
|
||||
$total = bcadd($total, $perDay);
|
||||
++$count;
|
||||
app('log')->debug(sprintf('Found %d budget limits. Per day is %s, total is %s', $count, $perDay, $total));
|
||||
Log::debug(sprintf('Found %d budget limits. Per day is %s, total is %s', $count, $perDay, $total));
|
||||
}
|
||||
$avg = $total;
|
||||
if ($count > 0) {
|
||||
$avg = bcdiv($total, (string) $count);
|
||||
}
|
||||
app('log')->debug(sprintf('%s / %d = %s = average.', $total, $count, $avg));
|
||||
Log::debug(sprintf('%s / %d = %s = average.', $total, $count, $avg));
|
||||
|
||||
return $avg;
|
||||
}
|
||||
|
||||
@@ -108,11 +108,11 @@ class CategoryRepository implements CategoryRepositoryInterface, UserGroupInterf
|
||||
*/
|
||||
public function findCategory(?int $categoryId, ?string $categoryName): ?Category
|
||||
{
|
||||
app('log')->debug('Now in findCategory()');
|
||||
app('log')->debug(sprintf('Searching for category with ID #%d...', $categoryId));
|
||||
Log::debug('Now in findCategory()');
|
||||
Log::debug(sprintf('Searching for category with ID #%d...', $categoryId));
|
||||
$result = $this->find((int) $categoryId);
|
||||
if (!$result instanceof Category) {
|
||||
app('log')->debug(sprintf('Searching for category with name %s...', $categoryName));
|
||||
Log::debug(sprintf('Searching for category with name %s...', $categoryName));
|
||||
$result = $this->findByName((string) $categoryName);
|
||||
if (!$result instanceof Category && '' !== (string) $categoryName) {
|
||||
// create it!
|
||||
@@ -120,9 +120,9 @@ class CategoryRepository implements CategoryRepositoryInterface, UserGroupInterf
|
||||
}
|
||||
}
|
||||
if ($result instanceof Category) {
|
||||
app('log')->debug(sprintf('Found category #%d: %s', $result->id, $result->name));
|
||||
Log::debug(sprintf('Found category #%d: %s', $result->id, $result->name));
|
||||
}
|
||||
app('log')->debug(sprintf('Found category result is null? %s', var_export(!$result instanceof Category, true)));
|
||||
Log::debug(sprintf('Found category result is null? %s', var_export(!$result instanceof Category, true)));
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -240,7 +240,7 @@ class CategoryRepository implements CategoryRepositoryInterface, UserGroupInterf
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $set->each(
|
||||
static function (Attachment $attachment) use ($disk) { // @phpstan-ignore-line
|
||||
static function (Attachment $attachment) use ($disk): Attachment { // @phpstan-ignore-line
|
||||
$notes = $attachment->notes()->first();
|
||||
$attachment->file_exists = $disk->exists($attachment->fileName());
|
||||
$attachment->notes_text = null !== $notes ? $notes->text : '';
|
||||
|
||||
@@ -183,9 +183,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
|
||||
$all = TransactionCurrency::orderBy('code', 'ASC')->get();
|
||||
$local = $this->get();
|
||||
|
||||
return $all->map(static function (TransactionCurrency $current) use ($local) {
|
||||
$hasId = $local->contains(static fn (TransactionCurrency $entry) => $entry->id === $current->id);
|
||||
$isPrimary = $local->contains(static fn (TransactionCurrency $entry) => 1 === (int)$entry->pivot->group_default && $entry->id === $current->id);
|
||||
return $all->map(static function (TransactionCurrency $current) use ($local): TransactionCurrency {
|
||||
$hasId = $local->contains(static fn (TransactionCurrency $entry): bool => $entry->id === $current->id);
|
||||
$isPrimary = $local->contains(static fn (TransactionCurrency $entry): bool => 1 === (int)$entry->pivot->group_default && $entry->id === $current->id);
|
||||
$current->userGroupEnabled = $hasId;
|
||||
$current->userGroupNative = $isPrimary;
|
||||
|
||||
@@ -196,14 +196,13 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
|
||||
public function get(): Collection
|
||||
{
|
||||
$all = $this->userGroup->currencies()->orderBy('code', 'ASC')->withPivot(['group_default'])->get();
|
||||
$all->map(static function (TransactionCurrency $current) { // @phpstan-ignore-line
|
||||
$all->map(static function (TransactionCurrency $current): TransactionCurrency { // @phpstan-ignore-line
|
||||
$current->userGroupEnabled = true;
|
||||
$current->userGroupNative = 1 === (int)$current->pivot->group_default;
|
||||
|
||||
return $current;
|
||||
});
|
||||
|
||||
/** @var Collection */
|
||||
return $all;
|
||||
}
|
||||
|
||||
@@ -402,7 +401,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
|
||||
{
|
||||
Log::debug('Now in update()');
|
||||
// can be true, false, null
|
||||
$enabled = array_key_exists('enabled', $data) ? $data['enabled'] : null;
|
||||
$enabled = $data['enabled'] ?? null;
|
||||
// can be true, false, but method only responds to "true".
|
||||
$default = array_key_exists('default', $data) ? $data['default'] : false;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface, UserGroupIn
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $set->each(
|
||||
static function (Attachment $attachment) use ($disk) {
|
||||
static function (Attachment $attachment) use ($disk): Attachment {
|
||||
$notes = $attachment->notes()->first();
|
||||
$attachment->file_exists = $disk->exists($attachment->fileName());
|
||||
$attachment->notes_text = null !== $notes ? $notes->text : ''; // TODO should not set notes like this.
|
||||
|
||||
@@ -78,11 +78,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
{
|
||||
/** @var null|TransactionJournal $entry */
|
||||
$entry = $this->user->transactionJournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
|
||||
if (null !== $entry) {
|
||||
return $entry;
|
||||
}
|
||||
|
||||
return null;
|
||||
return $entry;
|
||||
}
|
||||
|
||||
public function getDestinationAccount(TransactionJournal $journal): Account
|
||||
@@ -120,11 +116,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
{
|
||||
/** @var null|TransactionJournal $entry */
|
||||
$entry = $this->user->transactionJournals()->orderBy('date', 'DESC')->first(['transaction_journals.*']);
|
||||
if (null !== $entry) {
|
||||
return $entry;
|
||||
}
|
||||
|
||||
return null;
|
||||
return $entry;
|
||||
}
|
||||
|
||||
public function getLinkNoteText(TransactionJournalLink $link): string
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\LinkType;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Exception;
|
||||
use FireflyIII\Models\LinkType;
|
||||
use FireflyIII\Models\Note;
|
||||
@@ -85,7 +86,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface, UserGroupInterf
|
||||
*/
|
||||
public function findLink(TransactionJournal $one, TransactionJournal $two): bool
|
||||
{
|
||||
app('log')->debug(sprintf('Now in findLink(%d, %d)', $one->id, $two->id));
|
||||
Log::debug(sprintf('Now in findLink(%d, %d)', $one->id, $two->id));
|
||||
$count = TransactionJournalLink::whereDestinationId($one->id)->whereSourceId($two->id)->count();
|
||||
$opposingCount = TransactionJournalLink::whereDestinationId($two->id)->whereSourceId($one->id)->count();
|
||||
|
||||
@@ -150,7 +151,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface, UserGroupInterf
|
||||
$merged = $outward->merge($inward);
|
||||
|
||||
return $merged->filter(
|
||||
static fn (TransactionJournalLink $link) => null !== $link->source && null !== $link->destination
|
||||
static fn (TransactionJournalLink $link): bool => null !== $link->source && null !== $link->destination
|
||||
);
|
||||
}
|
||||
|
||||
@@ -192,13 +193,13 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface, UserGroupInterf
|
||||
$link = new TransactionJournalLink();
|
||||
$link->linkType()->associate($linkType);
|
||||
if ('inward' === $information['direction']) {
|
||||
app('log')->debug(sprintf('Link type is inwards ("%s"), so %d is source and %d is destination.', $linkType->inward, $inward->id, $outward->id));
|
||||
Log::debug(sprintf('Link type is inwards ("%s"), so %d is source and %d is destination.', $linkType->inward, $inward->id, $outward->id));
|
||||
$link->source()->associate($inward);
|
||||
$link->destination()->associate($outward);
|
||||
}
|
||||
|
||||
if ('outward' === $information['direction']) {
|
||||
app('log')->debug(sprintf('Link type is inwards ("%s"), so %d is source and %d is destination.', $linkType->outward, $outward->id, $inward->id));
|
||||
Log::debug(sprintf('Link type is inwards ("%s"), so %d is source and %d is destination.', $linkType->outward, $outward->id, $inward->id));
|
||||
$link->source()->associate($outward);
|
||||
$link->destination()->associate($inward);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\ObjectGroup;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Models\ObjectGroup;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
|
||||
@@ -96,14 +97,14 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface, UserGroup
|
||||
|
||||
public function resetOrder(): void
|
||||
{
|
||||
app('log')->debug('Now in resetOrder');
|
||||
Log::debug('Now in resetOrder');
|
||||
$list = $this->get();
|
||||
$index = 1;
|
||||
|
||||
/** @var ObjectGroup $objectGroup */
|
||||
foreach ($list as $objectGroup) {
|
||||
if ($index !== $objectGroup->order) {
|
||||
app('log')->debug(
|
||||
Log::debug(
|
||||
sprintf('objectGroup #%d ("%s"): order should %d be but is %d.', $objectGroup->id, $objectGroup->title, $index, $objectGroup->order)
|
||||
);
|
||||
$objectGroup->order = $index;
|
||||
@@ -166,7 +167,7 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface, UserGroup
|
||||
$objectGroup->save();
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('Objectgroup #%d order is now %d', $objectGroup->id, $newOrder));
|
||||
Log::debug(sprintf('Objectgroup #%d order is now %d', $objectGroup->id, $newOrder));
|
||||
|
||||
return $objectGroup;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $set->each(
|
||||
static function (Attachment $attachment) use ($disk) { // @phpstan-ignore-line
|
||||
static function (Attachment $attachment) use ($disk): Attachment { // @phpstan-ignore-line
|
||||
$notes = $attachment->notes()->first();
|
||||
$attachment->file_exists = $disk->exists($attachment->fileName());
|
||||
$attachment->notes_text = null !== $notes ? $notes->text : '';
|
||||
|
||||
@@ -79,7 +79,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
foreach ($set as $journalMeta) {
|
||||
$count = TransactionJournalMeta::where(static function (Builder $q2) use ($date): void {
|
||||
$string = (string) $date;
|
||||
app('log')->debug(sprintf('Search for date: %s', json_encode($string)));
|
||||
Log::debug(sprintf('Search for date: %s', json_encode($string)));
|
||||
$q2->where('name', 'recurrence_date');
|
||||
$q2->where('data', json_encode($string));
|
||||
})
|
||||
@@ -87,7 +87,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
->count()
|
||||
;
|
||||
if ($count > 0) {
|
||||
app('log')->debug(sprintf('Looks like journal #%d was already created', $journalMeta->transaction_journal_id));
|
||||
Log::debug(sprintf('Looks like journal #%d was already created', $journalMeta->transaction_journal_id));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -373,7 +373,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
*/
|
||||
public function getXOccurrencesSince(RecurrenceRepetition $repetition, Carbon $date, Carbon $afterDate, int $count): array
|
||||
{
|
||||
app('log')->debug('Now in getXOccurrencesSince()');
|
||||
Log::debug('Now in getXOccurrencesSince()');
|
||||
$skipMod = $repetition->repetition_skip + 1;
|
||||
$occurrences = [];
|
||||
|
||||
@@ -433,7 +433,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
*/
|
||||
public function repetitionDescription(RecurrenceRepetition $repetition): string
|
||||
{
|
||||
app('log')->debug('Now in repetitionDescription()');
|
||||
Log::debug('Now in repetitionDescription()');
|
||||
|
||||
/** @var Preference $pref */
|
||||
$pref = app('preferences')->getForUser($this->user, 'language', config('firefly.default_language', 'en_US'));
|
||||
@@ -546,8 +546,8 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
$mutator = clone $start;
|
||||
$mutator->startOfDay();
|
||||
$skipMod = $repetition->repetition_skip + 1;
|
||||
app('log')->debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type));
|
||||
app('log')->debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
|
||||
Log::debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type));
|
||||
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
|
||||
|
||||
if ('daily' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getDailyInRange($mutator, $end, $skipMod);
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\Rule;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Rule;
|
||||
@@ -261,9 +262,9 @@ class RuleRepository implements RuleRepositoryInterface, UserGroupInterface
|
||||
|
||||
// reset order:
|
||||
$this->resetRuleOrder($ruleGroup);
|
||||
app('log')->debug('Done with resetting.');
|
||||
Log::debug('Done with resetting.');
|
||||
if (array_key_exists('order', $data)) {
|
||||
app('log')->debug(sprintf('User has submitted order %d', $data['order']));
|
||||
Log::debug(sprintf('User has submitted order %d', $data['order']));
|
||||
$this->setOrder($rule, $data['order']);
|
||||
}
|
||||
|
||||
@@ -318,7 +319,7 @@ class RuleRepository implements RuleRepositoryInterface, UserGroupInterface
|
||||
$groupId = $rule->rule_group_id;
|
||||
$maxOrder = $this->maxOrder($rule->ruleGroup);
|
||||
$newOrder = $newOrder > $maxOrder ? $maxOrder + 1 : $newOrder;
|
||||
app('log')->debug(sprintf('New order will be %d', $newOrder));
|
||||
Log::debug(sprintf('New order will be %d', $newOrder));
|
||||
|
||||
if ($newOrder > $oldOrder) {
|
||||
$this->user->rules()
|
||||
@@ -329,7 +330,7 @@ class RuleRepository implements RuleRepositoryInterface, UserGroupInterface
|
||||
->decrement('rules.order')
|
||||
;
|
||||
$rule->order = $newOrder;
|
||||
app('log')->debug(sprintf('Order of rule #%d ("%s") is now %d', $rule->id, $rule->title, $newOrder));
|
||||
Log::debug(sprintf('Order of rule #%d ("%s") is now %d', $rule->id, $rule->title, $newOrder));
|
||||
$rule->save();
|
||||
|
||||
return;
|
||||
@@ -343,7 +344,7 @@ class RuleRepository implements RuleRepositoryInterface, UserGroupInterface
|
||||
->increment('rules.order')
|
||||
;
|
||||
$rule->order = $newOrder;
|
||||
app('log')->debug(sprintf('Order of rule #%d ("%s") is now %d', $rule->id, $rule->title, $newOrder));
|
||||
Log::debug(sprintf('Order of rule #%d ("%s") is now %d', $rule->id, $rule->title, $newOrder));
|
||||
$rule->save();
|
||||
}
|
||||
|
||||
|
||||
@@ -280,11 +280,11 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
|
||||
Log::debug(sprintf('Will filter getRuleGroupsWithRules on "%s".', $filter));
|
||||
|
||||
return $groups->map(
|
||||
static function (RuleGroup $group) use ($filter) { // @phpstan-ignore-line
|
||||
static function (RuleGroup $group) use ($filter): RuleGroup { // @phpstan-ignore-line
|
||||
Log::debug(sprintf('Now filtering group #%d', $group->id));
|
||||
// filter the rules in the rule group:
|
||||
$group->rules = $group->rules->filter(
|
||||
static function (Rule $rule) use ($filter, $group) {
|
||||
static function (Rule $rule) use ($filter, $group): bool {
|
||||
Log::debug(sprintf('Now filtering rule #%d', $rule->id));
|
||||
foreach ($rule->ruleTriggers as $trigger) {
|
||||
if ('user_action' === $trigger->trigger_type && $filter === $trigger->trigger_value) {
|
||||
@@ -337,11 +337,11 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
|
||||
Log::debug(sprintf('Will filter getRuleGroupsWithRules on "%s".', $filter));
|
||||
|
||||
return $groups->map(
|
||||
static function (RuleGroup $group) use ($filter) { // @phpstan-ignore-line
|
||||
static function (RuleGroup $group) use ($filter): RuleGroup { // @phpstan-ignore-line
|
||||
Log::debug(sprintf('Now filtering group #%d', $group->id));
|
||||
// filter the rules in the rule group:
|
||||
$group->rules = $group->rules->filter(
|
||||
static function (Rule $rule) use ($filter, $group) {
|
||||
static function (Rule $rule) use ($filter, $group): bool {
|
||||
Log::debug(sprintf('Now filtering rule #%d', $rule->id));
|
||||
foreach ($rule->ruleTriggers as $trigger) {
|
||||
if ('user_action' === $trigger->trigger_type && $filter === $trigger->trigger_value) {
|
||||
|
||||
@@ -110,7 +110,6 @@ class TagRepository implements TagRepositoryInterface, UserGroupInterface
|
||||
|
||||
public function firstUseDate(Tag $tag): ?Carbon
|
||||
{
|
||||
/** @var null|Carbon */
|
||||
return $tag->transactionJournals()->orderBy('date', 'ASC')->first()?->date;
|
||||
}
|
||||
|
||||
@@ -137,13 +136,13 @@ class TagRepository implements TagRepositoryInterface, UserGroupInterface
|
||||
|
||||
// add date range (or not):
|
||||
if (null === $year) {
|
||||
app('log')->debug('Get tags without a date.');
|
||||
Log::debug('Get tags without a date.');
|
||||
$tagQuery->whereNull('tags.date');
|
||||
}
|
||||
|
||||
if (null !== $year) {
|
||||
$year = min(2038, max(1970, $year));
|
||||
app('log')->debug(sprintf('Get tags with year %s.', $year));
|
||||
Log::debug(sprintf('Get tags with year %s.', $year));
|
||||
$tagQuery->where('tags.date', '>=', sprintf('%d-01-01 00:00:00', $year))->where('tags.date', '<=', sprintf('%d-12-31 23:59:59', $year));
|
||||
}
|
||||
$collection = $tagQuery->get();
|
||||
@@ -177,7 +176,6 @@ class TagRepository implements TagRepositoryInterface, UserGroupInterface
|
||||
|
||||
public function lastUseDate(Tag $tag): ?Carbon
|
||||
{
|
||||
/** @var null|Carbon */
|
||||
return $tag->transactionJournals()->orderBy('date', 'DESC')->first()?->date;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\TransactionGroup;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
@@ -78,7 +79,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
|
||||
public function destroy(TransactionGroup $group): void
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||
$service = new TransactionGroupDestroyService();
|
||||
$service->destroy($group);
|
||||
}
|
||||
@@ -406,13 +407,13 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
try {
|
||||
return $factory->create($data);
|
||||
} catch (DuplicateTransactionException $e) {
|
||||
app('log')->warning('Group repository caught group factory with a duplicate exception!');
|
||||
Log::warning('Group repository caught group factory with a duplicate exception!');
|
||||
|
||||
throw new DuplicateTransactionException($e->getMessage(), 0, $e);
|
||||
} catch (FireflyException $e) {
|
||||
app('log')->warning('Group repository caught group factory with an exception!');
|
||||
app('log')->error($e->getMessage());
|
||||
app('log')->error($e->getTraceAsString());
|
||||
Log::warning('Group repository caught group factory with an exception!');
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
throw new FireflyException($e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\TransactionType;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -35,9 +36,9 @@ class TransactionTypeRepository implements TransactionTypeRepositoryInterface
|
||||
{
|
||||
public function findTransactionType(?TransactionType $type, ?string $typeString): TransactionType
|
||||
{
|
||||
app('log')->debug('Now looking for a transaction type.');
|
||||
Log::debug('Now looking for a transaction type.');
|
||||
if ($type instanceof TransactionType) {
|
||||
app('log')->debug(sprintf('Found $type in parameters, its %s. Will return it.', $type->type));
|
||||
Log::debug(sprintf('Found $type in parameters, its %s. Will return it.', $type->type));
|
||||
|
||||
return $type;
|
||||
}
|
||||
@@ -46,7 +47,7 @@ class TransactionTypeRepository implements TransactionTypeRepositoryInterface
|
||||
if (!$search instanceof TransactionType) {
|
||||
$search = $this->findByType(TransactionTypeEnum::WITHDRAWAL->value);
|
||||
}
|
||||
app('log')->debug(sprintf('Tried to search for "%s", came up with "%s". Will return it.', $typeString, $search->type));
|
||||
Log::debug(sprintf('Tried to search for "%s", came up with "%s". Will return it.', $typeString, $search->type));
|
||||
|
||||
return $search;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\User;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -97,7 +98,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
|
||||
public function deleteInvite(InvitedUser $invite): void
|
||||
{
|
||||
app('log')->debug(sprintf('Deleting invite #%d', $invite->id));
|
||||
Log::debug(sprintf('Deleting invite #%d', $invite->id));
|
||||
$invite->delete();
|
||||
}
|
||||
|
||||
@@ -106,7 +107,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
*/
|
||||
public function destroy(User $user): bool
|
||||
{
|
||||
app('log')->debug(sprintf('Calling delete() on user %d', $user->id));
|
||||
Log::debug(sprintf('Calling delete() on user %d', $user->id));
|
||||
|
||||
$user->groupMemberships()->delete();
|
||||
$user->delete();
|
||||
@@ -123,7 +124,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
foreach ($groups as $group) {
|
||||
$count = $group->groupMemberships()->count();
|
||||
if (0 === $count) {
|
||||
app('log')->info(sprintf('Deleted empty group #%d ("%s")', $group->id, $group->title));
|
||||
Log::info(sprintf('Deleted empty group #%d ("%s")', $group->id, $group->title));
|
||||
$group->delete();
|
||||
}
|
||||
}
|
||||
@@ -198,33 +199,12 @@ class UserRepository implements UserRepositoryInterface
|
||||
*/
|
||||
public function getUserData(User $user): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
// two factor:
|
||||
$return['has_2fa'] = null !== $user->mfa_secret;
|
||||
$return['is_admin'] = $this->hasRole($user, 'owner');
|
||||
$return['blocked'] = 1 === (int) $user->blocked;
|
||||
$return['blocked_code'] = $user->blocked_code;
|
||||
$return['accounts'] = $user->accounts()->count();
|
||||
$return['journals'] = $user->transactionJournals()->count();
|
||||
$return['transactions'] = $user->transactions()->count();
|
||||
$return['attachments'] = $user->attachments()->count();
|
||||
$return['attachments_size'] = $user->attachments()->sum('size');
|
||||
$return['bills'] = $user->bills()->count();
|
||||
$return['categories'] = $user->categories()->count();
|
||||
$return['budgets'] = $user->budgets()->count();
|
||||
$return['budgets_with_limits'] = BudgetLimit::distinct()
|
||||
return ['has_2fa' => null !== $user->mfa_secret, 'is_admin' => $this->hasRole($user, 'owner'), 'blocked' => 1 === (int) $user->blocked, 'blocked_code' => $user->blocked_code, 'accounts' => $user->accounts()->count(), 'journals' => $user->transactionJournals()->count(), 'transactions' => $user->transactions()->count(), 'attachments' => $user->attachments()->count(), 'attachments_size' => $user->attachments()->sum('size'), 'bills' => $user->bills()->count(), 'categories' => $user->categories()->count(), 'budgets' => $user->budgets()->count(), 'budgets_with_limits' => BudgetLimit::distinct()
|
||||
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||
->where('amount', '>', 0)
|
||||
->whereNull('budgets.deleted_at')
|
||||
->where('budgets.user_id', $user->id)
|
||||
->count('budget_limits.budget_id')
|
||||
;
|
||||
$return['rule_groups'] = $user->ruleGroups()->count();
|
||||
$return['rules'] = $user->rules()->count();
|
||||
$return['tags'] = $user->tags()->count();
|
||||
|
||||
return $return;
|
||||
->count('budget_limits.budget_id'), 'rule_groups' => $user->ruleGroups()->count(), 'rules' => $user->rules()->count(), 'tags' => $user->tags()->count()];
|
||||
}
|
||||
|
||||
public function hasRole(Authenticatable|User|null $user, string $role): bool
|
||||
@@ -327,7 +307,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
{
|
||||
$roleObject = Role::where('name', $role)->first();
|
||||
if (null === $roleObject) {
|
||||
app('log')->error(sprintf('Could not find role "%s" in attachRole()', $role));
|
||||
Log::error(sprintf('Could not find role "%s" in attachRole()', $role));
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -336,7 +316,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
$user->roles()->attach($roleObject);
|
||||
} catch (QueryException $e) {
|
||||
// don't care
|
||||
app('log')->error(sprintf('Query exception when giving user a role: %s', $e->getMessage()));
|
||||
Log::error(sprintf('Query exception when giving user a role: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\UserGroup;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\UserRoleEnum;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\UserGroupFactory;
|
||||
@@ -47,7 +48,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
|
||||
public function destroy(UserGroup $userGroup): void
|
||||
{
|
||||
app('log')->debug(sprintf('Going to destroy user group #%d ("%s").', $userGroup->id, $userGroup->title));
|
||||
Log::debug(sprintf('Going to destroy user group #%d ("%s").', $userGroup->id, $userGroup->title));
|
||||
$memberships = $userGroup->groupMemberships()->get();
|
||||
|
||||
/** @var GroupMembership $membership */
|
||||
@@ -57,19 +58,19 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
if (null === $user) {
|
||||
continue;
|
||||
}
|
||||
app('log')->debug(sprintf('Processing membership #%d (user #%d "%s")', $membership->id, $user->id, $user->email));
|
||||
Log::debug(sprintf('Processing membership #%d (user #%d "%s")', $membership->id, $user->id, $user->email));
|
||||
// user has memberships of other groups?
|
||||
$count = $user->groupMemberships()->where('user_group_id', '!=', $userGroup->id)->count();
|
||||
if (0 === $count) {
|
||||
app('log')->debug('User has no other memberships and needs a new user group.');
|
||||
Log::debug('User has no other memberships and needs a new user group.');
|
||||
$newUserGroup = $this->createNewUserGroup($user);
|
||||
$user->user_group_id = $newUserGroup->id;
|
||||
$user->save();
|
||||
app('log')->debug(sprintf('Make new group #%d ("%s")', $newUserGroup->id, $newUserGroup->title));
|
||||
Log::debug(sprintf('Make new group #%d ("%s")', $newUserGroup->id, $newUserGroup->title));
|
||||
}
|
||||
// user has other memberships, select one at random and assign it to the user.
|
||||
if ($count > 0) {
|
||||
app('log')->debug('User has other memberships and will be assigned a new administration.');
|
||||
Log::debug('User has other memberships and will be assigned a new administration.');
|
||||
|
||||
/** @var GroupMembership $first */
|
||||
$first = $user->groupMemberships()->where('user_group_id', '!=', $userGroup->id)->inRandomOrder()->first();
|
||||
@@ -91,7 +92,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
}
|
||||
}
|
||||
$userGroup->delete();
|
||||
app('log')->debug('Done!');
|
||||
Log::debug('Done!');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,23 +217,23 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
public function updateMembership(UserGroup $userGroup, array $data): UserGroup
|
||||
{
|
||||
$owner = UserRole::whereTitle(UserRoleEnum::OWNER)->first();
|
||||
app('log')->debug('in update membership');
|
||||
Log::debug('in update membership');
|
||||
|
||||
/** @var null|User $user */
|
||||
$user = null;
|
||||
if (array_key_exists('id', $data)) {
|
||||
/** @var null|User $user */
|
||||
$user = User::find($data['id']);
|
||||
app('log')->debug('Found user by ID');
|
||||
Log::debug('Found user by ID');
|
||||
}
|
||||
if (array_key_exists('email', $data) && '' !== (string)$data['email']) {
|
||||
/** @var null|User $user */
|
||||
$user = User::whereEmail($data['email'])->first();
|
||||
app('log')->debug('Found user by email');
|
||||
Log::debug('Found user by email');
|
||||
}
|
||||
if (null === $user) {
|
||||
// should throw error, but validator already catches this.
|
||||
app('log')->debug('No user found');
|
||||
Log::debug('No user found');
|
||||
|
||||
return $userGroup;
|
||||
}
|
||||
@@ -244,13 +245,13 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
$lastUserId = $userGroup->groupMemberships()->distinct()->first(['group_memberships.user_id'])->user_id;
|
||||
// if this is also the user we're editing right now, and we remove all of their roles:
|
||||
if ($lastUserId === (int)$user->id && 0 === count($data['roles'])) {
|
||||
app('log')->debug('User is last in this group, refuse to act');
|
||||
Log::debug('User is last in this group, refuse to act');
|
||||
|
||||
throw new FireflyException('You cannot remove the last member from this user group. Delete the user group instead.');
|
||||
}
|
||||
// if this is also the user we're editing right now, and do not grant them the owner role:
|
||||
if ($lastUserId === (int)$user->id && count($data['roles']) > 0 && !in_array(UserRoleEnum::OWNER->value, $data['roles'], true)) {
|
||||
app('log')->debug('User needs to have owner role in this group, refuse to act');
|
||||
Log::debug('User needs to have owner role in this group, refuse to act');
|
||||
|
||||
throw new FireflyException('The last member in this user group must get or keep the "owner" role.');
|
||||
}
|
||||
@@ -267,7 +268,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
&& (0 === count($data['roles'])
|
||||
|| (count($data['roles']) > 0 // @phpstan-ignore-line
|
||||
&& !in_array(UserRoleEnum::OWNER->value, $data['roles'], true)))) {
|
||||
app('log')->debug('User needs to keep owner role in this group, refuse to act');
|
||||
Log::debug('User needs to keep owner role in this group, refuse to act');
|
||||
|
||||
throw new FireflyException('The last owner in this user group must keep the "owner" role.');
|
||||
}
|
||||
@@ -294,12 +295,12 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
private function simplifyListByName(array $roles): array
|
||||
{
|
||||
if (in_array(UserRoleEnum::OWNER->value, $roles, true)) {
|
||||
app('log')->debug(sprintf('List of roles is [%1$s] but this includes "%2$s", so return [%2$s]', implode(',', $roles), UserRoleEnum::OWNER->value));
|
||||
Log::debug(sprintf('List of roles is [%1$s] but this includes "%2$s", so return [%2$s]', implode(',', $roles), UserRoleEnum::OWNER->value));
|
||||
|
||||
return [UserRoleEnum::OWNER->value];
|
||||
}
|
||||
if (in_array(UserRoleEnum::FULL->value, $roles, true)) {
|
||||
app('log')->debug(sprintf('List of roles is [%1$s] but this includes "%2$s", so return [%2$s]', implode(',', $roles), UserRoleEnum::FULL->value));
|
||||
Log::debug(sprintf('List of roles is [%1$s] but this includes "%2$s", so return [%2$s]', implode(',', $roles), UserRoleEnum::FULL->value));
|
||||
|
||||
return [UserRoleEnum::FULL->value];
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class WebhookRepository implements WebhookRepositoryInterface, UserGroupInterfac
|
||||
->where('webhook_messages.errored', 0)
|
||||
->get(['webhook_messages.*'])
|
||||
->filter(
|
||||
static fn (WebhookMessage $message) // @phpstan-ignore-line
|
||||
static fn (WebhookMessage $message): bool // @phpstan-ignore-line
|
||||
=> $message->webhookAttempts()->count() <= 2
|
||||
)->splice(0, 3)
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user