Comment: | Déplacement de la grosse majorité de la logique de DB dans KD2, suppression des méthodes simple* dépréciées |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dev |
Files: | files | file ages | folders |
SHA1: |
8cf95684983160d5b681b7a0c8ad5a08 |
User & Date: | bohwaz on 2017-06-30 05:42:55 |
Other Links: | branch diff | manifest | tags |
2017-07-03
| ||
07:30 | Modernisation objets comptes check-in: bbf4e7b183 user: bohwaz tags: dev | |
2017-06-30
| ||
05:42 | Déplacement de la grosse majorité de la logique de DB dans KD2, suppression des méthodes simple* dépréciées check-in: 8cf9568498 user: bohwaz tags: dev | |
2017-06-20
| ||
00:44 | Ajout signal édition membre cf [743d7e1483] check-in: 225b85cec2 user: bohwaz tags: dev | |
Modified src/include/lib/Garradin/Config.php from [db09fc48dc] to [12077bf319].
︙ | ︙ | |||
279 280 281 282 283 284 285 | if (!$champs->get($value)) { throw new UserException('Le champ '.$value.' n\'existe pas pour la configuration de '.$key); } // Vérification que le champ est unique pour l'identifiant if ($key == 'champ_identifiant' | | | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | if (!$champs->get($value)) { throw new UserException('Le champ '.$value.' n\'existe pas pour la configuration de '.$key); } // Vérification que le champ est unique pour l'identifiant if ($key == 'champ_identifiant' && !$db->firstColumn('SELECT (COUNT(DISTINCT '.$value.') = COUNT(*)) FROM membres WHERE '.$value.' IS NOT NULL AND '.$value.' != \'\';')) { throw new UserException('Le champ '.$value.' comporte des doublons et ne peut donc pas servir comme identifiant pour la connexion.'); } break; } case 'categorie_cotisations': |
︙ | ︙ |
Modified src/include/lib/Garradin/Cotisations.php from [afff89c062] to [8bdc434117].
︙ | ︙ | |||
63 64 65 66 67 68 69 | { throw new UserException('La date de fin est invalide.'); } } if (isset($data['id_categorie_compta'])) { | | | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | { throw new UserException('La date de fin est invalide.'); } } if (isset($data['id_categorie_compta'])) { if ($data['id_categorie_compta'] != 0 && !$db->firstColumn('SELECT 1 FROM compta_categories WHERE id = ?;', (int) $data['id_categorie_compta'])) { throw new UserException('Catégorie comptable inconnue'); } $data['id_categorie_compta'] = (int) $data['id_categorie_compta']; } } |
︙ | ︙ |
Modified src/include/lib/Garradin/DB.php from [e4161210dd] to [ef10557379].
1 2 3 4 | <?php namespace Garradin; | > > | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | < < < < < < | < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | <?php namespace Garradin; use KD2\DB_SQLite3; class DB extends DB_SQLite3 { /** * Application ID pour SQLite * @link https://www.sqlite.org/pragma.html#pragma_application_id */ const APPID = 0x5da2d811; static protected $_instance = null; static public function getInstance($create = false) { return self::$_instance ?: self::$_instance = new DB($create); } private function __clone() { // Désactiver le clonage, car on ne veut qu'une seule instance } public function __construct($create = false) { $flags = \SQLITE3_OPEN_READWRITE; if ($create) { $flags |= \SQLITE3_OPEN_CREATE; } parent::__construct(DB_FILE, $flags); // Ne pas se connecter ici, on ne se connectera que quand une requête sera faite } public function connect() { parent::connect(); // Activer les contraintes des foreign keys $this->db->exec('PRAGMA foreign_keys = ON;'); $this->db->createFunction('transliterate_to_ascii', ['Garradin\Utils', 'transliterateToAscii']); } /** * Import a file containing SQL commands * Allows to use the statement ".import other_file.sql" to load other files * @param string $file Path to file containing SQL commands * @return boolean */ public function import($file) { $sql = file_get_contents($file); $dir = dirname($file); $sql = preg_replace_callback('/^\.import (.+\.sql)$/m', function ($match) use ($dir) { return file_get_contents($dir . DIRECTORY_SEPARATOR . $match[1]) . "\n"; }, $sql); return $this->db->exec($sql); } } |
Modified src/include/lib/Garradin/Membres.php from [c8a6c9bf0d] to [dac59ded18].
︙ | ︙ | |||
210 211 212 213 214 215 216 | if ($db->firstColumn('SELECT 1 FROM wiki_revisions WHERE id_auteur = ?;', (int)$id) || $db->firstColumn('SELECT 1 FROM compta_journal WHERE id_auteur = ?;', (int)$id) || $db->firstColumn('SELECT 1 FROM compta_rapprochement WHERE id_auteur = ?;', (int)$id) || $db->firstColumn('SELECT 1 FROM membres_operations WHERE id_membre = ?;', (int)$id) || $db->firstColumn('SELECT 1 FROM cotisations_membres WHERE id_membre = ?;', (int)$id) || $db->firstColumn('SELECT 1 FROM rappels_envoyes WHERE id_membre = ?;', (int)$id) || $db->firstColumn('SELECT 1 FROM fichiers_membres WHERE id = ?;', (int)$id)) | | | 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | if ($db->firstColumn('SELECT 1 FROM wiki_revisions WHERE id_auteur = ?;', (int)$id) || $db->firstColumn('SELECT 1 FROM compta_journal WHERE id_auteur = ?;', (int)$id) || $db->firstColumn('SELECT 1 FROM compta_rapprochement WHERE id_auteur = ?;', (int)$id) || $db->firstColumn('SELECT 1 FROM membres_operations WHERE id_membre = ?;', (int)$id) || $db->firstColumn('SELECT 1 FROM cotisations_membres WHERE id_membre = ?;', (int)$id) || $db->firstColumn('SELECT 1 FROM rappels_envoyes WHERE id_membre = ?;', (int)$id) || $db->firstColumn('SELECT 1 FROM fichiers_membres WHERE id = ?;', (int)$id)) # FIXME || $db->firstColumn('SELECT 1 FROM wiki_suivi WHERE id_membre = ?;', false, (int)$id)) { throw new UserException('Le numéro n\'est pas modifiable pour ce membre car des contenus sont liés à ce numéro de membre (wiki, compta, etc.).'); } } if (!empty($data['passe']) && trim($data['passe'])) { |
︙ | ︙ |
Modified src/include/lib/Garradin/Membres/Categories.php from [04d2da3478] to [7cda995183].
︙ | ︙ | |||
100 101 102 103 104 105 106 | $config = Config::getInstance(); if ($id == $config->get('categorie_membres')) { throw new UserException('Il est interdit de supprimer la catégorie définie par défaut dans la configuration.'); } | | | 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | $config = Config::getInstance(); if ($id == $config->get('categorie_membres')) { throw new UserException('Il est interdit de supprimer la catégorie définie par défaut dans la configuration.'); } if ($db->firstColumn('SELECT 1 FROM membres WHERE id_categorie = ?;', (int)$id)) { throw new UserException('La catégorie contient encore des membres, il n\'est pas possible de la supprimer.'); } $db->update( 'wiki_pages', [ |
︙ | ︙ |
Modified src/include/lib/Garradin/Membres/Champs.php from [ddca1d72f4] to [d384371350].
︙ | ︙ | |||
42 43 44 45 46 47 48 | 'type', 'title', 'help', 'editable', 'list_row', 'mandatory', 'private', | | < | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 'type', 'title', 'help', 'editable', 'list_row', 'mandatory', 'private', 'options' ]; static protected $presets = null; public function __toString() { return Utils::write_ini_string($this->champs); |
︙ | ︙ | |||
116 117 118 119 120 121 122 | public function getTypes() { return $this->types; } public function get($champ, $key = null) { | < < < < < | 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | public function getTypes() { return $this->types; } public function get($champ, $key = null) { if (!property_exists($this->champs, $champ)) return null; if ($key !== null) { if (property_exists($this->champs->$champ, $key)) return $this->champs->$champ->$key; |
︙ | ︙ |
Modified src/include/lib/Garradin/Membres/Cotisations.php from [720be42932] to [df3fbb87a3].
︙ | ︙ | |||
22 23 24 25 26 27 28 | if (empty($data['date']) || !Utils::checkDate($data['date'])) { throw new UserException('Date vide ou invalide.'); } if (empty($data['id_cotisation']) | | | | < | 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | if (empty($data['date']) || !Utils::checkDate($data['date'])) { throw new UserException('Date vide ou invalide.'); } if (empty($data['id_cotisation']) || !$db->firstColumn('SELECT 1 FROM cotisations WHERE id = ?;', (int) $data['id_cotisation'])) { throw new UserException('Cotisation inconnue.'); } $data['id_cotisation'] = (int) $data['id_cotisation']; if (empty($data['id_membre']) || !$db->firstColumn('SELECT 1 FROM membres WHERE id = ?;', (int) $data['id_membre'])) { throw new UserException('Membre inconnu ou invalide.'); } $data['id_membre'] = (int) $data['id_membre']; if ($compta) { if (!isset($data['moyen_paiement']) || trim($data['moyen_paiement']) === '') { throw new UserException('Moyen de paiement inconnu ou invalide.'); } if ($data['moyen_paiement'] != 'ES') { if (trim($data['banque']) == '') { throw new UserException('Le compte bancaire choisi est invalide.'); } if (!$db->firstColumn('SELECT 1 FROM compta_comptes_bancaires WHERE id = ?;', $data['banque'])) { throw new UserException('Le compte bancaire choisi n\'existe pas.'); } } if (!isset($data['montant']) || !is_numeric($data['montant']) || $data['montant'] < 0) { |
︙ | ︙ |
Modified src/include/lib/Garradin/Plugin.php from [12a29cbd97] to [778f6c082f].
︙ | ︙ | |||
284 285 286 287 288 289 290 | } $db = DB::getInstance(); // Signaux exclusifs, qui ne peuvent être attribués qu'à un seul plugin if (strpos($signal, 'boucle.') === 0) { | | | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | } $db = DB::getInstance(); // Signaux exclusifs, qui ne peuvent être attribués qu'à un seul plugin if (strpos($signal, 'boucle.') === 0) { $registered = $db->firstColumn('SELECT plugin FROM plugins_signaux WHERE signal = ? AND plugin != ?;', $signal, $this->id); if ($registered) { throw new \LogicException('Le signal ' . $name . ' est exclusif et déjà associé au plugin "'.$registered.'"'); } } |
︙ | ︙ | |||
306 307 308 309 310 311 312 | /** * Liste des plugins installés (en DB) * @return array Liste des plugins triés par nom */ static public function listInstalled() { $db = DB::getInstance(); | | | 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | /** * Liste des plugins installés (en DB) * @return array Liste des plugins triés par nom */ static public function listInstalled() { $db = DB::getInstance(); $plugins = $db->getGrouped('SELECT id, * FROM plugins ORDER BY nom;'); $system = explode(',', PLUGINS_SYSTEM); foreach ($plugins as &$row) { $row->system = in_array($row->id, $system); } |
︙ | ︙ |
Modified src/include/lib/Garradin/Rappels.php from [c017a2b4d9] to [15cdccc907].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * @return void */ protected function _checkFields(&$data) { $db = DB::getInstance(); if (empty($data['id_cotisation']) | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * @return void */ protected function _checkFields(&$data) { $db = DB::getInstance(); if (empty($data['id_cotisation']) || !$db->firstColumn('SELECT 1 FROM cotisations WHERE id = ?;', (int) $data['id_cotisation'])) { throw new UserException('Cotisation inconnue.'); } $data['id_cotisation'] = (int) $data['id_cotisation']; if ((trim($data['delai']) === '') || !is_numeric($data['delai'])) |
︙ | ︙ |
Modified src/include/lib/Garradin/Rappels_Envoyes.php from [4dd5416887] to [4cb0920949].
︙ | ︙ | |||
23 24 25 26 27 28 29 | * @return void */ protected function _checkFields(&$data) { $db = DB::getInstance(); if (!array_key_exists('id_rappel', $data) | | | | | 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 48 49 50 51 52 53 | * @return void */ protected function _checkFields(&$data) { $db = DB::getInstance(); if (!array_key_exists('id_rappel', $data) || (!is_null($data['id_rappel']) && (empty($data['id_rappel']) || !$db->firstColumn('SELECT 1 FROM rappels WHERE id = ?;', (int) $data['id_rappel'])))) { throw new \LogicException('ID rappel non fourni ou inexistant dans la table rappels'); } if (isset($data['id_cotisation'])) { if (!$db->firstColumn('SELECT 1 FROM cotisations WHERE id = ?;', (int) $data['id_cotisation'])) { throw new UserException('Cotisation inconnue.'); } $data['id_cotisation'] = (int) $data['id_cotisation']; } if (empty($data['id_membre']) || !$db->firstColumn('SELECT 1 FROM membres WHERE id = ?;', (int) $data['id_membre'])) { throw new UserException('Membre inconnu.'); } $data['id_membre'] = (int) $data['id_membre']; if (empty($data['media']) || !is_numeric($data['media']) |
︙ | ︙ | |||
95 96 97 98 99 100 101 | /** * Renvoie les données sur un rappel * @param integer $id Numéro du rappel * @return array Données du rappel */ public function get($id) { | | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | /** * Renvoie les données sur un rappel * @param integer $id Numéro du rappel * @return array Données du rappel */ public function get($id) { return DB::getInstance()->first('SELECT * FROM rappels_envoyes WHERE id = ?;', (int)$id); } /** * Remplacer les tags dans le contenu/sujet du mail * @param string $content Chaîne à traiter * @param array $data Données supplémentaires à utiliser comme tags (tableau associatif) * @return string $content dont les tags ont été remplacés par le contenu correct |
︙ | ︙ | |||
203 204 205 206 207 208 209 | /** * Nombre de rappels pour une cotisation donnée * @param integer $id Numéro de la cotisation * @return integer Nombre de rappels envoyés */ public function countForCotisation($id) { | | | | 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | /** * Nombre de rappels pour une cotisation donnée * @param integer $id Numéro de la cotisation * @return integer Nombre de rappels envoyés */ public function countForCotisation($id) { return DB::getInstance()->firstColumn('SELECT COUNT(*) FROM rappels_envoyes WHERE id_rappel IN (SELECT id FROM rappels WHERE id_cotisation = ?);', (int)$id); } /** * Liste des rappels envoyés pour un rappel automatique * @param integer $id Numéro du rappel * @param integer $page Numéro de page de liste * @return array Liste des rappels envoyés |
︙ | ︙ | |||
230 231 232 233 234 235 236 | /** * Nombre de rappels envoyés pour un rappel automatique * @param integer $id Numéro du rappel * @return integer Nombre de rappels envoyés pour ce rappel */ public function countForRappel($id) { | | | | 230 231 232 233 234 235 236 237 238 239 240 | /** * Nombre de rappels envoyés pour un rappel automatique * @param integer $id Numéro du rappel * @return integer Nombre de rappels envoyés pour ce rappel */ public function countForRappel($id) { return DB::getInstance()->firstColumn('SELECT COUNT(*) FROM rappels_envoyes WHERE id_rappel = ?;', (int)$id); } } |
Modified src/include/lib/Garradin/Sauvegarde.php from [8cfee07aa3] to [e1a44c08fc].
︙ | ︙ | |||
403 404 405 406 407 408 409 | /** * Taille occupée par les fichiers dans la base de données * @return integer Taille en octets */ public function getDBFilesSize() { $db = DB::getInstance(); | | | 403 404 405 406 407 408 409 410 411 412 | /** * Taille occupée par les fichiers dans la base de données * @return integer Taille en octets */ public function getDBFilesSize() { $db = DB::getInstance(); return (int) $db->firstColumn('SELECT SUM(taille) FROM fichiers_contenu;'); } } |
Modified src/include/lib/Garradin/Wiki.php from [a4ede7290f] to [a7fb957d19].
︙ | ︙ | |||
470 471 472 473 474 475 476 | { $db = DB::getInstance(); $flat = [ (object) [ 'id' => 0, 'parent' => null, 'titre' => 'Racine', | | | | | 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | { $db = DB::getInstance(); $flat = [ (object) [ 'id' => 0, 'parent' => null, 'titre' => 'Racine', 'children' => $db->getGrouped('SELECT id, parent, titre FROM wiki_pages WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;', 0) ] ]; $max = 0; do { $parent = $db->get('SELECT parent FROM wiki_pages WHERE id = ? LIMIT 1;', (int)$id); $flat[$id] = (object) [ 'id' => $id, 'parent' => $id ? (int)$parent : null, 'titre' => $id ? $this->getTitle($id) : 'Racine', 'children' => $db->getGrouped('SELECT id, parent, titre FROM wiki_pages WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;', (int)$id) ]; $id = (int)$parent; } while ($id != 0 && $max++ < 20); |
︙ | ︙ |
Modified src/www/admin/membres/recherche.php from [88e89e6801] to [d54744adc2].
︙ | ︙ | |||
43 44 45 46 47 48 49 | { Utils::redirect('/admin/membres/fiche.php?id=' . (int)$result[0]->id); } } $champs_liste = $champs->getList(); | < | < < | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | { Utils::redirect('/admin/membres/fiche.php?id=' . (int)$result[0]->id); } } $champs_liste = $champs->getList(); $champs_liste->id = (object) ['title' => 'Numéro unique', 'type' => 'number']; $champs_entete = $champs->getListedFields(); if (!array_key_exists($champ, $champs_entete)) { $champs_entete = array_merge( [$champ => $champs_liste->$champ], |
︙ | ︙ |