[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\console\command\thumbnail; 15 16 use Symfony\Component\Console\Input\InputInterface; 17 use Symfony\Component\Console\Output\OutputInterface; 18 use Symfony\Component\Console\Style\SymfonyStyle; 19 20 class generate extends \phpbb\console\command\command 21 { 22 /** 23 * @var \phpbb\config\config 24 */ 25 protected $config; 26 27 /** 28 * @var \phpbb\db\driver\driver_interface 29 */ 30 protected $db; 31 32 /** 33 * @var \phpbb\cache\service 34 */ 35 protected $cache; 36 37 /** 38 * phpBB root path 39 * @var string 40 */ 41 protected $phpbb_root_path; 42 43 /** 44 * PHP extension. 45 * 46 * @var string 47 */ 48 protected $php_ext; 49 50 /** 51 * Constructor 52 * 53 * @param \config\config $config The config 54 * @param \phpbb\user $user The user object (used to get language information) 55 * @param \phpbb\db\driver\driver_interface $db Database connection 56 * @param \phpbb\cache\service $cache The cache service 57 * @param string $phpbb_root_path Root path 58 * @param string $php_ext PHP extension 59 */ 60 public function __construct(\phpbb\config\config $config, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $phpbb_root_path, $php_ext) 61 { 62 $this->config = $config; 63 $this->db = $db; 64 $this->cache = $cache; 65 $this->phpbb_root_path = $phpbb_root_path; 66 $this->php_ext = $php_ext; 67 68 parent::__construct($user); 69 } 70 71 /** 72 * Sets the command name and description 73 * 74 * @return null 75 */ 76 protected function configure() 77 { 78 $this 79 ->setName('thumbnail:generate') 80 ->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_GENERATE')) 81 ; 82 } 83 84 /** 85 * Executes the command thumbnail:generate. 86 * 87 * Generate a thumbnail for all attachments which need one and don't have it yet. 88 * 89 * @param InputInterface $input The input stream used to get the argument and verboe option. 90 * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. 91 * 92 * @return int 0. 93 */ 94 protected function execute(InputInterface $input, OutputInterface $output) 95 { 96 $io = new SymfonyStyle($input, $output); 97 98 $io->section($this->user->lang('CLI_THUMBNAIL_GENERATING')); 99 100 $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails 101 FROM ' . ATTACHMENTS_TABLE . ' 102 WHERE thumbnail = 0'; 103 $result = $this->db->sql_query($sql); 104 $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails'); 105 $this->db->sql_freeresult($result); 106 107 if ($nb_missing_thumbnails === 0) 108 { 109 $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE')); 110 return 0; 111 } 112 113 $extensions = $this->cache->obtain_attach_extensions(true); 114 115 $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype 116 FROM ' . ATTACHMENTS_TABLE . ' 117 WHERE thumbnail = 0'; 118 $result = $this->db->sql_query($sql); 119 120 if (!function_exists('create_thumbnail')) 121 { 122 require($this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext); 123 } 124 125 $progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output); 126 127 $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATING')); 128 129 $progress->start(); 130 131 $thumbnail_created = array(); 132 while ($row = $this->db->sql_fetchrow($result)) 133 { 134 if (isset($extensions[$row['extension']]['display_cat']) && $extensions[$row['extension']]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE) 135 { 136 $source = $this->phpbb_root_path . $this->config['upload_path'] . '/' . $row['physical_filename']; 137 $destination = $this->phpbb_root_path . $this->config['upload_path'] . '/thumb_' . $row['physical_filename']; 138 139 if (create_thumbnail($source, $destination, $row['mimetype'])) 140 { 141 $thumbnail_created[] = (int) $row['attach_id']; 142 143 if (count($thumbnail_created) === 250) 144 { 145 $this->commit_changes($thumbnail_created); 146 $thumbnail_created = array(); 147 } 148 149 $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); 150 } 151 else 152 { 153 $progress->setMessage('<info>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</info>'); 154 } 155 } 156 157 $progress->advance(); 158 } 159 $this->db->sql_freeresult($result); 160 161 if (!empty($thumbnail_created)) 162 { 163 $this->commit_changes($thumbnail_created); 164 } 165 166 $progress->finish(); 167 168 $io->newLine(2); 169 $io->success($this->user->lang('CLI_THUMBNAIL_GENERATING_DONE')); 170 171 return 0; 172 } 173 174 /** 175 * Commits the changes to the database 176 * 177 * @param array $thumbnail_created 178 */ 179 protected function commit_changes(array $thumbnail_created) 180 { 181 $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' 182 SET thumbnail = 1 183 WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_created); 184 $this->db->sql_query($sql); 185 } 186 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |