Overview
Comment:Clear graph cache after import
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA3-256: eead5b5fb1f243c4c8427e748c63f953f9bd4f7d59c601774cba343f649a5a04
User & Date: bohwaz on 2021-11-30 14:56:43
Other Links: manifest | tags
Context
2021-11-30
17:16
Don't order by price, but by label check-in: 32e3b9404e user: bohwaz tags: trunk, stable
14:56
Clear graph cache after import check-in: eead5b5fb1 user: bohwaz tags: trunk, stable
14:38
Fix checkbox in chart editing check-in: fea7d49f1e user: bohwaz tags: trunk, stable
Changes

Modified src/include/lib/Garradin/Accounting/Graph.php from [af4ec17e7a] to [825b55b4d7].

51
52
53
54
55
56
57

















58
59
60
61
62
63
64
		'revenue' => ['position' => Account::REVENUE, 'exclude_type' => Account::TYPE_VOLUNTEERING],
		'expense' => ['position' => Account::EXPENSE, 'exclude_type' => Account::TYPE_VOLUNTEERING],
		'assets' => ['type' => [Account::TYPE_BANK, Account::TYPE_CASH, Account::TYPE_OUTSTANDING]],
	];

	const WEEKLY_INTERVAL = 604800; // 7 days
	const MONTHLY_INTERVAL = 2635200; // 1 month


















	static public function plot(string $type, array $criterias, int $interval = self::WEEKLY_INTERVAL, int $width = 700)
	{
		if (!array_key_exists($type, self::PLOT_TYPES)) {
			throw new \InvalidArgumentException('Unknown type');
		}








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
		'revenue' => ['position' => Account::REVENUE, 'exclude_type' => Account::TYPE_VOLUNTEERING],
		'expense' => ['position' => Account::EXPENSE, 'exclude_type' => Account::TYPE_VOLUNTEERING],
		'assets' => ['type' => [Account::TYPE_BANK, Account::TYPE_CASH, Account::TYPE_OUTSTANDING]],
	];

	const WEEKLY_INTERVAL = 604800; // 7 days
	const MONTHLY_INTERVAL = 2635200; // 1 month

	static public function clearCache(string $type, array $criterias, int $interval = self::WEEKLY_INTERVAL, int $width = 700): void
	{
		if (!array_key_exists($type, self::PLOT_TYPES)) {
			throw new \InvalidArgumentException('Unknown type');
		}

		$cache_id = sha1('plot' . json_encode(func_get_args()));

		Static_Cache::remove($cache_id);
	}

	static public function clearCacheAllYears(): void
	{
		self::clearCache('assets', [], Graph::MONTHLY_INTERVAL, 600);
		self::clearCache('result', [], Graph::MONTHLY_INTERVAL, 600);
	}

	static public function plot(string $type, array $criterias, int $interval = self::WEEKLY_INTERVAL, int $width = 700)
	{
		if (!array_key_exists($type, self::PLOT_TYPES)) {
			throw new \InvalidArgumentException('Unknown type');
		}

Modified src/include/lib/Garradin/Accounting/Transactions.php from [7839877bed] to [31743804a6].

307
308
309
310
311
312
313


314
315
316
317
318
319
320
				$e->setDetails($transaction->asDetailsArray());
			}

			throw $e;
		}

		$db->commit();


	}

	static public function importCustom(Year $year, CSV_Custom $csv, int $user_id)
	{
		if ($year->closed) {
			throw new \InvalidArgumentException('Closed year');
		}







>
>







307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
				$e->setDetails($transaction->asDetailsArray());
			}

			throw $e;
		}

		$db->commit();

		Graph::clearCacheAllYears();
	}

	static public function importCustom(Year $year, CSV_Custom $csv, int $user_id)
	{
		if ($year->closed) {
			throw new \InvalidArgumentException('Closed year');
		}
394
395
396
397
398
399
400


401
402
403
404
405
406
407
				$e->setDetails($transaction->asDetailsArray());
			}

			throw $e;
		}

		$db->commit();


	}

	static public function setAnalytical(?int $id_analytical, ?array $transactions = null, ?array $lines = null)
	{
		$db = DB::getInstance();

		if (null !== $id_analytical && !$db->test(Account::TABLE, 'type = ? AND id = ?', Account::TYPE_ANALYTICAL, $id_analytical)) {







>
>







396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
				$e->setDetails($transaction->asDetailsArray());
			}

			throw $e;
		}

		$db->commit();

		Graph::clearCacheAllYears();
	}

	static public function setAnalytical(?int $id_analytical, ?array $transactions = null, ?array $lines = null)
	{
		$db = DB::getInstance();

		if (null !== $id_analytical && !$db->test(Account::TABLE, 'type = ? AND id = ?', Account::TYPE_ANALYTICAL, $id_analytical)) {