Overview
Comment: | Method to delete linked files |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dev |
Files: | files | file ages | folders |
SHA1: |
e90ff81d47e38e88ff3cac2ca976c86d |
User & Date: | bohwaz on 2020-09-16 15:18:31 |
Other Links: | branch diff | manifest | tags |
Context
2020-09-16
| ||
15:19 | Removal of accounting transactions check-in: a4353b8d3f user: bohwaz tags: dev | |
15:18 | Method to delete linked files check-in: e90ff81d47 user: bohwaz tags: dev | |
01:53 | Not used anymore check-in: 5e35f1ac90 user: bohwaz tags: dev | |
Changes
Modified src/include/lib/Garradin/Fichiers.php from [f0028d1e21] to [90881d3690].
︙ | ︙ | |||
70 71 72 73 74 75 76 | return max(self::$allowed_thumb_sizes); } /** * Constructeur de l'objet pour un fichier * @param integer $id Numéro unique du fichier */ | | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | return max(self::$allowed_thumb_sizes); } /** * Constructeur de l'objet pour un fichier * @param integer $id Numéro unique du fichier */ public function __construct(int $id, ?iterable $data = null) { if (is_null($data)) { $data = DB::getInstance()->first('SELECT fichiers.*, fc.hash, fc.taille, strftime(\'%s\', datetime) AS datetime FROM fichiers INNER JOIN fichiers_contenu AS fc ON fc.id = fichiers.id_contenu WHERE fichiers.id = ?;', (int)$id); |
︙ | ︙ | |||
232 233 234 235 236 237 238 | * Supprime le fichier * @return boolean TRUE en cas de succès */ public function remove() { $db = DB::getInstance(); $db->begin(); | | | | | 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | * Supprime le fichier * @return boolean TRUE en cas de succès */ public function remove() { $db = DB::getInstance(); $db->begin(); $db->delete('fichiers_' . self::LIEN_COMPTA, 'fichier = ?', (int)$this->id); $db->delete('fichiers_' . self::LIEN_WIKI, 'fichier = ?', (int)$this->id); $db->delete('fichiers_' . self::LIEN_MEMBRES, 'fichier = ?', (int)$this->id); $db->delete('fichiers', 'id = ?', (int)$this->id); // Suppression du contenu s'il n'est pas utilisé par un autre fichier if (!$db->firstColumn('SELECT 1 FROM fichiers WHERE id_contenu = ? AND id != ? LIMIT 1;', (int)$this->id_contenu, (int)$this->id)) { |
︙ | ︙ | |||
619 620 621 622 623 624 625 626 627 628 629 630 631 632 | { $file->url = self::_getURL($file->id, $file->nom); $file->thumb = $file->image ? self::_getURL($file->id, $file->nom, 200) : false; } return $files; } /** * Enlève d'une liste de fichiers ceux qui sont mentionnés dans un texte wiki * @param array $files Liste de fichiers * @param string $text texte wiki * @return array Un tableau qui ne contient pas les fichiers mentionnés dans $text */ | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | { $file->url = self::_getURL($file->id, $file->nom); $file->thumb = $file->image ? self::_getURL($file->id, $file->nom, 200) : false; } return $files; } static public function deleteLinkedFiles($type, int $id) { static $check = [self::LIEN_MEMBRES, self::LIEN_WIKI, self::LIEN_COMPTA]; if (!in_array($type, $check)) { throw new \LogicException('Type de lien de fichier inconnu.'); } $files = DB::getInstance()->delete('fichiers_' . $type, 'id = ?', $id); return self::deleteUnlinkedFiles(); } static public function deleteUnlinkedFiles() { static $all = [self::LIEN_MEMBRES, self::LIEN_WIKI, self::LIEN_COMPTA]; $list = DB::getInstance()->iterate(sprintf('SELECT f.id, f.id_contenu FROM fichiers f LEFT JOIN fichiers_%s a ON a.fichier = f.id LEFT JOIN fichiers_%s b ON b.fichier = f.id LEFT JOIN fichiers_%s c ON c.fichier = f.id WHERE a.id IS NULL AND b.id IS NULL AND c.id IS NULL;', self::LIEN_MEMBRES, self::LIEN_WIKI, self::LIEN_COMPTA)); foreach ($list as $file) { $f = new Fichiers($file->id, (array) $file); $f->remove(); } } /** * Enlève d'une liste de fichiers ceux qui sont mentionnés dans un texte wiki * @param array $files Liste de fichiers * @param string $text texte wiki * @return array Un tableau qui ne contient pas les fichiers mentionnés dans $text */ |
︙ | ︙ |