Overview
Comment:Fix search sync with files
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable | 1.1.10
Files: files | file ages | folders
SHA3-256: 4b346293f708755da82044f790615d2a122fc385fef8a5d58b44941c464d531d
User & Date: bohwaz on 2021-07-16 17:16:49
Other Links: manifest | tags
Context
2021-07-16
17:30
Fix dot-directories issue check-in: 811e54d7d8 user: bohwaz tags: trunk, stable, 1.1.10
17:16
Fix search sync with files check-in: 4b346293f7 user: bohwaz tags: trunk, stable, 1.1.10
16:23
Add year label to reports title check-in: 92074c0b13 user: bohwaz tags: trunk, stable
Changes

Modified src/VERSION from [6930707832] to [04dae89166].

1
1.1.9
|
1
1.1.10

Modified src/include/lib/Garradin/Entities/Files/File.php from [5806611bab] to [211bafd088].

167
168
169
170
171
172
173


174
175
176
177
178
179
180
		Plugin::fireSignal('files.delete', ['file' => $this]);

		// clean up thumbnails
		foreach (self::ALLOWED_THUMB_SIZES as $size)
		{
			Static_Cache::remove(sprintf(self::THUMB_CACHE_ID, $this->pathHash(), $size));
		}



		if ($this->exists()) {
			return parent::delete();
		}

		return true;
	}







>
>







167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
		Plugin::fireSignal('files.delete', ['file' => $this]);

		// clean up thumbnails
		foreach (self::ALLOWED_THUMB_SIZES as $size)
		{
			Static_Cache::remove(sprintf(self::THUMB_CACHE_ID, $this->pathHash(), $size));
		}

		DB::getInstance()->delete('files_search', 'path = ? OR path LIKE ?', $this->path, $this->path . '/%');

		if ($this->exists()) {
			return parent::delete();
		}

		return true;
	}

Modified src/include/lib/Garradin/Files/Files.php from [31ce22e30c] to [dac7d36ab5].

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343

344
345
346
347




348
349
350
351
352
		if (FILE_STORAGE_BACKEND == 'SQLite') {
			return 'files';
		}

		return 'tmp_files';
	}

	static public function syncVirtualTable(string $parent = '')
	{
		if (FILE_STORAGE_BACKEND == 'SQLite') {
			// No need to create a virtual table, use the real one
			return;
		}

		$db = DB::getInstance();
		$db->begin();

		$db->exec('CREATE TEMP TABLE IF NOT EXISTS tmp_files AS SELECT * FROM files WHERE 0;');

		foreach (Files::list($parent) as $file) {
			$db->insert('tmp_files', $file->asArray(true));




		}

		$db->commit();
	}
}







|








>




>
>
>
>





328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
		if (FILE_STORAGE_BACKEND == 'SQLite') {
			return 'files';
		}

		return 'tmp_files';
	}

	static public function syncVirtualTable(string $parent = '', bool $recursive = false)
	{
		if (FILE_STORAGE_BACKEND == 'SQLite') {
			// No need to create a virtual table, use the real one
			return;
		}

		$db = DB::getInstance();
		$db->begin();

		$db->exec('CREATE TEMP TABLE IF NOT EXISTS tmp_files AS SELECT * FROM files WHERE 0;');

		foreach (Files::list($parent) as $file) {
			$db->insert('tmp_files', $file->asArray(true));

			if ($recursive && $file->type === $file::TYPE_DIRECTORY) {
				self::syncVirtualTable($file->path, $recursive);
			}
		}

		$db->commit();
	}
}

Modified src/include/lib/Garradin/Upgrade.php from [ef2fdce049] to [a3d7e4ed57].

315
316
317
318
319
320
321









322
323
324
325
326
327
328
				$db->commit();
			}

			if (version_compare($v, '1.1.8', '==')) {
				// Force sync to add missing pages if you had the buggy 1.1.8 version
				\Garradin\Web\Web::sync(true);
			}










			// Vérification de la cohérence des clés étrangères
			$db->foreignKeyCheck();

			// Delete local cached files
			Utils::resetCache(USER_TEMPLATES_CACHE_ROOT);
			Utils::resetCache(STATIC_CACHE_ROOT);







>
>
>
>
>
>
>
>
>







315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
				$db->commit();
			}

			if (version_compare($v, '1.1.8', '==')) {
				// Force sync to add missing pages if you had the buggy 1.1.8 version
				\Garradin\Web\Web::sync(true);
			}

			if (version_compare($v, '1.1.10', '<')) {
				\Garradin\Web\Web::sync(true); // Force sync of web pages
				Files::syncVirtualTable('', true);

				$db->begin();
				$db->exec(sprintf('DELETE FROM files_search WHERE path NOT IN (SELECT path FROM %s);', Files::getVirtualTableName()));
				$db->commit();
			}

			// Vérification de la cohérence des clés étrangères
			$db->foreignKeyCheck();

			// Delete local cached files
			Utils::resetCache(USER_TEMPLATES_CACHE_ROOT);
			Utils::resetCache(STATIC_CACHE_ROOT);