Differences From Artifact [e7dfb28581]:

To Artifact [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();