2013-11-26 17:12:48 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC;
|
|
|
|
|
|
|
|
use OC\Hooks\BasicEmitter;
|
2014-06-12 16:40:43 +04:00
|
|
|
use OC\Hooks\Emitter;
|
2013-11-26 17:12:48 +04:00
|
|
|
|
|
|
|
class Repair extends BasicEmitter {
|
2014-06-10 13:47:27 +04:00
|
|
|
/**
|
2014-06-26 16:27:41 +04:00
|
|
|
* @var RepairStep[]
|
2014-06-10 13:47:27 +04:00
|
|
|
**/
|
|
|
|
private $repairSteps;
|
2014-03-25 15:51:16 +04:00
|
|
|
|
2013-11-26 17:12:48 +04:00
|
|
|
/**
|
2014-03-25 15:51:16 +04:00
|
|
|
* Creates a new repair step runner
|
|
|
|
*
|
2014-06-10 13:47:27 +04:00
|
|
|
* @param array $repairSteps array of RepairStep instances
|
2014-03-25 15:51:16 +04:00
|
|
|
*/
|
2014-06-10 13:47:27 +04:00
|
|
|
public function __construct($repairSteps = array()) {
|
|
|
|
$this->repairSteps = $repairSteps;
|
2014-03-25 15:51:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run a series of repair steps for common problems
|
2013-11-26 17:12:48 +04:00
|
|
|
*/
|
|
|
|
public function run() {
|
2014-03-25 15:51:16 +04:00
|
|
|
$self = $this;
|
2014-06-10 13:47:27 +04:00
|
|
|
if (count($this->repairSteps) === 0) {
|
|
|
|
$this->emit('\OC\Repair', 'info', array('No repair steps available'));
|
|
|
|
return;
|
|
|
|
}
|
2014-03-25 15:51:16 +04:00
|
|
|
// run each repair step
|
2014-06-10 13:47:27 +04:00
|
|
|
foreach ($this->repairSteps as $step) {
|
2014-03-25 15:51:16 +04:00
|
|
|
$this->emit('\OC\Repair', 'step', array($step->getName()));
|
|
|
|
|
2014-06-12 16:40:43 +04:00
|
|
|
if ($step instanceof Emitter) {
|
2014-06-10 13:47:27 +04:00
|
|
|
$step->listen('\OC\Repair', 'warning', function ($description) use ($self) {
|
|
|
|
$self->emit('\OC\Repair', 'warning', array($description));
|
|
|
|
});
|
|
|
|
$step->listen('\OC\Repair', 'info', function ($description) use ($self) {
|
|
|
|
$self->emit('\OC\Repair', 'info', array($description));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-03-25 15:51:16 +04:00
|
|
|
$step->run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-10 13:47:27 +04:00
|
|
|
* Add repair step
|
2014-03-25 15:51:16 +04:00
|
|
|
*
|
2014-06-10 13:47:27 +04:00
|
|
|
* @param RepairStep $repairStep repair step
|
2014-03-25 15:51:16 +04:00
|
|
|
*/
|
2014-06-10 13:47:27 +04:00
|
|
|
public function addStep($repairStep) {
|
|
|
|
$this->repairSteps[] = $repairStep;
|
2013-11-26 17:12:48 +04:00
|
|
|
}
|
2014-03-25 15:51:16 +04:00
|
|
|
|
2014-06-10 13:47:27 +04:00
|
|
|
/**
|
|
|
|
* Returns the default repair steps to be run on the
|
|
|
|
* command line or after an upgrade.
|
|
|
|
*
|
|
|
|
* @return array of RepairStep instances
|
|
|
|
*/
|
|
|
|
public static function getRepairSteps() {
|
2014-06-25 21:34:39 +04:00
|
|
|
return array(
|
2014-03-25 15:52:32 +04:00
|
|
|
new \OC\Repair\RepairMimeTypes(),
|
|
|
|
new \OC\Repair\RepairLegacyStorages(\OC::$server->getConfig(), \OC_DB::getConnection()),
|
2014-08-26 21:02:40 +04:00
|
|
|
new \OC\Repair\RepairConfig(),
|
2014-06-25 21:34:39 +04:00
|
|
|
);
|
2014-06-10 13:47:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the repair steps to be run before an
|
|
|
|
* upgrade.
|
|
|
|
*
|
|
|
|
* @return array of RepairStep instances
|
|
|
|
*/
|
|
|
|
public static function getBeforeUpgradeRepairSteps() {
|
2014-09-21 19:16:21 +04:00
|
|
|
$steps = array(
|
2014-07-07 19:37:35 +04:00
|
|
|
new \OC\Repair\InnoDB(),
|
2014-09-09 17:18:57 +04:00
|
|
|
new \OC\Repair\Collation(\OC::$server->getConfig(), \OC_DB::getConnection()),
|
|
|
|
new \OC\Repair\SearchLuceneTables()
|
2014-06-25 21:34:39 +04:00
|
|
|
);
|
2014-09-21 19:16:21 +04:00
|
|
|
|
|
|
|
//There is no need to delete all previews on every single update
|
|
|
|
//only 7.0.0 thru 7.0.2 generated broken previews
|
|
|
|
$currentVersion = \OC_Config::getValue('version');
|
|
|
|
if (version_compare($currentVersion, '7.0.0.0', '>=') &&
|
|
|
|
version_compare($currentVersion, '7.0.2.2', '<=')) {
|
|
|
|
$steps[] = new \OC\Repair\Preview();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $steps;
|
2014-06-10 13:47:27 +04:00
|
|
|
}
|
2014-06-26 16:27:41 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*
|
|
|
|
* Redeclared as public to allow invocation from within the closure above in php 5.3
|
|
|
|
*/
|
|
|
|
public function emit($scope, $method, $arguments = array()) {
|
|
|
|
parent::emit($scope, $method, $arguments);
|
|
|
|
}
|
2013-11-26 17:12:48 +04:00
|
|
|
}
|