Various code cleanup.

This commit is contained in:
James Cole
2022-12-30 09:28:03 +01:00
parent 03e176bd16
commit ee0116f112
17 changed files with 171 additions and 125 deletions

View File

@@ -71,6 +71,7 @@ class RecurrenceController extends Controller
*/
public function events(Request $request): JsonResponse
{
$occurrences = [];
$return = [];
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
@@ -106,20 +107,19 @@ class RecurrenceController extends Controller
$repetition->weekend = (int)$request->get('weekend');
$actualEnd = clone $end;
switch ($endsAt) {
default:
case 'forever':
// simply generate up until $end. No change from default behavior.
$occurrences = $this->recurring->getOccurrencesInRange($repetition, $actualStart, $actualEnd);
break;
case 'until_date':
$actualEnd = $endDate ?? clone $end;
$occurrences = $this->recurring->getOccurrencesInRange($repetition, $actualStart, $actualEnd);
break;
case 'times':
$occurrences = $this->recurring->getXOccurrences($repetition, $actualStart, $repetitions);
break;
if('until_date' === $endsAt) {
$actualEnd = $endDate ?? clone $end;
$occurrences = $this->recurring->getOccurrencesInRange($repetition, $actualStart, $actualEnd);
}
if('times' === $endsAt) {
$occurrences = $this->recurring->getXOccurrences($repetition, $actualStart, $repetitions);
}
if('times' !== $endsAt && 'until_date' !== $endsAt) {
// 'forever'
$occurrences = $this->recurring->getOccurrencesInRange($repetition, $actualStart, $actualEnd);
}
/** @var Carbon $current */
foreach ($occurrences as $current) {
if ($current->gte($start)) {

View File

@@ -67,7 +67,7 @@ class TriggerController extends Controller
foreach ($groups as $group) {
/** @var TransactionJournal $journal */
foreach ($group->transactionJournals as $journal) {
Log::debug(sprintf('Set date of journal #%d to today!', $journal->id, $date));
Log::debug(sprintf('Set date of journal #%d to today!', $journal->id));
$journal->date = Carbon::today();
$journal->save();
}

View File

@@ -170,9 +170,10 @@ class EditController extends Controller
]
)->render();
} catch (Throwable $e) {
Log::debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
$message = sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage());
Log::debug($message);
Log::error($e->getTraceAsString());
throw new FireflyException($result, 0, $e);
throw new FireflyException($message, 0, $e);
}
$index++;
}

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Http\Controllers\System;
use Artisan;
use Cache;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Support\Facades\Preferences;
use FireflyIII\Support\Http\Controllers\GetConfigurationData;
@@ -165,7 +166,17 @@ class InstallController extends Controller
$index++;
continue;
}
$result = $this->executeCommand($command, $args);
try {
$result = $this->executeCommand($command, $args);
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
$this->lastError = self::BASEDIR_ERROR;
}
$result = false;
$this->lastError = sprintf('%s %s', self::OTHER_ERROR, $e->getMessage());
}
if (false === $result) {
$response['errorMessage'] = $this->lastError;
$response['error'] = true;
@@ -184,7 +195,7 @@ class InstallController extends Controller
/**
* @param string $command
* @param array $args
*
* @throws FireflyException
* @return bool
*/
private function executeCommand(string $command, array $args): bool
@@ -199,16 +210,7 @@ class InstallController extends Controller
Log::debug(Artisan::output());
}
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
$this->lastError = self::BASEDIR_ERROR;
return false;
}
$this->lastError = sprintf('%s %s', self::OTHER_ERROR, $e->getMessage());
return false;
throw new FireflyException($e->getMessage(), 0, $e);
}
// clear cache as well.
Cache::clear();