Overview
Comment:Un peu optimiste sur les capacités de SQLite, la conversion de format doit se faire manuellement en fait
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable | 0.9.7
Files: files | file ages | folders
SHA1: 7f5dfb0dcd83579f8ff3a48a4476083d33588932
User & Date: bohwaz on 2020-06-23 00:07:39
Other Links: manifest | tags
Context
2020-06-23
00:08
Ajout d'un format de date exotique check-in: e4c2076e26 user: bohwaz tags: trunk, stable, 0.9.7
00:07
Un peu optimiste sur les capacités de SQLite, la conversion de format doit se faire manuellement en fait check-in: 7f5dfb0dcd user: bohwaz tags: trunk, stable, 0.9.7
2020-06-22
23:34
Restaurer contenu article.html qui a été malencontreusement remplacé check-in: 68c2ae597f user: bohwaz tags: trunk, stable, 0.9.7
Changes

Modified src/www/admin/upgrade.php from [e7dfb28581] to [bc8ddb2ada].

275
276
277
278
279
280
281

282
283
284
285
286
287
288
























289
290
291
292
293
294
295

    if (version_compare($v, '0.9.7', '<'))
    {
        $db->begin();

        // Conversion des champs date
        $champs = (array) $config->get('champs_membres')->getAll();


        foreach ($champs as $key => $champ) {
            if ($champ->type == 'date') {
                $db->exec(sprintf('UPDATE membres SET %s = date(%01$s) WHERE %01$s IS NOT NULL;', $db->quoteIdentifier($key)));
            }
            elseif ($champ->type == 'datetime') {
                $db->exec(sprintf('UPDATE membres SET %s = datetime(%01$s) WHERE %01$s IS NOT NULL;', $db->quoteIdentifier($key)));
























            }
        }

        $db->commit();
    }

    Utils::clearCaches();







>



|


|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320

    if (version_compare($v, '0.9.7', '<'))
    {
        $db->begin();

        // Conversion des champs date
        $champs = (array) $config->get('champs_membres')->getAll();
        $formats = ['d/m/Y', 'd/m/Y H:i:s', 'd/m/Y H:i', 'd-m-Y'];

        foreach ($champs as $key => $champ) {
            if ($champ->type == 'date') {
                $target_format = 'Y-m-d';
            }
            elseif ($champ->type == 'datetime') {
                $target_format = 'Y-m-d H:i:s';
            }
            else {
                continue;
            }

            $sql = sprintf('SELECT id, %s AS date FROM membres WHERE %01$s IS NOT NULL AND date(%01$s) IS NULL;', $db->quoteIdentifier($key));

            foreach ($db->iterate($sql) as $row) {
                foreach ($formats as $format) {
                    $date = \DateTime::createFromFormat($format, $row->date);

                    if ($date) {
                        break;
                    }
                }

                if ($date) {
                    $date = $date->format($target_format);
                }
                else {
                    $date = null;
                }

                $db->update('membres', [$key => $date], 'id = ' . (int)$row->id);
            }
        }

        $db->commit();
    }

    Utils::clearCaches();