Compare commits

..

8 Commits

Author SHA1 Message Date
github-actions
5285e1ac14 Auto commit for release 'branch-v6.2' on 2024-12-15 2024-12-15 16:16:13 +01:00
James Cole
48a999cf91 Fix old reference. 2024-12-15 16:11:48 +01:00
github-actions
6bb297e76f Auto commit for release 'branch-v6.2' on 2024-12-15 2024-12-15 10:32:00 +01:00
James Cole
bc698f67ea Merge branch 'main' into v6.2 2024-12-15 09:07:04 +01:00
James Cole
f1c859aaa3 Update build job 2024-12-15 08:57:55 +01:00
James Cole
2d0aa207d4 Fix various piggy bank errors 2024-12-15 08:50:57 +01:00
James Cole
4a75e9c262 Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2 2024-12-15 08:20:52 +01:00
James Cole
ee7c4b8863 Fix user test notification. 2024-12-15 08:20:42 +01:00
7 changed files with 110 additions and 65 deletions

View File

@@ -179,10 +179,10 @@ jobs:
if [[ "$version" == branch* ]]; then
[[ -z $(git status --untracked-files=normal --porcelain) ]] && echo "this branch is clean, no need to push..." && exit 0;
# branch builds overrule develop
releaseName=develop-$(date +'%Y%m%d')
releaseName=$version-$(date +'%Y%m%d')
originalName=$releaseName
zipName=FireflyIII-develop.zip
tarName=FireflyIII-develop.tar.gz
zipName=FireflyIII-$version.zip
tarName=FireflyIII-$version.tar.gz
fi
# in both cases, if the release or tag already exists, add ".1" until it no longer exists.
@@ -226,12 +226,13 @@ jobs:
gpg --armor --detach-sign $zipName
gpg --armor --detach-sign $tarName
# create a development (nightly) release:
if [[ "develop" == "$version" ]] || [[ "$version" == branch* ]]; then
# describe the development release.
if [[ "develop" == "$version" ]]; then
echo 'Develop release.'
# add text to output.txt (instructions)
rm output.txt
echo "Bi-weekly development release of Firefly III with the latest fixes, translations and features. Docker users can find this release under the \`develop\` tag." >> output.txt
touch output.txt
sudo chown -R runner:docker output.txt
echo "Weekly development release of Firefly III with the latest fixes, translations and features. Docker users can find this release under the \`develop\` tag." >> output.txt
echo "" >> output.txt
echo "This release was created on **$(date +'%Y-%m-%d')** and may contain unexpected bugs. Data loss is rare but is not impossible. The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/)." >> output.txt
echo "" >> output.txt
@@ -239,10 +240,41 @@ jobs:
echo "* Or read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)" >> output.txt
echo "" >> output.txt
echo ":warning: Please be careful with this pre-release, as it may not work as expected." >> output.txt
fi
# describe a branch release
if [[ "$version" == branch* ]]; then
echo 'Branch release.'
rm output.txt
touch output.txt
sudo chown -R runner:docker output.txt
echo "Irregular BRANCH release of Firefly III. This release contains specific features or changes. Docker users can find this release under the \`$version\` tag." >> output.txt
echo "" >> output.txt
echo "This release was created on **$(date +'%Y-%m-%d')** and may contain unexpected bugs. Data loss is rare but is not impossible. The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/)." >> output.txt
echo "" >> output.txt
echo "* Please read the installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/)" >> output.txt
echo "* Or read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)" >> output.txt
echo "" >> output.txt
echo ":warning: Please be careful with this branch pre-release, as it may not work as expected." >> output.txt
fi
# describe the main release
if [[ "develop" != "$version" ]] && [[ "$version" != branch* ]]; then
sudo chown -R runner:docker output.txt
echo 'Main release.'
echo '' >> output.txt
echo '### Instructions' >> output.txt
echo '' >> output.txt
echo "* Installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/)" >> output.txt
echo "* Or read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)" >> output.txt
echo "* The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/)." >> output.txt
fi
# create a development (nightly) release:
if [[ "develop" == "$version" ]] || [[ "$version" == branch* ]]; then
# create the release:
echo "Create nightly release."
git tag -a $releaseName -m "Nightly development release '$version' on $(date +'%Y-%m-%d')"
echo "Create nightly or branch release."
git tag -a $releaseName -m "Development release '$version' on $(date +'%Y-%m-%d')"
git push origin $releaseName
gh release create $releaseName -p --verify-tag \
-t "Development release for $(date +'%Y-%m-%d')" \
@@ -266,16 +298,6 @@ jobs:
gh release upload $releaseName HEAD.txt
else
echo 'MAIN (real) release'
sudo chown -R runner:docker output.txt
# add text to output.txt (more instructions)
echo '' >> output.txt
echo '### Instructions' >> output.txt
echo '' >> output.txt
echo "* Installation instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/installation/docker/), [Portainer](https://docs.firefly-iii.org/how-to/firefly-iii/installation/portainer/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/installation/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/installation/self-managed/)" >> output.txt
echo "* Or read the upgrade instructions for [Docker](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/docker/), [Kubernetes](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/kubernetes/) or [self-managed servers](https://docs.firefly-iii.org/how-to/firefly-iii/upgrade/self-managed/)" >> output.txt
echo "* The releases are signed, and you can verify them using the [Firefly III releases PGP key](https://docs.firefly-iii.org/explanation/more-information/signatures/)." >> output.txt
echo "Create default release."
git tag -a $releaseName -m "Here be changelog"
git push origin $releaseName
gh release create $releaseName -F output.txt -t "$releaseName" --verify-tag

View File

@@ -103,7 +103,7 @@ class PiggyBankController extends Controller
/** @var PiggyBank $piggy */
foreach ($piggies as $piggy) {
$currency = $piggy->transactionCurrency;
$currentAmount = $this->piggyRepository->getRepetition($piggy)->current_amount ?? '0';
$currentAmount = $this->piggyRepository->getCurrentAmount($piggy);
$objectGroup = $piggy->objectGroups()->first();
$response[] = [
'id' => (string)$piggy->id,

View File

@@ -32,6 +32,7 @@ use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\User;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Log;
/**
* Class PiggyBankFactory
@@ -221,7 +222,22 @@ class PiggyBankFactory
public function linkToAccountIds(PiggyBank $piggyBank, array $accounts): void
{
Log::debug(sprintf('Linking piggy bank #%d to %d accounts.', $piggyBank->id, count($accounts)), $accounts);
// collect current current_amount so the sync does not remove them.
// TODO this is a tedious check. Feels like a hack.
$toBeLinked = [];
foreach($piggyBank->accounts as $account) {
foreach($accounts as $info) {
if($account->id === $info['account_id']) {
if(array_key_exists($account->id, $accounts)) {
$toBeLinked[$account->id] = ['current_amount' => $account->pivot->current_amount];
Log::debug(sprintf('Prefilled for account #%d with amount %s', $account->id, $account->pivot->current_amount));
}
}
}
}
/** @var array $info */
foreach ($accounts as $info) {
$account = $this->accountRepository->find((int) ($info['account_id'] ?? 0));
@@ -230,13 +246,14 @@ class PiggyBankFactory
}
if (array_key_exists('current_amount', $info)) {
$toBeLinked[$account->id] = ['current_amount' => $info['current_amount']];
//$piggyBank->accounts()->syncWithoutDetaching([$account->id => ['current_amount' => $info['current_amount'] ?? '0']]);
Log::debug(sprintf('Will link account #%d with amount %s', $account->id, $account->pivot->current_amount));
}
if (!array_key_exists('current_amount', $info)) {
$toBeLinked[$account->id] = [];
//$piggyBank->accounts()->syncWithoutDetaching([$account->id]);
$toBeLinked[$account->id] ??= [];
Log::debug(sprintf('Will link account #%d with info: ', $account->id), $toBeLinked[$account->id]);
}
}
Log::debug(sprintf('Link information: %s', json_encode($toBeLinked)));
$piggyBank->accounts()->sync($toBeLinked);
}
}

View File

@@ -24,7 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\Test;
use FireflyIII\Notifications\Notifiables\OwnerNotifiable;
use FireflyIII\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
@@ -38,20 +38,17 @@ class UserTestNotificationSlack extends Notification
{
use Queueable;
private OwnerNotifiable $owner;
private User $user;
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(OwnerNotifiable $owner)
public function __construct(User $user)
{
$this->owner = $owner;
$this->user = $user;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function toArray(OwnerNotifiable $notifiable)
public function toArray(User $user)
{
return [
];
@@ -60,7 +57,7 @@ class UserTestNotificationSlack extends Notification
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function toSlack(OwnerNotifiable $notifiable)
public function toSlack(User $user)
{
return new SlackMessage()->content((string) trans('email.admin_test_subject'));
// return new SlackMessage()->text((string) trans('email.admin_test_subject'))->to($url);
@@ -69,7 +66,7 @@ class UserTestNotificationSlack extends Notification
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function via(OwnerNotifiable $notifiable)
public function via(User $user)
{
return ['slack'];
}

View File

@@ -46,13 +46,13 @@ trait ModifiesPiggyBanks
public function addAmountToRepetition(PiggyBankRepetition $repetition, string $amount, TransactionJournal $journal): void
{
throw new FireflyException('[a] Piggy bank repetitions are EOL.');
app('log')->debug(sprintf('addAmountToRepetition: %s', $amount));
Log::debug(sprintf('addAmountToRepetition: %s', $amount));
if (-1 === bccomp($amount, '0')) {
app('log')->debug('Remove amount.');
Log::debug('Remove amount.');
$this->removeAmount($repetition->piggyBank, bcmul($amount, '-1'), $journal);
}
if (1 === bccomp($amount, '0')) {
app('log')->debug('Add amount.');
Log::debug('Add amount.');
$this->addAmount($repetition->piggyBank, $amount, $journal);
}
}
@@ -64,7 +64,7 @@ trait ModifiesPiggyBanks
$pivot->current_amount = bcsub($currentAmount, $amount);
$pivot->save();
app('log')->debug('removeAmount [a]: Trigger change for negative amount.');
Log::debug('ChangedAmount: removeAmount [a]: Trigger change for negative amount.');
event(new ChangedAmount($piggyBank, bcmul($amount, '-1'), $journal, null));
return true;
@@ -95,7 +95,7 @@ trait ModifiesPiggyBanks
$pivot->current_amount = bcadd($currentAmount, $amount);
$pivot->save();
app('log')->debug('addAmount [b]: Trigger change for positive amount.');
Log::debug('ChangedAmount: addAmount [b]: Trigger change for positive amount.');
event(new ChangedAmount($piggyBank, $amount, $journal, null));
return true;
@@ -109,21 +109,21 @@ trait ModifiesPiggyBanks
$savedSoFar = $this->getCurrentAmount($piggyBank);
$maxAmount = $leftOnAccount;
app('log')->debug(sprintf('Left on account: %s on %s', $leftOnAccount, $today->format('Y-m-d H:i:s')));
app('log')->debug(sprintf('Saved so far: %s', $savedSoFar));
Log::debug(sprintf('Left on account: %s on %s', $leftOnAccount, $today->format('Y-m-d H:i:s')));
Log::debug(sprintf('Saved so far: %s', $savedSoFar));
if (0 !== bccomp($piggyBank->target_amount, '0')) {
$leftToSave = bcsub($piggyBank->target_amount, $savedSoFar);
$maxAmount = 1 === bccomp($leftOnAccount, $leftToSave) ? $leftToSave : $leftOnAccount;
app('log')->debug(sprintf('Left to save: %s', $leftToSave));
app('log')->debug(sprintf('Maximum amount: %s', $maxAmount));
Log::debug(sprintf('Left to save: %s', $leftToSave));
Log::debug(sprintf('Maximum amount: %s', $maxAmount));
}
$compare = bccomp($amount, $maxAmount);
$result = $compare <= 0;
app('log')->debug(sprintf('Compare <= 0? %d, so canAddAmount is %s', $compare, var_export($result, true)));
Log::debug(sprintf('Compare <= 0? %d, so canAddAmount is %s', $compare, var_export($result, true)));
return $result;
}
@@ -168,11 +168,11 @@ trait ModifiesPiggyBanks
$repetition->save();
if (-1 === bccomp($difference, '0')) {
app('log')->debug('addAmount [c]: Trigger change for negative amount.');
Log::debug('ChangedAmount: addAmount [c]: Trigger change for negative amount.');
event(new ChangedAmount($piggyBank, $difference, null, null));
}
if (1 === bccomp($difference, '0')) {
app('log')->debug('addAmount [d]: Trigger change for positive amount.');
Log::debug('ChangedAmount: addAmount [d]: Trigger change for positive amount.');
event(new ChangedAmount($piggyBank, $difference, null, null));
}
@@ -203,7 +203,7 @@ trait ModifiesPiggyBanks
public function setOrder(PiggyBank $piggyBank, int $newOrder): bool
{
$oldOrder = $piggyBank->order;
// app('log')->debug(sprintf('Will move piggy bank #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
// Log::debug(sprintf('Will move piggy bank #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
if ($newOrder > $oldOrder) {
PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
@@ -214,7 +214,7 @@ trait ModifiesPiggyBanks
;
$piggyBank->order = $newOrder;
app('log')->debug(sprintf('[1] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
Log::debug(sprintf('[1] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
$piggyBank->save();
return true;
@@ -228,7 +228,7 @@ trait ModifiesPiggyBanks
;
$piggyBank->order = $newOrder;
app('log')->debug(sprintf('[2] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
Log::debug(sprintf('[2] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
$piggyBank->save();
return true;
@@ -271,13 +271,15 @@ trait ModifiesPiggyBanks
$factory->linkToAccountIds($piggyBank, $data['accounts']);
// if the piggy bank is now smaller than the current relevant rep,
// remove money from the rep.
// if the piggy bank is now smaller than the sum of the money saved,
// remove money from all accounts until the piggy bank is the right amount.
$currentAmount = $this->getCurrentAmount($piggyBank);
if (1 === bccomp($currentAmount, '100') && 0 !== bccomp($piggyBank->target_amount, '0')) {
if (1 === bccomp($currentAmount, $piggyBank->target_amount) && 0 !== bccomp($piggyBank->target_amount, '0')) {
Log::debug(sprintf('Current amount is %s, target amount is %s', $currentAmount, $piggyBank->target_amount));
$difference = bcsub($piggyBank->target_amount, $currentAmount);
// an amount will be removed, create "negative" event:
Log::debug(sprintf('ChangedAmount: is triggered with difference "%s"', $difference));
event(new ChangedAmount($piggyBank, $difference, null, null));
// question is, from which account(s) to remove the difference?

View File

@@ -270,14 +270,12 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
*/
public function getPiggyBanksWithAmount(): Collection
{
$currency = app('amount')->getDefaultCurrency();
$set = $this->getPiggyBanks();
$set = $this->getPiggyBanks();
/** @var PiggyBank $piggy */
foreach ($set as $piggy) {
$currentAmount = $this->getRepetition($piggy)->current_amount ?? '0';
$piggy->name = $piggy->name.' ('.app('amount')->formatAnything($currency, $currentAmount, false).')';
$currentAmount = $this->getCurrentAmount($piggy);
$piggy->name = $piggy->name.' ('.app('amount')->formatAnything($piggy->transactionCurrency, $currentAmount, false).')';
}
return $set;
@@ -349,7 +347,16 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
public function searchPiggyBank(string $query, int $limit): Collection
{
$search = $this->user->piggyBanks();
$search = PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
->where('accounts.user_id', auth()->user()->id)
->with(
[
'objectGroups',
]
)
->orderBy('piggy_banks.order', 'ASC')->distinct()
;
if ('' !== $query) {
$search->whereLike('piggy_banks.name', sprintf('%%%s%%', $query));
}
@@ -357,7 +364,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
->orderBy('piggy_banks.name', 'ASC')
;
return $search->take($limit)->get();
return $search->take($limit)->get(['piggy_banks.*']);
}
#[\Override]

14
composer.lock generated
View File

@@ -6596,16 +6596,16 @@
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.14-dev"
},
"laravel": {
"providers": [
"TwigBridge\\ServiceProvider"
],
"aliases": {
"Twig": "TwigBridge\\Facade\\Twig"
}
},
"providers": [
"TwigBridge\\ServiceProvider"
]
},
"branch-alias": {
"dev-master": "0.14-dev"
}
},
"autoload": {