Overview
Comment:Fix collation
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA3-256: 9ecbcbce5c018a76f41f9ea92516c05f01f47c2b1ed3392462d14f0f4602e76f
User & Date: bohwaz on 2021-03-30 21:45:41
Other Links: branch diff | manifest | tags
Context
2021-03-30
21:58
Cache quota as it may make things slow check-in: c0f86221c0 user: bohwaz tags: dev
21:45
Fix collation check-in: 9ecbcbce5c user: bohwaz tags: dev
21:23
Fix session issue check-in: 0efff9c95b user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/DB.php from [f7de57d793] to [8dd3841b1b].

47
48
49
50
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
        // Performance enhancement
        // see https://www.cs.utexas.edu/~jaya/slides/apsys17-sqlite-slides.pdf
        // https://ericdraken.com/sqlite-performance-testing/
        $this->exec(sprintf('PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL; PRAGMA journal_size_limit = %d;', 32 * 1024 * 1024));

        $this->db->createFunction('dirname', [Utils::class, 'dirname']);
        $this->db->createFunction('basename', [Utils::class, 'basename']);
        $this->db->createCollation('NOCASE', [static::class, 'unicodeCaseComparison']);
    }

    static public function unicodeCaseComparison($a, $b): int
    {
        if (function_exists('mb_strtoupper')) {
            $a = mb_strtoupper($a);
            $b = mb_strtoupper($b);
        }
        else {
            $a = strtoupper(Utils::transliterateToAscii($a));
            $b = strtoupper(Utils::transliterateToAscii($b));
        }

        return strcmp($a, $b);
    }

    public function version(): ?string
    {
        if (-1 === $this->_version) {
            $this->connect();
            $this->_version = self::getVersion($this->db);







|
<
<
<
<
<
<
<
<
<
<
<
<
<
<







47
48
49
50
51
52
53
54














55
56
57
58
59
60
61
        // Performance enhancement
        // see https://www.cs.utexas.edu/~jaya/slides/apsys17-sqlite-slides.pdf
        // https://ericdraken.com/sqlite-performance-testing/
        $this->exec(sprintf('PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL; PRAGMA journal_size_limit = %d;', 32 * 1024 * 1024));

        $this->db->createFunction('dirname', [Utils::class, 'dirname']);
        $this->db->createFunction('basename', [Utils::class, 'basename']);
        $this->db->createCollation('NOCASE', [Utils::class, 'unicodeCaseComparison']);














    }

    public function version(): ?string
    {
        if (-1 === $this->_version) {
            $this->connect();
            $this->_version = self::getVersion($this->db);

Modified src/include/lib/Garradin/Files/Storage/FileSystem.php from [41e39a13ce] to [d45a8b3cdb].

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
		foreach (new \FilesystemIterator($fullpath, \FilesystemIterator::SKIP_DOTS) as $file) {
			// Used to make sorting easier
			// directory_blabla
			// file_image.jpeg
			$files[$file->getType() . '_' .$file->getFilename()] = self::_SplToFile($file);
		}

		uksort($files, function ($a, $b) {
			return strnatcasecmp($a, $b) > 0 ? 1 : -1;
		});

		return $files;
	}

	static public function getTotalSize(): int
	{
		if (null !== self::$_size) {
			return self::$_size;
		}







|
<
<
<
<







203
204
205
206
207
208
209
210




211
212
213
214
215
216
217
		foreach (new \FilesystemIterator($fullpath, \FilesystemIterator::SKIP_DOTS) as $file) {
			// Used to make sorting easier
			// directory_blabla
			// file_image.jpeg
			$files[$file->getType() . '_' .$file->getFilename()] = self::_SplToFile($file);
		}

		return Utils::knatcasesort($files);




	}

	static public function getTotalSize(): int
	{
		if (null !== self::$_size) {
			return self::$_size;
		}

Modified src/include/lib/Garradin/Files/Storage/SQLite.php from [a974b86035] to [4526537084].

3
4
5
6
7
8
9

10
11
12
13
14
15
16
namespace Garradin\Files\Storage;

use Garradin\Entities\Files\File;
use Garradin\Files\Files;

use Garradin\Static_Cache;
use Garradin\DB;


use KD2\DB\EntityManager as EM;

use const Garradin\{DB_FILE, DATA_ROOT};

class SQLite implements StorageInterface
{







>







3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace Garradin\Files\Storage;

use Garradin\Entities\Files\File;
use Garradin\Files\Files;

use Garradin\Static_Cache;
use Garradin\DB;
use Garradin\Utils;

use KD2\DB\EntityManager as EM;

use const Garradin\{DB_FILE, DATA_ROOT};

class SQLite implements StorageInterface
{

Modified src/include/lib/Garradin/UserTemplate/Sections.php from [66f75daf66] to [edc615ff84].

1
2
3
4
5
6

7
8
9
10
11
12
13
<?php

namespace Garradin\UserTemplate;

use KD2\Brindille_Exception;
use Garradin\DB;

use Garradin\Entities\Web\Page;
use Garradin\Web\Web;
use Garradin\Files\Files;
use Garradin\Entities\Files\File;

use const Garradin\WWW_URL;







>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php

namespace Garradin\UserTemplate;

use KD2\Brindille_Exception;
use Garradin\DB;
use Garradin\Utils;
use Garradin\Entities\Web\Page;
use Garradin\Web\Web;
use Garradin\Files\Files;
use Garradin\Entities\Files\File;

use const Garradin\WWW_URL;

Modified src/include/lib/Garradin/Utils.php from [d4dc8dfafb] to [8c1e367a44].

10
11
12
13
14
15
16


17
18
19
20
21
22
23
...
880
881
882
883
884
885
886
887
























class Utils
{
    const EMAIL_CONTEXT_BULK = 'bulk';
    const EMAIL_CONTEXT_PRIVATE = 'private';
    const EMAIL_CONTEXT_SYSTEM = 'system';



    const FRENCH_DATE_NAMES = [
        'January'=>'Janvier', 'February'=>'Février', 'March'=>'Mars', 'April'=>'Avril', 'May'=>'Mai',
        'June'=>'Juin', 'July'=>'Juillet', 'August'=>'Août', 'September'=>'Septembre', 'October'=>'Octobre',
        'November'=>'Novembre', 'December'=>'Décembre', 'Monday'=>'Lundi', 'Tuesday'=>'Mardi', 'Wednesday'=>'Mercredi',
        'Thursday'=>'Jeudi','Friday'=>'Vendredi','Saturday'=>'Samedi','Sunday'=>'Dimanche',
        'Feb'=>'Fév','Apr'=>'Avr','Jun'=>'Juin', 'Jul'=>'Juil','Aug'=>'Aout','Dec'=>'Déc',
        'Mon'=>'Lun','Tue'=>'Mar','Wed'=>'Mer','Thu'=>'Jeu','Fri'=>'Ven','Sat'=>'Sam','Sun'=>'Dim'];
................................................................................
    {
        $str = str_replace(DIRECTORY_SEPARATOR, '/', $str);
        $str = trim($str, '/');
        $str = substr($str, strrpos($str, '/'));
        $str = trim($str, '/');
        return $str;
    }
}






























>
>







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912

class Utils
{
    const EMAIL_CONTEXT_BULK = 'bulk';
    const EMAIL_CONTEXT_PRIVATE = 'private';
    const EMAIL_CONTEXT_SYSTEM = 'system';

    static protected $collator;

    const FRENCH_DATE_NAMES = [
        'January'=>'Janvier', 'February'=>'Février', 'March'=>'Mars', 'April'=>'Avril', 'May'=>'Mai',
        'June'=>'Juin', 'July'=>'Juillet', 'August'=>'Août', 'September'=>'Septembre', 'October'=>'Octobre',
        'November'=>'Novembre', 'December'=>'Décembre', 'Monday'=>'Lundi', 'Tuesday'=>'Mardi', 'Wednesday'=>'Mercredi',
        'Thursday'=>'Jeudi','Friday'=>'Vendredi','Saturday'=>'Samedi','Sunday'=>'Dimanche',
        'Feb'=>'Fév','Apr'=>'Avr','Jun'=>'Juin', 'Jul'=>'Juil','Aug'=>'Aout','Dec'=>'Déc',
        'Mon'=>'Lun','Tue'=>'Mar','Wed'=>'Mer','Thu'=>'Jeu','Fri'=>'Ven','Sat'=>'Sam','Sun'=>'Dim'];
................................................................................
    {
        $str = str_replace(DIRECTORY_SEPARATOR, '/', $str);
        $str = trim($str, '/');
        $str = substr($str, strrpos($str, '/'));
        $str = trim($str, '/');
        return $str;
    }

    static public function unicodeCaseComparison($a, $b): int
    {
        if (!isset(self::$collator) && function_exists('collator_create')) {
            self::$collator = \Collator::create('fr_FR');
            self::$collator->setAttribute(\Collator::NUMERIC_COLLATION, \Collator::ON);
        }

        if (isset(self::$collator)) {
            return self::$collator->compare($a, $b);
        }

        $a = strtoupper(self::transliterateToAscii($a));
        $b = strtoupper(self::transliterateToAscii($b));

        return strcmp($a, $b);
    }

    static public function knatcasesort(array $array)
    {
        uksort($array, [self::class, 'unicodeCaseComparison']);
        return $array;
    }
}