Repair mime types only when upgrading from OC 8.0

This commit is contained in:
Vincent Petry 2015-08-25 14:09:38 +02:00
parent 9fbd3fa6c1
commit 0bda4d54c5
3 changed files with 54 additions and 25 deletions

View File

@ -103,7 +103,7 @@ class Repair extends BasicEmitter {
*/ */
public static function getRepairSteps() { public static function getRepairSteps() {
return [ return [
new RepairMimeTypes(), new RepairMimeTypes(\OC::$server->getConfig()),
new RepairLegacyStorages(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), new RepairLegacyStorages(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
new RepairConfig(), new RepairConfig(),
new AssetCache(), new AssetCache(),

View File

@ -29,6 +29,17 @@ namespace OC\Repair;
use OC\Hooks\BasicEmitter; use OC\Hooks\BasicEmitter;
class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep { class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
/**
* @var \OCP\IConfig
*/
protected $config;
/**
* @param \OCP\IConfig $config
*/
public function __construct($config) {
$this->config = $config;
}
public function getName() { public function getName() {
return 'Repair mime types'; return 'Repair mime types';
@ -243,36 +254,45 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
* Fix mime types * Fix mime types
*/ */
public function run() { public function run() {
if ($this->fixOfficeMimeTypes()) {
$this->emit('\OC\Repair', 'info', array('Fixed office mime types'));
}
if ($this->fixApkMimeType()) { $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
$this->emit('\OC\Repair', 'info', array('Fixed APK mime type'));
}
if ($this->fixFontsMimeTypes()) { // NOTE TO DEVELOPERS: when adding new mime types, please make sure to
$this->emit('\OC\Repair', 'info', array('Fixed fonts mime types')); // add a version comparison to avoid doing it every time
}
if ($this->fixPostscriptMimeType()) { // only update mime types if necessary as it can be expensive
$this->emit('\OC\Repair', 'info', array('Fixed Postscript mime types')); if (version_compare($ocVersionFromBeforeUpdate, '8.2.0', '<')) {
} if ($this->fixOfficeMimeTypes()) {
$this->emit('\OC\Repair', 'info', array('Fixed office mime types'));
}
if ($this->introduceRawMimeType()) { if ($this->fixApkMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed Raw mime types')); $this->emit('\OC\Repair', 'info', array('Fixed APK mime type'));
} }
if ($this->introduce3dImagesMimeType()) { if ($this->fixFontsMimeTypes()) {
$this->emit('\OC\Repair', 'info', array('Fixed 3D images mime types')); $this->emit('\OC\Repair', 'info', array('Fixed fonts mime types'));
} }
if ($this->introduceConfMimeType()) { if ($this->fixPostscriptMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed Conf/cnf mime types')); $this->emit('\OC\Repair', 'info', array('Fixed Postscript mime types'));
} }
if ($this->introduceYamlMimeType()) { if ($this->introduceRawMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed Yaml/Yml mime types')); $this->emit('\OC\Repair', 'info', array('Fixed Raw mime types'));
}
if ($this->introduce3dImagesMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed 3D images mime types'));
}
if ($this->introduceConfMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed Conf/cnf mime types'));
}
if ($this->introduceYamlMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed Yaml/Yml mime types'));
}
} }
} }
} }

View File

@ -26,8 +26,17 @@ class RepairMimeTypes extends \Test\TestCase {
$this->savedMimetypeLoader = \OC::$server->getMimeTypeLoader(); $this->savedMimetypeLoader = \OC::$server->getMimeTypeLoader();
$this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); $this->mimetypeLoader = \OC::$server->getMimeTypeLoader();
$config = $this->getMockBuilder('OCP\IConfig')
->disableOriginalConstructor()
->getMock();
$config->expects($this->any())
->method('getSystemValue')
->with('version')
->will($this->returnValue('8.0.0.0'));
$this->storage = new \OC\Files\Storage\Temporary([]); $this->storage = new \OC\Files\Storage\Temporary([]);
$this->repair = new \OC\Repair\RepairMimeTypes();
$this->repair = new \OC\Repair\RepairMimeTypes($config);
} }
protected function tearDown() { protected function tearDown() {