Overview
Comment:Ne pas limiter les requêtes pour l'envoi de mail, et préciser clairement si la requête ne permet pas d'accéder aux colonnes nécessaires
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA1: b13b9efbeefe582f01cc7e1be304d7d0093e37e5
User & Date: bohwaz on 2019-02-22 10:17:07
Other Links: manifest | tags
Context
2019-03-03
23:21
Ajout possibilité de visualiser dans la liste des cotisants tous les membres dont c'est la cotisation obligatoire, répond à un besoin basique de plusieurs assos (merci @Dbout) check-in: d56bf48588 user: bohwaz tags: trunk, stable
2019-02-22
10:17
Ne pas limiter les requêtes pour l'envoi de mail, et préciser clairement si la requête ne permet pas d'accéder aux colonnes nécessaires check-in: b13b9efbee user: bohwaz tags: trunk, stable
2019-02-06
15:34
Affichage correct des expirations des cotisations à durée définie check-in: 64f6a74326 user: bohwaz tags: trunk, stable
Changes

Modified src/include/lib/Garradin/Recherche.php from [0325ea49c7] to [35a5a3057c].

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
			WHERE (id_membre IS NULL OR id_membre = ?) AND cible = ?
			ORDER BY intitule;', (int)$id_membre, $cible);
	}

	/**
	 * Lancer une recherche enregistrée
	 */
	public function search($id, $force_select = null)
	{
		$search = $this->get($id);

		if (!$search)
		{
			return false;
		}

		if ($search->type == self::TYPE_JSON)
		{
			$search->contenu = $this->buildQuery($search->cible, $search->query, $search->order, $search->desc, $search->limit);
		}

		return $this->searchSQL($search->cible, $search->contenu, $force_select);
	}

	/**
	 * Renvoie la liste des colonnes d'une cible
	 */
	public function getColumns($target)
	{







|










|


|







135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
			WHERE (id_membre IS NULL OR id_membre = ?) AND cible = ?
			ORDER BY intitule;', (int)$id_membre, $cible);
	}

	/**
	 * Lancer une recherche enregistrée
	 */
	public function search($id, array $force_select = null, $no_limit = false)
	{
		$search = $this->get($id);

		if (!$search)
		{
			return false;
		}

		if ($search->type == self::TYPE_JSON)
		{
			$search->contenu = $this->buildQuery($search->cible, $search->query, $search->order, $search->desc, $no_limit ? 10000 : $search->limit);
		}

		return $this->searchSQL($search->cible, $search->contenu, $force_select, $no_limit);
	}

	/**
	 * Renvoie la liste des colonnes d'une cible
	 */
	public function getColumns($target)
	{
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414







415
416
417
418
419
420
421

		return $sql_query;
	}

	/**
	 * Lancer une recherche SQL
	 */
	public function searchSQL($target, $query, $force_select = null)
	{
		if (!in_array($target, self::TARGETS, true))
		{
			throw new \InvalidArgumentException('Cible inconnue : ' . $target);
		}

		if ($force_select)
		{
			$query = preg_replace('/^\s*SELECT.*FROM\s+/Ui', 'SELECT ' . $force_select . ' FROM ', $query);
		}

		if (!preg_match('/LIMIT\s+\d+/i', $query))
		{
			$query = preg_replace('/;?\s*$/', '', $query);
			$query .= ' LIMIT 100';
		}

		try {
			return DB::getInstance()->userSelectGet($query);
		}
		catch (\Exception $e) {
			throw new UserException('Erreur dans la requête : ' . $e->getMessage());







		}
	}

	public function schema($target)
	{
		$db = DB::getInstance();








|






|

|


|









|
>
>
>
>
>
>
>







385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428

		return $sql_query;
	}

	/**
	 * Lancer une recherche SQL
	 */
	public function searchSQL($target, $query, array $force_select = null, $no_limit = false)
	{
		if (!in_array($target, self::TARGETS, true))
		{
			throw new \InvalidArgumentException('Cible inconnue : ' . $target);
		}

		if (null !== $force_select)
		{
			$query = preg_replace('/^\s*SELECT.*FROM\s+/Ui', 'SELECT ' . implode(', ', $force_select) . ' FROM ', $query);
		}

		if (!$no_limit && !preg_match('/LIMIT\s+\d+/i', $query))
		{
			$query = preg_replace('/;?\s*$/', '', $query);
			$query .= ' LIMIT 100';
		}

		try {
			return DB::getInstance()->userSelectGet($query);
		}
		catch (\Exception $e) {
			$message = 'Erreur dans la requête : ' . $e->getMessage();

			if (null !== $force_select)
			{
				$message .= "\nVérifiez que votre requête sélectionne bien les colonnes suivantes : " . implode(', ', $force_select);
			}

			throw new UserException($message);
		}
	}

	public function schema($target)
	{
		$db = DB::getInstance();

Modified src/www/admin/membres/message_collectif.php from [4372383f21] to [e6c89479ee].

18
19
20
21
22
23
24

25
26


27


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    {
        if ($match[1] == 'categorie')
        {
            $recipients = $membres->listAllByCategory($match[2], true);
        }
        else
        {

            $recipients = $recherche->search($match[2], 'id, email');
        }





        if (!count($recipients) || !isset($recipients[0]->email))
        {
            $form->addError('Aucun membre dans la liste.');
        }
    }
    else
    {
        throw new UserException('Destinataires invalides : ' . f('recipients'));
    }

    if (!$form->hasErrors())
    {
        try {
            $membres->sendMessage($recipients, f('sujet'),
                f('message'), (bool) f('copie'));







>
|
|
>
>
|
>
>
|






|







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    {
        if ($match[1] == 'categorie')
        {
            $recipients = $membres->listAllByCategory($match[2], true);
        }
        else
        {
            try {
                $recipients = $recherche->search($match[2], ['id', 'email'], true);
            }
            catch (UserException $e) {
                $form->addError($e->getMessage());
            }
        }

        if (isset($recipients) && (!count($recipients) || !isset($recipients[0]->email)))
        {
            $form->addError('Aucun membre dans la liste.');
        }
    }
    else
    {
        $form->addErrror('Destinataires invalides : ' . f('recipients'));
    }

    if (!$form->hasErrors())
    {
        try {
            $membres->sendMessage($recipients, f('sujet'),
                f('message'), (bool) f('copie'));