Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

delete.php

Zuletzt modifiziert: 01.05.2026, 11:26 - Dateigröße: 4.10 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013  namespace phpbb\console\command\thumbnail;
 014   
 015  use Symfony\Component\Console\Input\InputInterface;
 016  use Symfony\Component\Console\Output\OutputInterface;
 017  use Symfony\Component\Console\Style\SymfonyStyle;
 018   
 019  class delete extends \phpbb\console\command\command
 020  {
 021      /**
 022      * @var \phpbb\config\config
 023      */
 024      protected $config;
 025   
 026      /**
 027      * @var \phpbb\db\driver\driver_interface
 028      */
 029      protected $db;
 030   
 031      /**
 032      * phpBB root path
 033      * @var string
 034      */
 035      protected $phpbb_root_path;
 036   
 037      /**
 038      * Constructor
 039      *
 040      * @param \config\config $config The config
 041      * @param \phpbb\user $user The user object (used to get language information)
 042      * @param \phpbb\db\driver\driver_interface $db Database connection
 043      * @param string $phpbb_root_path Root path
 044      */
 045      public function __construct(\phpbb\config\config $config, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, $phpbb_root_path)
 046      {
 047          $this->config = $config;
 048          $this->db = $db;
 049          $this->phpbb_root_path = $phpbb_root_path;
 050   
 051          parent::__construct($user);
 052      }
 053   
 054      /**
 055      * Sets the command name and description
 056      *
 057      * @return null
 058      */
 059      protected function configure()
 060      {
 061          $this
 062              ->setName('thumbnail:delete')
 063              ->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_DELETE'))
 064          ;
 065      }
 066   
 067      /**
 068      * Executes the command thumbnail:delete.
 069      *
 070      * Deletes all existing thumbnails and updates the database accordingly.
 071      *
 072      * @param InputInterface $input The input stream used to get the argument and verbose option.
 073      * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
 074      *
 075      * @return int 0 if all is ok, 1 if a thumbnail couldn't be deleted.
 076      */
 077      protected function execute(InputInterface $input, OutputInterface $output)
 078      {
 079          $io = new SymfonyStyle($input, $output);
 080   
 081          $io->section($this->user->lang('CLI_THUMBNAIL_DELETING'));
 082   
 083          $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
 084              FROM ' . ATTACHMENTS_TABLE . '
 085              WHERE thumbnail = 1';
 086          $result = $this->db->sql_query($sql);
 087          $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails');
 088          $this->db->sql_freeresult($result);
 089   
 090          if ($nb_missing_thumbnails === 0)
 091          {
 092              $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE'));
 093              return 0;
 094          }
 095   
 096          $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype
 097              FROM ' . ATTACHMENTS_TABLE . '
 098              WHERE thumbnail = 1';
 099          $result = $this->db->sql_query($sql);
 100   
 101          $progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output);
 102   
 103          $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETING'));
 104   
 105          $progress->start();
 106   
 107          $thumbnail_deleted = array();
 108          $return = 0;
 109          while ($row = $this->db->sql_fetchrow($result))
 110          {
 111              $thumbnail_path = $this->phpbb_root_path . $this->config['upload_path'] . '/thumb_' . $row['physical_filename'];
 112   
 113              if (@unlink($thumbnail_path))
 114              {
 115                  $thumbnail_deleted[] = $row['attach_id'];
 116   
 117                  if (count($thumbnail_deleted) === 250)
 118                  {
 119                      $this->commit_changes($thumbnail_deleted);
 120                      $thumbnail_deleted = array();
 121                  }
 122   
 123                  $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename']));
 124              }
 125              else
 126              {
 127                  $return = 1;
 128                  $progress->setMessage('<error>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</error>');
 129              }
 130   
 131              $progress->advance();
 132          }
 133          $this->db->sql_freeresult($result);
 134   
 135          if (!empty($thumbnail_deleted))
 136          {
 137              $this->commit_changes($thumbnail_deleted);
 138          }
 139   
 140          $progress->finish();
 141   
 142          $io->newLine(2);
 143          $io->success($this->user->lang('CLI_THUMBNAIL_DELETING_DONE'));
 144   
 145          return $return;
 146      }
 147   
 148      /**
 149      * Commits the changes to the database
 150      *
 151      * @param array $thumbnail_deleted
 152      */
 153      protected function commit_changes(array $thumbnail_deleted)
 154      {
 155          $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
 156                  SET thumbnail = 0
 157                  WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_deleted);
 158          $this->db->sql_query($sql);
 159      }
 160  }
 161