2015-09-01 16:12:52 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2020-08-24 15:54:25 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-09-01 16:12:52 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-10-05 21:54:56 +03:00
|
|
|
*
|
2015-09-01 16:12:52 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Core\Command\Maintenance\Mimetype;
|
|
|
|
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\Files\IMimeTypeDetector;
|
|
|
|
use OCP\Files\IMimeTypeLoader;
|
2015-09-01 16:12:52 +03:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
2019-11-22 22:52:10 +03:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2015-09-01 16:12:52 +03:00
|
|
|
|
|
|
|
class UpdateDB extends Command {
|
2020-04-10 17:54:27 +03:00
|
|
|
public const DEFAULT_MIMETYPE = 'application/octet-stream';
|
2015-09-01 16:12:52 +03:00
|
|
|
|
|
|
|
/** @var IMimeTypeDetector */
|
|
|
|
protected $mimetypeDetector;
|
|
|
|
|
|
|
|
/** @var IMimeTypeLoader */
|
|
|
|
protected $mimetypeLoader;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
IMimeTypeDetector $mimetypeDetector,
|
|
|
|
IMimeTypeLoader $mimetypeLoader
|
|
|
|
) {
|
|
|
|
parent::__construct();
|
|
|
|
$this->mimetypeDetector = $mimetypeDetector;
|
|
|
|
$this->mimetypeLoader = $mimetypeLoader;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function configure() {
|
|
|
|
$this
|
|
|
|
->setName('maintenance:mimetype:update-db')
|
|
|
|
->setDescription('Update database mimetypes and update filecache')
|
|
|
|
->addOption(
|
|
|
|
'repair-filecache',
|
|
|
|
null,
|
|
|
|
InputOption::VALUE_NONE,
|
|
|
|
'Repair filecache for all mimetypes, not just new ones'
|
|
|
|
)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:54:51 +03:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2015-09-01 16:12:52 +03:00
|
|
|
$mappings = $this->mimetypeDetector->getAllMappings();
|
|
|
|
|
|
|
|
$totalFilecacheUpdates = 0;
|
|
|
|
$totalNewMimetypes = 0;
|
|
|
|
|
|
|
|
foreach ($mappings as $ext => $mimetypes) {
|
|
|
|
if ($ext[0] === '_') {
|
|
|
|
// comment
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$mimetype = $mimetypes[0];
|
|
|
|
$existing = $this->mimetypeLoader->exists($mimetype);
|
|
|
|
// this will add the mimetype if it didn't exist
|
|
|
|
$mimetypeId = $this->mimetypeLoader->getId($mimetype);
|
|
|
|
|
|
|
|
if (!$existing) {
|
|
|
|
$output->writeln('Added mimetype "'.$mimetype.'" to database');
|
|
|
|
$totalNewMimetypes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$existing || $input->getOption('repair-filecache')) {
|
|
|
|
$touchedFilecacheRows = $this->mimetypeLoader->updateFilecache($ext, $mimetypeId);
|
|
|
|
if ($touchedFilecacheRows > 0) {
|
|
|
|
$output->writeln('Updated '.$touchedFilecacheRows.' filecache rows for mimetype "'.$mimetype.'"');
|
|
|
|
}
|
|
|
|
$totalFilecacheUpdates += $touchedFilecacheRows;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$output->writeln('Added '.$totalNewMimetypes.' new mimetypes');
|
|
|
|
$output->writeln('Updated '.$totalFilecacheUpdates.' filecache rows');
|
2020-06-26 15:54:51 +03:00
|
|
|
return 0;
|
2015-09-01 16:12:52 +03:00
|
|
|
}
|
|
|
|
}
|