Overview
Comment:Reset CSV import if it fails
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA3-256: 7dcca899df2f0f968b501ad606e4d681233158ccf0f81c042ddd92c28c6b9cb0
User & Date: bohwaz on 2022-07-26 01:04:21
Other Links: manifest | tags
Context
2022-07-26
10:42
Make sure we cannot serve directories as templates check-in: 0f104738a7 user: bohwaz tags: trunk, stable
01:04
Reset CSV import if it fails check-in: 7dcca899df user: bohwaz tags: trunk, stable
2022-07-25
23:34
Accept hours with only one digit check-in: c7ebeccb57 user: bohwaz tags: trunk, stable
Changes

Modified src/include/lib/Garradin/CSV_Custom.php from [69eadcaed6] to [407382c630].

183
184
185
186
187
188
189

190
191
192
193
194
195
196
	}

	public function clear(): void
	{
		$this->session->set($this->key, null);
		$this->session->set($this->key . '_translation', null);
		$this->session->set($this->key . '_skip', null);

		$this->translation = null;
	}

	public function loaded(): bool
	{
		return null !== $this->csv;
	}







>







183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
	}

	public function clear(): void
	{
		$this->session->set($this->key, null);
		$this->session->set($this->key . '_translation', null);
		$this->session->set($this->key . '_skip', null);
		$this->csv = null;
		$this->translation = null;
	}

	public function loaded(): bool
	{
		return null !== $this->csv;
	}

Modified src/www/admin/acc/years/import.php from [1f7549983a] to [c4d45cabf9].

47
48
49
50
51
52
53
54
55
56
57

58


59

60
61
62
63
64
65
66

if ($type && $type_name) {
	$columns = Transactions::EXPORT_COLUMNS[$type];
	unset($columns['linked_users']);
	$csv->setColumns($columns);
	$csv->setMandatoryColumns(Transactions::MANDATORY_COLUMNS[$type]);

	$form->runIf(f('assign') && $csv->loaded(), function () use ($type, $csv, $year, $user, $ignore_ids) {
		$csv->skip((int)f('skip_first_line'));
		$csv->setTranslationTable(f('translation_table'));


		Transactions::import($type, $year, $csv, $user->id, (bool) $ignore_ids);


		$csv->clear();

	}, $csrf_key, ADMIN_URL . 'acc/years/?msg=IMPORT');

	$form->runIf(f('load') && isset($_FILES['file']['tmp_name']), function () use ($type, $csv, $year, $params) {
		$csv->load($_FILES['file']);
		Utils::redirect(Utils::getSelfURI($params));
	}, $csrf_key);
}







|



>
|
>
>
|
>







47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

if ($type && $type_name) {
	$columns = Transactions::EXPORT_COLUMNS[$type];
	unset($columns['linked_users']);
	$csv->setColumns($columns);
	$csv->setMandatoryColumns(Transactions::MANDATORY_COLUMNS[$type]);

	$form->runIf(f('assign') && $csv->loaded(), function () use ($type, &$csv, $year, $user, $ignore_ids) {
		$csv->skip((int)f('skip_first_line'));
		$csv->setTranslationTable(f('translation_table'));

		try {
			Transactions::import($type, $year, $csv, $user->id, (bool) $ignore_ids);
		}
		finally {
			$csv->clear();
		}
	}, $csrf_key, ADMIN_URL . 'acc/years/?msg=IMPORT');

	$form->runIf(f('load') && isset($_FILES['file']['tmp_name']), function () use ($type, $csv, $year, $params) {
		$csv->load($_FILES['file']);
		Utils::redirect(Utils::getSelfURI($params));
	}, $csrf_key);
}