Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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: 09.10.2024, 12:55 - Dateigröße: 3.92 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\db\driver\driver_interface
023      */
024      protected $db;
025   
026      /**
027      * phpBB root path
028      * @var string
029      */
030      protected $phpbb_root_path;
031   
032      /**
033      * Constructor
034      *
035      * @param \phpbb\user $user The user object (used to get language information)
036      * @param \phpbb\db\driver\driver_interface $db Database connection
037      * @param string $phpbb_root_path Root path
038      */
039      public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, $phpbb_root_path)
040      {
041          $this->db = $db;
042          $this->phpbb_root_path = $phpbb_root_path;
043   
044          parent::__construct($user);
045      }
046   
047      /**
048      * Sets the command name and description
049      *
050      * @return null
051      */
052      protected function configure()
053      {
054          $this
055              ->setName('thumbnail:delete')
056              ->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_DELETE'))
057          ;
058      }
059   
060      /**
061      * Executes the command thumbnail:delete.
062      *
063      * Deletes all existing thumbnails and updates the database accordingly.
064      *
065      * @param InputInterface $input The input stream used to get the argument and verbose option.
066      * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
067      *
068      * @return int 0 if all is ok, 1 if a thumbnail couldn't be deleted.
069      */
070      protected function execute(InputInterface $input, OutputInterface $output)
071      {
072          $io = new SymfonyStyle($input, $output);
073   
074          $io->section($this->user->lang('CLI_THUMBNAIL_DELETING'));
075   
076          $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
077              FROM ' . ATTACHMENTS_TABLE . '
078              WHERE thumbnail = 1';
079          $result = $this->db->sql_query($sql);
080          $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails');
081          $this->db->sql_freeresult($result);
082   
083          if ($nb_missing_thumbnails === 0)
084          {
085              $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE'));
086              return 0;
087          }
088   
089          $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype
090              FROM ' . ATTACHMENTS_TABLE . '
091              WHERE thumbnail = 1';
092          $result = $this->db->sql_query($sql);
093   
094          $progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output);
095   
096          $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETING'));
097   
098          $progress->start();
099   
100          $thumbnail_deleted = array();
101          $return = 0;
102          while ($row = $this->db->sql_fetchrow($result))
103          {
104              $thumbnail_path = $this->phpbb_root_path . 'files/thumb_' . $row['physical_filename'];
105   
106              if (@unlink($thumbnail_path))
107              {
108                  $thumbnail_deleted[] = $row['attach_id'];
109   
110                  if (sizeof($thumbnail_deleted) === 250)
111                  {
112                      $this->commit_changes($thumbnail_deleted);
113                      $thumbnail_deleted = array();
114                  }
115   
116                  $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename']));
117              }
118              else
119              {
120                  $return = 1;
121                  $progress->setMessage('<error>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</error>');
122              }
123   
124              $progress->advance();
125          }
126          $this->db->sql_freeresult($result);
127   
128          if (!empty($thumbnail_deleted))
129          {
130              $this->commit_changes($thumbnail_deleted);
131          }
132   
133          $progress->finish();
134   
135          $io->newLine(2);
136          $io->success($this->user->lang('CLI_THUMBNAIL_DELETING_DONE'));
137   
138          return $return;
139      }
140   
141      /**
142      * Commits the changes to the database
143      *
144      * @param array $thumbnail_deleted
145      */
146      protected function commit_changes(array $thumbnail_deleted)
147      {
148          $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
149                  SET thumbnail = 0
150                  WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_deleted);
151          $this->db->sql_query($sql);
152      }
153  }
154