2013-11-26 13:12:48 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Georg Ehrke <georg@owncloud.com>
|
|
|
|
* @author Joas Schilling <nickvergessen@owncloud.com>
|
|
|
|
* @author Lukas Reschke <lukas@owncloud.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @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,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2013-11-26 13:12:48 +00:00
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2013-11-26 13:12:48 +00:00
|
|
|
namespace OC;
|
|
|
|
|
|
|
|
use OC\Hooks\BasicEmitter;
|
2014-06-12 12:40:43 +00:00
|
|
|
use OC\Hooks\Emitter;
|
2014-10-06 10:38:59 +00:00
|
|
|
use OC\Repair\AssetCache;
|
2015-01-14 10:57:26 +00:00
|
|
|
use OC\Repair\CleanTags;
|
2014-10-06 10:38:59 +00:00
|
|
|
use OC\Repair\Collation;
|
2015-05-12 16:19:44 +00:00
|
|
|
use OC\Repair\DropOldJobs;
|
2015-03-25 17:31:49 +00:00
|
|
|
use OC\Repair\SqliteAutoincrement;
|
2015-03-02 11:02:14 +00:00
|
|
|
use OC\Repair\DropOldTables;
|
2015-01-12 14:22:02 +00:00
|
|
|
use OC\Repair\FillETags;
|
2014-10-06 10:38:59 +00:00
|
|
|
use OC\Repair\InnoDB;
|
|
|
|
use OC\Repair\RepairConfig;
|
|
|
|
use OC\Repair\RepairLegacyStorages;
|
|
|
|
use OC\Repair\RepairMimeTypes;
|
|
|
|
use OC\Repair\SearchLuceneTables;
|
2013-11-26 13:12:48 +00:00
|
|
|
|
|
|
|
class Repair extends BasicEmitter {
|
2014-06-10 09:47:27 +00:00
|
|
|
/**
|
2014-06-26 12:27:41 +00:00
|
|
|
* @var RepairStep[]
|
2014-06-10 09:47:27 +00:00
|
|
|
**/
|
|
|
|
private $repairSteps;
|
2014-03-25 11:51:16 +00:00
|
|
|
|
2013-11-26 13:12:48 +00:00
|
|
|
/**
|
2014-03-25 11:51:16 +00:00
|
|
|
* Creates a new repair step runner
|
|
|
|
*
|
2014-06-10 09:47:27 +00:00
|
|
|
* @param array $repairSteps array of RepairStep instances
|
2014-03-25 11:51:16 +00:00
|
|
|
*/
|
2014-06-10 09:47:27 +00:00
|
|
|
public function __construct($repairSteps = array()) {
|
|
|
|
$this->repairSteps = $repairSteps;
|
2014-03-25 11:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run a series of repair steps for common problems
|
2013-11-26 13:12:48 +00:00
|
|
|
*/
|
|
|
|
public function run() {
|
2014-03-25 11:51:16 +00:00
|
|
|
$self = $this;
|
2014-06-10 09:47:27 +00:00
|
|
|
if (count($this->repairSteps) === 0) {
|
|
|
|
$this->emit('\OC\Repair', 'info', array('No repair steps available'));
|
|
|
|
return;
|
|
|
|
}
|
2014-03-25 11:51:16 +00:00
|
|
|
// run each repair step
|
2014-06-10 09:47:27 +00:00
|
|
|
foreach ($this->repairSteps as $step) {
|
2014-03-25 11:51:16 +00:00
|
|
|
$this->emit('\OC\Repair', 'step', array($step->getName()));
|
|
|
|
|
2014-06-12 12:40:43 +00:00
|
|
|
if ($step instanceof Emitter) {
|
2014-06-10 09:47:27 +00: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 11:51:16 +00:00
|
|
|
$step->run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-10 09:47:27 +00:00
|
|
|
* Add repair step
|
2014-03-25 11:51:16 +00:00
|
|
|
*
|
2014-06-10 09:47:27 +00:00
|
|
|
* @param RepairStep $repairStep repair step
|
2014-03-25 11:51:16 +00:00
|
|
|
*/
|
2014-06-10 09:47:27 +00:00
|
|
|
public function addStep($repairStep) {
|
|
|
|
$this->repairSteps[] = $repairStep;
|
2013-11-26 13:12:48 +00:00
|
|
|
}
|
2014-03-25 11:51:16 +00:00
|
|
|
|
2014-06-10 09:47:27 +00: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 17:34:39 +00:00
|
|
|
return array(
|
2014-10-06 10:38:59 +00:00
|
|
|
new RepairMimeTypes(),
|
|
|
|
new RepairLegacyStorages(\OC::$server->getConfig(), \OC_DB::getConnection()),
|
|
|
|
new RepairConfig(),
|
2015-01-12 14:22:02 +00:00
|
|
|
new AssetCache(),
|
2015-01-14 10:57:26 +00:00
|
|
|
new FillETags(\OC_DB::getConnection()),
|
|
|
|
new CleanTags(\OC_DB::getConnection()),
|
2015-03-02 11:02:14 +00:00
|
|
|
new DropOldTables(\OC_DB::getConnection()),
|
2015-05-12 16:19:44 +00:00
|
|
|
new DropOldJobs(\OC::$server->getJobList()),
|
2014-06-25 17:34:39 +00:00
|
|
|
);
|
2014-06-10 09:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the repair steps to be run before an
|
|
|
|
* upgrade.
|
|
|
|
*
|
|
|
|
* @return array of RepairStep instances
|
|
|
|
*/
|
|
|
|
public static function getBeforeUpgradeRepairSteps() {
|
2014-09-21 15:16:21 +00:00
|
|
|
$steps = array(
|
2014-10-06 10:38:59 +00:00
|
|
|
new InnoDB(),
|
|
|
|
new Collation(\OC::$server->getConfig(), \OC_DB::getConnection()),
|
2015-03-25 17:31:49 +00:00
|
|
|
new SqliteAutoincrement(\OC_DB::getConnection()),
|
2014-11-13 12:34:11 +00:00
|
|
|
new SearchLuceneTables(),
|
|
|
|
new RepairConfig()
|
2014-06-25 17:34:39 +00:00
|
|
|
);
|
2014-09-21 15:16:21 +00:00
|
|
|
|
|
|
|
//There is no need to delete all previews on every single update
|
2014-10-06 10:38:59 +00:00
|
|
|
//only 7.0.0 through 7.0.2 generated broken previews
|
|
|
|
$currentVersion = \OC::$server->getConfig()->getSystemValue('version');
|
2014-09-21 15:16:21 +00:00
|
|
|
if (version_compare($currentVersion, '7.0.0.0', '>=') &&
|
2014-11-25 14:42:02 +00:00
|
|
|
version_compare($currentVersion, '7.0.3.4', '<=')) {
|
2014-09-21 15:16:21 +00:00
|
|
|
$steps[] = new \OC\Repair\Preview();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $steps;
|
2014-06-10 09:47:27 +00:00
|
|
|
}
|
2014-06-26 12:27:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*
|
2014-10-06 10:38:59 +00:00
|
|
|
* Re-declared as public to allow invocation from within the closure above in php 5.3
|
2014-06-26 12:27:41 +00:00
|
|
|
*/
|
|
|
|
public function emit($scope, $method, $arguments = array()) {
|
|
|
|
parent::emit($scope, $method, $arguments);
|
|
|
|
}
|
2013-11-26 13:12:48 +00:00
|
|
|
}
|