Move maintenance:mimetypesjs to sublocation, cleanup code

This commit is contained in:
Robin McCorkell 2015-09-01 14:09:15 +01:00
parent 9e9ffb1356
commit 79fceeff33
2 changed files with 26 additions and 19 deletions

View File

@ -18,27 +18,35 @@
*
*/
namespace OC\Core\Command\Maintenance;
namespace OC\Core\Command\Maintenance\Mimetype;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class MimeTypesJS extends Command {
use OCP\Files\IMimeTypeDetector;
class UpdateJS extends Command {
/** @var IMimeTypeDetector */
protected $mimetypeDetector;
public function __construct(
IMimeTypeDetector $mimetypeDetector
) {
parent::__construct();
$this->mimetypeDetector = $mimetypeDetector;
}
protected function configure() {
$this
->setName('maintenance:mimetypesjs')
->setName('maintenance:mimetype:update-js')
->setDescription('Update mimetypelist.js');
}
protected function execute(InputInterface $input, OutputInterface $output) {
// Fetch all the aliases
$aliases = json_decode(file_get_contents(\OC::$SERVERROOT . '/config/mimetypealiases.dist.json'), true);
if (file_exists(\OC::$SERVERROOT . '/config/mimetypealiases.json')) {
$custom = get_object_vars(json_decode(file_get_contents(\OC::$SERVERROOT . '/config/mimetypealiases.json')));
$aliases = array_merge($aliases, $custom);
}
$aliases = $this->mimetypeDetector->getAllAliases();
// Remove comments
$keys = array_filter(array_keys($aliases), function($k) {
@ -49,23 +57,22 @@ class MimeTypesJS extends Command {
}
// Fetch all files
$dir = new \DirectoryIterator(dirname(__DIR__) . '/../img/filetypes');
$dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes');
$files = [];
foreach($dir as $fileInfo) {
if ($fileInfo->isFile()) {
$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
$files[] = $file;
}
if ($fileInfo->isFile()) {
$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
$files[] = $file;
}
}
//Remove duplicates
$files = array_values(array_unique($files));
// Fetch all themes!
$themes = [];
$dirs = new \DirectoryIterator(dirname(__DIR__) . '/../../themes/');
$dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/');
foreach($dirs as $dir) {
//Valid theme dir
if ($dir->isFile() || $dir->isDot()) {
@ -84,7 +91,7 @@ class MimeTypesJS extends Command {
$themeIt = new \DirectoryIterator($themeDir);
foreach ($themeIt as $fileInfo) {
if ($fileInfo->isFile()) {
$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
$themes[$theme][] = $file;
}
}
@ -110,7 +117,7 @@ OC.MimeTypeList={
';
//Output the JS
file_put_contents(dirname(__DIR__) . '/../js/mimetypelist.js', $js);
file_put_contents(\OC::$SERVERROOT.'/core/js/mimetypelist.js', $js);
$output->writeln('<info>mimetypelist.js is updated');
}

View File

@ -79,10 +79,10 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
);
$application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util));
$application->add(new OC\Core\Command\Maintenance\MimeTypesJS());
$application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Maintenance\Repair(new \OC\Repair(\OC\Repair::getRepairSteps()), \OC::$server->getConfig()));
$application->add(new OC\Core\Command\Maintenance\SingleUser(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector()));
$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig()));