Introduce OCP\Migration\IRepairStep and adopt all repair steps to this new interface - refs #24198

This commit is contained in:
Thomas Müller 2016-04-22 15:35:39 +02:00
parent a4b1d9feee
commit c7542c02db
No known key found for this signature in database
GPG Key ID: A943788A3BBEC44C
35 changed files with 369 additions and 199 deletions

View File

@ -23,23 +23,23 @@
namespace OC\Repair; namespace OC\Repair;
use Doctrine\DBAL\Platforms\MySqlPlatform; use OCP\Migration\IOutput;
use OC\Hooks\BasicEmitter; use OCP\Migration\IRepairStep;
class AssetCache extends BasicEmitter implements \OC\RepairStep { class AssetCache implements IRepairStep {
public function getName() { public function getName() {
return 'Clear asset cache after upgrade'; return 'Clear asset cache after upgrade';
} }
public function run() { public function run(IOutput $output) {
if (!\OC_Template::isAssetPipelineEnabled()) { if (!\OC_Template::isAssetPipelineEnabled()) {
$this->emit('\OC\Repair', 'info', array('Asset pipeline disabled -> nothing to do')); $output->info('Asset pipeline disabled -> nothing to do');
return; return;
} }
$assetDir = \OC::$server->getConfig()->getSystemValue('assetdirectory', \OC::$SERVERROOT) . '/assets'; $assetDir = \OC::$server->getConfig()->getSystemValue('assetdirectory', \OC::$SERVERROOT) . '/assets';
\OC_Helper::rmdirr($assetDir, false); \OC_Helper::rmdirr($assetDir, false);
$this->emit('\OC\Repair', 'info', array('Asset cache cleared.')); $output->info('Asset cache cleared.');
} }
} }

View File

@ -22,17 +22,17 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Hooks\BasicEmitter;
use OC\RepairStep;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
/** /**
* Class RepairConfig * Class RepairConfig
* *
* @package OC\Repair * @package OC\Repair
*/ */
class CleanTags extends BasicEmitter implements RepairStep { class CleanTags implements IRepairStep {
/** @var IDBConnection */ /** @var IDBConnection */
protected $connection; protected $connection;
@ -54,17 +54,18 @@ class CleanTags extends BasicEmitter implements RepairStep {
/** /**
* Updates the configuration after running an update * Updates the configuration after running an update
*/ */
public function run() { public function run(IOutput $output) {
$this->deleteOrphanFileEntries(); $this->deleteOrphanFileEntries($output);
$this->deleteOrphanTagEntries(); $this->deleteOrphanTagEntries($output);
$this->deleteOrphanCategoryEntries(); $this->deleteOrphanCategoryEntries($output);
} }
/** /**
* Delete tag entries for deleted files * Delete tag entries for deleted files
*/ */
protected function deleteOrphanFileEntries() { protected function deleteOrphanFileEntries(IOutput $output) {
$this->deleteOrphanEntries( $this->deleteOrphanEntries(
$output,
'%d tags for delete files have been removed.', '%d tags for delete files have been removed.',
'vcategory_to_object', 'objid', 'vcategory_to_object', 'objid',
'filecache', 'fileid', 'path_hash' 'filecache', 'fileid', 'path_hash'
@ -74,8 +75,9 @@ class CleanTags extends BasicEmitter implements RepairStep {
/** /**
* Delete tag entries for deleted tags * Delete tag entries for deleted tags
*/ */
protected function deleteOrphanTagEntries() { protected function deleteOrphanTagEntries(IOutput $output) {
$this->deleteOrphanEntries( $this->deleteOrphanEntries(
$output,
'%d tag entries for deleted tags have been removed.', '%d tag entries for deleted tags have been removed.',
'vcategory_to_object', 'categoryid', 'vcategory_to_object', 'categoryid',
'vcategory', 'id', 'uid' 'vcategory', 'id', 'uid'
@ -85,8 +87,9 @@ class CleanTags extends BasicEmitter implements RepairStep {
/** /**
* Delete tags that have no entries * Delete tags that have no entries
*/ */
protected function deleteOrphanCategoryEntries() { protected function deleteOrphanCategoryEntries(IOutput $output) {
$this->deleteOrphanEntries( $this->deleteOrphanEntries(
$output,
'%d tags with no entries have been removed.', '%d tags with no entries have been removed.',
'vcategory', 'id', 'vcategory', 'id',
'vcategory_to_object', 'categoryid', 'type' 'vcategory_to_object', 'categoryid', 'type'
@ -108,7 +111,7 @@ class CleanTags extends BasicEmitter implements RepairStep {
* @param string $sourceNullColumn If this column is null in the source table, * @param string $sourceNullColumn If this column is null in the source table,
* the entry is deleted in the $deleteTable * the entry is deleted in the $deleteTable
*/ */
protected function deleteOrphanEntries($repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) { protected function deleteOrphanEntries(IOutput $output, $repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) {
$qb = $this->connection->getQueryBuilder(); $qb = $this->connection->getQueryBuilder();
$qb->select('d.' . $deleteId) $qb->select('d.' . $deleteId)
@ -141,7 +144,7 @@ class CleanTags extends BasicEmitter implements RepairStep {
} }
if ($repairInfo) { if ($repairInfo) {
$this->emit('\OC\Repair', 'info', array(sprintf($repairInfo, sizeof($orphanItems)))); $output->info(sprintf($repairInfo, sizeof($orphanItems)));
} }
} }
} }

View File

@ -23,9 +23,10 @@
namespace OC\Repair; namespace OC\Repair;
use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform;
use OC\Hooks\BasicEmitter; use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class Collation extends BasicEmitter implements \OC\RepairStep { class Collation implements IRepairStep {
/** /**
* @var \OCP\IConfig * @var \OCP\IConfig
*/ */
@ -52,15 +53,15 @@ class Collation extends BasicEmitter implements \OC\RepairStep {
/** /**
* Fix mime types * Fix mime types
*/ */
public function run() { public function run(IOutput $output) {
if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) { if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
$this->emit('\OC\Repair', 'info', array('Not a mysql database -> nothing to no')); $output->info('Not a mysql database -> nothing to no');
return; return;
} }
$tables = $this->getAllNonUTF8BinTables($this->connection); $tables = $this->getAllNonUTF8BinTables($this->connection);
foreach ($tables as $table) { foreach ($tables as $table) {
$this->emit('\OC\Repair', 'info', array("Change collation for $table ...")); $output->info("Change collation for $table ...");
$query = $this->connection->prepare('ALTER TABLE `' . $table . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;'); $query = $this->connection->prepare('ALTER TABLE `' . $table . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;');
$query->execute(); $query->execute();
} }

View File

@ -22,11 +22,11 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Hooks\BasicEmitter;
use OC\RepairStep;
use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\IJobList;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class DropOldJobs extends BasicEmitter implements RepairStep { class DropOldJobs implements IRepairStep {
/** @var IJobList */ /** @var IJobList */
protected $jobList; protected $jobList;
@ -53,7 +53,7 @@ class DropOldJobs extends BasicEmitter implements RepairStep {
* *
* @throws \Exception in case of failure * @throws \Exception in case of failure
*/ */
public function run() { public function run(IOutput $output) {
$oldJobs = $this->oldJobs(); $oldJobs = $this->oldJobs();
foreach($oldJobs as $job) { foreach($oldJobs as $job) {
if($this->jobList->has($job['class'], $job['arguments'])) { if($this->jobList->has($job['class'], $job['arguments'])) {

View File

@ -23,11 +23,11 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Hooks\BasicEmitter;
use OC\RepairStep;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class DropOldTables extends BasicEmitter implements RepairStep { class DropOldTables implements IRepairStep {
/** @var IDBConnection */ /** @var IDBConnection */
protected $connection; protected $connection;
@ -54,12 +54,10 @@ class DropOldTables extends BasicEmitter implements RepairStep {
* *
* @throws \Exception in case of failure * @throws \Exception in case of failure
*/ */
public function run() { public function run(IOutput $output) {
foreach ($this->oldDatabaseTables() as $tableName) { foreach ($this->oldDatabaseTables() as $tableName) {
if ($this->connection->tableExists($tableName)){ if ($this->connection->tableExists($tableName)){
$this->emit('\OC\Repair', 'info', [ $output->info(sprintf('Table %s has been deleted', $tableName));
sprintf('Table %s has been deleted', $tableName)
]);
$this->connection->dropTable($tableName); $this->connection->dropTable($tableName);
} }
} }

View File

@ -23,9 +23,10 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Hooks\BasicEmitter; use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class FillETags extends BasicEmitter implements \OC\RepairStep { class FillETags implements IRepairStep {
/** @var \OCP\IDBConnection */ /** @var \OCP\IDBConnection */
protected $connection; protected $connection;
@ -41,7 +42,7 @@ class FillETags extends BasicEmitter implements \OC\RepairStep {
return 'Generate ETags for file where no ETag is present.'; return 'Generate ETags for file where no ETag is present.';
} }
public function run() { public function run(IOutput $output) {
$qb = $this->connection->getQueryBuilder(); $qb = $this->connection->getQueryBuilder();
$qb->update('filecache') $qb->update('filecache')
->set('etag', $qb->expr()->literal('xxx')) ->set('etag', $qb->expr()->literal('xxx'))
@ -49,7 +50,7 @@ class FillETags extends BasicEmitter implements \OC\RepairStep {
->orWhere($qb->expr()->isNull('etag')); ->orWhere($qb->expr()->isNull('etag'));
$result = $qb->execute(); $result = $qb->execute();
$this->emit('\OC\Repair', 'info', array("ETags have been fixed for $result files/folders.")); $output->info("ETags have been fixed for $result files/folders.");
} }
} }

View File

@ -25,9 +25,10 @@
namespace OC\Repair; namespace OC\Repair;
use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform;
use OC\Hooks\BasicEmitter; use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class InnoDB extends BasicEmitter implements \OC\RepairStep { class InnoDB implements IRepairStep {
public function getName() { public function getName() {
return 'Repair MySQL database engine'; return 'Repair MySQL database engine';
@ -36,10 +37,10 @@ class InnoDB extends BasicEmitter implements \OC\RepairStep {
/** /**
* Fix mime types * Fix mime types
*/ */
public function run() { public function run(IOutput $output) {
$connection = \OC::$server->getDatabaseConnection(); $connection = \OC::$server->getDatabaseConnection();
if (!$connection->getDatabasePlatform() instanceof MySqlPlatform) { if (!$connection->getDatabasePlatform() instanceof MySqlPlatform) {
$this->emit('\OC\Repair', 'info', array('Not a mysql database -> nothing to do')); $output->info('Not a mysql database -> nothing to do');
return; return;
} }
@ -47,7 +48,7 @@ class InnoDB extends BasicEmitter implements \OC\RepairStep {
if (is_array($tables)) { if (is_array($tables)) {
foreach ($tables as $table) { foreach ($tables as $table) {
$connection->exec("ALTER TABLE $table ENGINE=InnoDB;"); $connection->exec("ALTER TABLE $table ENGINE=InnoDB;");
$this->emit('\OC\Repair', 'info', array("Fixed $table")); $output->info("Fixed $table");
} }
} }
} }

View File

@ -21,14 +21,13 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Hooks\BasicEmitter;
use OC\RepairStep;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use OCP\Share; use OCP\Share;
class OldGroupMembershipShares extends BasicEmitter implements RepairStep { class OldGroupMembershipShares implements IRepairStep {
/** @var \OCP\IDBConnection */ /** @var \OCP\IDBConnection */
protected $connection; protected $connection;
@ -65,7 +64,7 @@ class OldGroupMembershipShares extends BasicEmitter implements RepairStep {
* *
* @throws \Exception in case of failure * @throws \Exception in case of failure
*/ */
public function run() { public function run(IOutput $output) {
$deletedEntries = 0; $deletedEntries = 0;
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
@ -92,7 +91,7 @@ class OldGroupMembershipShares extends BasicEmitter implements RepairStep {
$result->closeCursor(); $result->closeCursor();
if ($deletedEntries) { if ($deletedEntries) {
$this->emit('\OC\Repair', 'info', array('Removed ' . $deletedEntries . ' shares where user is not a member of the group anymore')); $output->info('Removed ' . $deletedEntries . ' shares where user is not a member of the group anymore');
} }
} }

View File

@ -21,15 +21,16 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Files\View; use OC\Files\View;
use OC\Hooks\BasicEmitter; use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class Preview extends BasicEmitter implements \OC\RepairStep { class Preview implements IRepairStep {
public function getName() { public function getName() {
return 'Cleaning-up broken previews'; return 'Cleaning-up broken previews';
} }
public function run() { public function run(IOutput $out) {
$view = new View('/'); $view = new View('/');
$children = $view->getDirectoryContent('/'); $children = $view->getDirectoryContent('/');
@ -42,4 +43,4 @@ class Preview extends BasicEmitter implements \OC\RepairStep {
} }
} }
} }
} }

View File

@ -21,10 +21,11 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Hooks\BasicEmitter;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class RemoveGetETagEntries extends BasicEmitter { class RemoveGetETagEntries implements IRepairStep {
/** /**
* @var IDBConnection * @var IDBConnection
@ -45,15 +46,11 @@ class RemoveGetETagEntries extends BasicEmitter {
/** /**
* Removes all entries with the key "{DAV:}getetag" from the table properties * Removes all entries with the key "{DAV:}getetag" from the table properties
*/ */
public function run() { public function run(IOutput $out) {
$sql = 'DELETE FROM `*PREFIX*properties`' $sql = 'DELETE FROM `*PREFIX*properties`'
. ' WHERE `propertyname` = ?'; . ' WHERE `propertyname` = ?';
$deletedRows = $this->connection->executeUpdate($sql, ['{DAV:}getetag']); $deletedRows = $this->connection->executeUpdate($sql, ['{DAV:}getetag']);
$this->emit( $out->info('Removed ' . $deletedRows . ' unneeded "{DAV:}getetag" entries from properties table.');
'\OC\Repair',
'info',
['Removed ' . $deletedRows . ' unneeded "{DAV:}getetag" entries from properties table.']
);
} }
} }

View File

@ -23,23 +23,20 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Hooks\BasicEmitter; use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
/** /**
* Repairs shares with invalid data * Repairs shares with invalid data
*/ */
class RepairInvalidShares extends BasicEmitter implements \OC\RepairStep { class RepairInvalidShares implements IRepairStep {
const CHUNK_SIZE = 200; const CHUNK_SIZE = 200;
/** /** @var \OCP\IConfig */
* @var \OCP\IConfig
*/
protected $config; protected $config;
/** /** @var \OCP\IDBConnection */
* @var \OCP\IDBConnection
*/
protected $connection; protected $connection;
/** /**
@ -59,7 +56,7 @@ class RepairInvalidShares extends BasicEmitter implements \OC\RepairStep {
* Past bugs would make it possible to set an expiration date on user shares even * Past bugs would make it possible to set an expiration date on user shares even
* though it is not supported. This functions removes the expiration date from such entries. * though it is not supported. This functions removes the expiration date from such entries.
*/ */
private function removeExpirationDateFromNonLinkShares() { private function removeExpirationDateFromNonLinkShares(IOutput $out) {
$builder = $this->connection->getQueryBuilder(); $builder = $this->connection->getQueryBuilder();
$builder $builder
->update('share') ->update('share')
@ -69,14 +66,14 @@ class RepairInvalidShares extends BasicEmitter implements \OC\RepairStep {
$updatedEntries = $builder->execute(); $updatedEntries = $builder->execute();
if ($updatedEntries > 0) { if ($updatedEntries > 0) {
$this->emit('\OC\Repair', 'info', array('Removed invalid expiration date from ' . $updatedEntries . ' shares')); $out->info('Removed invalid expiration date from ' . $updatedEntries . ' shares');
} }
} }
/** /**
* Remove shares where the parent share does not exist anymore * Remove shares where the parent share does not exist anymore
*/ */
private function removeSharesNonExistingParent() { private function removeSharesNonExistingParent(IOutput $out) {
$deletedEntries = 0; $deletedEntries = 0;
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
@ -105,17 +102,17 @@ class RepairInvalidShares extends BasicEmitter implements \OC\RepairStep {
} }
if ($deletedEntries) { if ($deletedEntries) {
$this->emit('\OC\Repair', 'info', array('Removed ' . $deletedEntries . ' shares where the parent did not exist')); $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist');
} }
} }
public function run() { public function run(IOutput $out) {
$ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
if (version_compare($ocVersionFromBeforeUpdate, '8.2.0.7', '<')) { if (version_compare($ocVersionFromBeforeUpdate, '8.2.0.7', '<')) {
// this situation was only possible before 8.2 // this situation was only possible before 8.2
$this->removeExpirationDateFromNonLinkShares(); $this->removeExpirationDateFromNonLinkShares($out);
} }
$this->removeSharesNonExistingParent(); $this->removeSharesNonExistingParent($out);
} }
} }

View File

@ -24,10 +24,11 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Files\Cache\Storage; use OC\Files\Cache\Storage;
use OC\Hooks\BasicEmitter;
use OC\RepairException; use OC\RepairException;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class RepairLegacyStorages extends BasicEmitter { class RepairLegacyStorages implements IRepairStep{
/** /**
* @var \OCP\IConfig * @var \OCP\IConfig
*/ */
@ -149,7 +150,7 @@ class RepairLegacyStorages extends BasicEmitter {
* Converts legacy home storage ids in the format * Converts legacy home storage ids in the format
* "local::/data/dir/path/userid/" to the new format "home::userid" * "local::/data/dir/path/userid/" to the new format "home::userid"
*/ */
public function run() { public function run(IOutput $out) {
// only run once // only run once
if ($this->config->getAppValue('core', 'repairlegacystoragesdone') === 'yes') { if ($this->config->getAppValue('core', 'repairlegacystoragesdone') === 'yes') {
return; return;
@ -186,11 +187,7 @@ class RepairLegacyStorages extends BasicEmitter {
} }
catch (RepairException $e) { catch (RepairException $e) {
$hasWarnings = true; $hasWarnings = true;
$this->emit( $out->warning('Could not repair legacy storage ' . $currentId . ' automatically.');
'\OC\Repair',
'warning',
array('Could not repair legacy storage ' . $currentId . ' automatically.')
);
} }
} }
@ -233,11 +230,7 @@ class RepairLegacyStorages extends BasicEmitter {
} }
catch (RepairException $e) { catch (RepairException $e) {
$hasWarnings = true; $hasWarnings = true;
$this->emit( $out->warning('Could not repair legacy storage ' . $storageId . ' automatically.');
'\OC\Repair',
'warning',
array('Could not repair legacy storage ' . $storageId . ' automatically.')
);
} }
} }
} }
@ -245,16 +238,12 @@ class RepairLegacyStorages extends BasicEmitter {
} while (count($results) >= $limit); } while (count($results) >= $limit);
} }
$this->emit('\OC\Repair', 'info', array('Updated ' . $count . ' legacy home storage ids')); $out->info('Updated ' . $count . ' legacy home storage ids');
$this->connection->commit(); $this->connection->commit();
if ($hasWarnings) { if ($hasWarnings) {
$this->emit( $out->warning('Some legacy storages could not be repaired. Please manually fix them then re-run ./occ maintenance:repair');
'\OC\Repair',
'warning',
array('Some legacy storages could not be repaired. Please manually fix them then re-run ./occ maintenance:repair')
);
} else { } else {
// if all were done, no need to redo the repair during next upgrade // if all were done, no need to redo the repair during next upgrade
$this->config->setAppValue('core', 'repairlegacystoragesdone', 'yes'); $this->config->setAppValue('core', 'repairlegacystoragesdone', 'yes');

View File

@ -28,9 +28,10 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Hooks\BasicEmitter; use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep { class RepairMimeTypes implements IRepairStep {
/** /**
* @var \OCP\IConfig * @var \OCP\IConfig
*/ */
@ -308,7 +309,7 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
/** /**
* Fix mime types * Fix mime types
*/ */
public function run() { public function run(IOutput $out) {
$ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
@ -318,60 +319,60 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
// only update mime types if necessary as it can be expensive // only update mime types if necessary as it can be expensive
if (version_compare($ocVersionFromBeforeUpdate, '8.2.0', '<')) { if (version_compare($ocVersionFromBeforeUpdate, '8.2.0', '<')) {
if ($this->fixOfficeMimeTypes()) { if ($this->fixOfficeMimeTypes()) {
$this->emit('\OC\Repair', 'info', array('Fixed office mime types')); $out->info('Fixed office mime types');
} }
if ($this->fixApkMimeType()) { if ($this->fixApkMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed APK mime type')); $out->info('Fixed APK mime type');
} }
if ($this->fixFontsMimeTypes()) { if ($this->fixFontsMimeTypes()) {
$this->emit('\OC\Repair', 'info', array('Fixed fonts mime types')); $out->info('Fixed fonts mime types');
} }
if ($this->fixPostscriptMimeType()) { if ($this->fixPostscriptMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed Postscript mime types')); $out->info('Fixed Postscript mime types');
} }
if ($this->introduceRawMimeType()) { if ($this->introduceRawMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed Raw mime types')); $out->info('Fixed Raw mime types');
} }
if ($this->introduce3dImagesMimeType()) { if ($this->introduce3dImagesMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed 3D images mime types')); $out->info('Fixed 3D images mime types');
} }
if ($this->introduceConfMimeType()) { if ($this->introduceConfMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed Conf/cnf mime types')); $out->info('Fixed Conf/cnf mime types');
} }
if ($this->introduceYamlMimeType()) { if ($this->introduceYamlMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed Yaml/Yml mime types')); $out->info('Fixed Yaml/Yml mime types');
} }
} }
// Mimetype updates from #19272 // Mimetype updates from #19272
if (version_compare($ocVersionFromBeforeUpdate, '8.2.0.8', '<')) { if (version_compare($ocVersionFromBeforeUpdate, '8.2.0.8', '<')) {
if ($this->introduceJavaMimeType()) { if ($this->introduceJavaMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed java/class mime types')); $out->info('Fixed java/class mime types');
} }
if ($this->introduceHppMimeType()) { if ($this->introduceHppMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed hpp mime type')); $out->info('Fixed hpp mime type');
} }
if ($this->introduceRssMimeType()) { if ($this->introduceRssMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed rss mime type')); $out->info('Fixed rss mime type');
} }
if ($this->introduceRtfMimeType()) { if ($this->introduceRtfMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed rtf mime type')); $out->info('Fixed rtf mime type');
} }
} }
if (version_compare($ocVersionFromBeforeUpdate, '9.0.0.10', '<')) { if (version_compare($ocVersionFromBeforeUpdate, '9.0.0.10', '<')) {
if ($this->introduceRichDocumentsMimeTypes()) { if ($this->introduceRichDocumentsMimeTypes()) {
$this->emit('\OC\Repair', 'info', array('Fixed richdocuments additional office mime types')); $out->info('Fixed richdocuments additional office mime types');
} }
} }
} }

View File

@ -22,9 +22,10 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Hooks\BasicEmitter; use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class SearchLuceneTables extends BasicEmitter implements \OC\RepairStep { class SearchLuceneTables implements IRepairStep {
public function getName() { public function getName() {
return 'Repair duplicate entries in oc_lucene_status'; return 'Repair duplicate entries in oc_lucene_status';
@ -51,10 +52,10 @@ class SearchLuceneTables extends BasicEmitter implements \OC\RepairStep {
* *
* search_lucene will then reindex the fileids without a status when the next indexing job is executed * search_lucene will then reindex the fileids without a status when the next indexing job is executed
*/ */
public function run() { public function run(IOutput $out) {
$connection = \OC::$server->getDatabaseConnection(); $connection = \OC::$server->getDatabaseConnection();
if ($connection->tableExists('lucene_status')) { if ($connection->tableExists('lucene_status')) {
$this->emit('\OC\Repair', 'info', array('removing duplicate entries from lucene_status')); $out->info('removing duplicate entries from lucene_status');
$query = $connection->prepare(' $query = $connection->prepare('
DELETE FROM `*PREFIX*lucene_status` DELETE FROM `*PREFIX*lucene_status`
@ -69,7 +70,7 @@ class SearchLuceneTables extends BasicEmitter implements \OC\RepairStep {
)'); )');
$query->execute(); $query->execute();
} else { } else {
$this->emit('\OC\Repair', 'info', array('lucene_status table does not exist -> nothing to do')); $out->info('lucene_status table does not exist -> nothing to do');
} }
} }

View File

@ -20,10 +20,12 @@
*/ */
namespace OC\Repair; namespace OC\Repair;
use OC\Hooks\BasicEmitter;
use OCP\IConfig; use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class SharePropagation implements IRepairStep {
class SharePropagation extends BasicEmitter implements \OC\RepairStep {
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
@ -40,7 +42,7 @@ class SharePropagation extends BasicEmitter implements \OC\RepairStep {
return 'Remove old share propagation app entries'; return 'Remove old share propagation app entries';
} }
public function run() { public function run(IOutput $out ) {
$keys = $this->config->getAppKeys('files_sharing'); $keys = $this->config->getAppKeys('files_sharing');
foreach ($keys as $key) { foreach ($keys as $key) {

View File

@ -26,13 +26,14 @@ use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Schema\SchemaDiff; use Doctrine\DBAL\Schema\SchemaDiff;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\ColumnDiff;
use OC\Hooks\BasicEmitter; use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
/** /**
* Fixes Sqlite autoincrement by forcing the SQLite table schemas to be * Fixes Sqlite autoincrement by forcing the SQLite table schemas to be
* altered in order to retrigger SQL schema generation through OCSqlitePlatform. * altered in order to retrigger SQL schema generation through OCSqlitePlatform.
*/ */
class SqliteAutoincrement extends BasicEmitter implements \OC\RepairStep { class SqliteAutoincrement implements IRepairStep {
/** /**
* @var \OC\DB\Connection * @var \OC\DB\Connection
*/ */
@ -52,7 +53,7 @@ class SqliteAutoincrement extends BasicEmitter implements \OC\RepairStep {
/** /**
* Fix mime types * Fix mime types
*/ */
public function run() { public function run(IOutput $out) {
if (!$this->connection->getDatabasePlatform() instanceof SqlitePlatform) { if (!$this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
return; return;
} }

View File

@ -22,10 +22,10 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Files\View; use OC\Files\View;
use OC\Hooks\BasicEmitter;
use OC\RepairStep;
use OC\Server; use OC\Server;
use OCP\IConfig; use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
/** /**
* Class UpdateCertificateStore rewrites the user specific certificate store after * Class UpdateCertificateStore rewrites the user specific certificate store after
@ -34,7 +34,7 @@ use OCP\IConfig;
* *
* @package OC\Repair * @package OC\Repair
*/ */
class UpdateCertificateStore extends BasicEmitter implements RepairStep { class UpdateCertificateStore implements IRepairStep {
/** /**
* FIXME: The certificate manager does only allow specifying the user * FIXME: The certificate manager does only allow specifying the user
* within the constructor. This makes DI impossible. * within the constructor. This makes DI impossible.
@ -60,7 +60,7 @@ class UpdateCertificateStore extends BasicEmitter implements RepairStep {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public function run() { public function run(IOutput $out) {
$rootView = new View(); $rootView = new View();
$dataDirectory = $this->config->getSystemValue('datadirectory', null); $dataDirectory = $this->config->getSystemValue('datadirectory', null);
if(is_null($dataDirectory)) { if(is_null($dataDirectory)) {

View File

@ -21,9 +21,9 @@
namespace OC\Repair; namespace OC\Repair;
use OC\Hooks\BasicEmitter;
use OC\RepairStep;
use OCP\IConfig; use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
/** /**
* Class UpdateOutdatedOcsIds is used to update invalid outdated OCS IDs, this is * Class UpdateOutdatedOcsIds is used to update invalid outdated OCS IDs, this is
@ -33,7 +33,7 @@ use OCP\IConfig;
* *
* @package OC\Repair * @package OC\Repair
*/ */
class UpdateOutdatedOcsIds extends BasicEmitter implements RepairStep { class UpdateOutdatedOcsIds implements IRepairStep {
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
@ -71,7 +71,7 @@ class UpdateOutdatedOcsIds extends BasicEmitter implements RepairStep {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function run() { public function run(IOutput $output) {
$appsToUpdate = [ $appsToUpdate = [
'contacts' => [ 'contacts' => [
'old' => '166044', 'old' => '166044',
@ -97,11 +97,7 @@ class UpdateOutdatedOcsIds extends BasicEmitter implements RepairStep {
foreach($appsToUpdate as $appName => $ids) { foreach($appsToUpdate as $appName => $ids) {
if ($this->fixOcsId($appName, $ids['old'], $ids['new'])) { if ($this->fixOcsId($appName, $ids['old'], $ids['new'])) {
$this->emit( $output->info("Fixed invalid $appName OCS id");
'\OC\Repair',
'info',
[sprintf('Fixed invalid %s OCS id', $appName)]
);
} }
} }
} }

View File

@ -46,11 +46,13 @@ use OC\Repair\RepairMimeTypes;
use OC\Repair\SearchLuceneTables; use OC\Repair\SearchLuceneTables;
use OC\Repair\UpdateOutdatedOcsIds; use OC\Repair\UpdateOutdatedOcsIds;
use OC\Repair\RepairInvalidShares; use OC\Repair\RepairInvalidShares;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent; use Symfony\Component\EventDispatcher\GenericEvent;
class Repair extends BasicEmitter { class Repair extends BasicEmitter implements IOutput{
/* @var RepairStep[] */ /* @var IRepairStep[] */
private $repairSteps; private $repairSteps;
/** @var EventDispatcher */ /** @var EventDispatcher */
private $dispatcher; private $dispatcher;
@ -58,7 +60,7 @@ class Repair extends BasicEmitter {
/** /**
* Creates a new repair step runner * Creates a new repair step runner
* *
* @param RepairStep[] $repairSteps array of RepairStep instances * @param IRepairStep[] $repairSteps array of RepairStep instances
* @param EventDispatcher $dispatcher * @param EventDispatcher $dispatcher
*/ */
public function __construct($repairSteps = [], EventDispatcher $dispatcher = null) { public function __construct($repairSteps = [], EventDispatcher $dispatcher = null) {
@ -88,24 +90,24 @@ class Repair extends BasicEmitter {
}); });
} }
$step->run(); $step->run($this);
} }
} }
/** /**
* Add repair step * Add repair step
* *
* @param RepairStep|string $repairStep repair step * @param IRepairStep|string $repairStep repair step
* @throws \Exception * @throws \Exception
*/ */
public function addStep($repairStep) { public function addStep($repairStep) {
if (is_string($repairStep)) { if (is_string($repairStep)) {
if (class_exists($repairStep)) { if (class_exists($repairStep)) {
$s = new $repairStep(); $s = new $repairStep();
if ($s instanceof RepairStep) { if ($s instanceof IRepairStep) {
$this->repairSteps[] = $s; $this->repairSteps[] = $s;
} else { } else {
throw new \Exception("Repair step '$repairStep' is not of type \\OC\\RepairStep"); throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep");
} }
} else { } else {
throw new \Exception("Repair step '$repairStep' is unknown"); throw new \Exception("Repair step '$repairStep' is unknown");
@ -119,7 +121,7 @@ class Repair extends BasicEmitter {
* Returns the default repair steps to be run on the * Returns the default repair steps to be run on the
* command line or after an upgrade. * command line or after an upgrade.
* *
* @return array of RepairStep instances * @return IRepairStep[]
*/ */
public static function getRepairSteps() { public static function getRepairSteps() {
return [ return [
@ -141,7 +143,7 @@ class Repair extends BasicEmitter {
* Returns expensive repair steps to be run on the * Returns expensive repair steps to be run on the
* command line with a special option. * command line with a special option.
* *
* @return array of RepairStep instances * @return IRepairStep[]
*/ */
public static function getExpensiveRepairSteps() { public static function getExpensiveRepairSteps() {
return [ return [
@ -153,7 +155,7 @@ class Repair extends BasicEmitter {
* Returns the repair steps to be run before an * Returns the repair steps to be run before an
* upgrade. * upgrade.
* *
* @return array of RepairStep instances * @return IRepairStep[]
*/ */
public static function getBeforeUpgradeRepairSteps() { public static function getBeforeUpgradeRepairSteps() {
$connection = \OC::$server->getDatabaseConnection(); $connection = \OC::$server->getDatabaseConnection();
@ -185,4 +187,41 @@ class Repair extends BasicEmitter {
new GenericEvent("$scope::$method", $arguments)); new GenericEvent("$scope::$method", $arguments));
} }
} }
public function info($string) {
// for now just emit as we did in the past
$this->emit('\OC\Repair', 'info', array($string));
}
/**
* @param string $message
*/
public function warning($message) {
// for now just emit as we did in the past
$this->emit('\OC\Repair', 'warning', [$message]);
}
/**
* @param int $max
*/
public function startProgress($max = 0) {
// for now just emit as we did in the past
$this->emit('\OC\Repair', 'startProgress', [$max]);
}
/**
* @param int $step
*/
public function advance($step = 1) {
// for now just emit as we did in the past
$this->emit('\OC\Repair', 'advance', [$step]);
}
/**
* @param int $max
*/
public function finishProgress() {
// for now just emit as we did in the past
$this->emit('\OC\Repair', 'finishProgress', []);
}
} }

View File

@ -0,0 +1,61 @@
<?php
/**
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @copyright Copyright (c) 2016, 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/>
*
*/
namespace OCP\Migration;
/**
* Interface IOutput
*
* @package OCP\Migration
* @since 9.1.0
*/
interface IOutput {
/**
* @param string $message
* @since 9.1.0
*/
public function info($message);
/**
* @param string $message
* @since 9.1.0
*/
public function warning($message);
/**
* @param int $max
* @since 9.1.0
*/
public function startProgress($max = 0);
/**
* @param int $step
* @since 9.1.0
*/
public function advance($step = 1);
/**
* @param int $max
* @since 9.1.0
*/
public function finishProgress();
}

View File

@ -18,17 +18,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* *
*/ */
namespace OC; namespace OCP\Migration;
/** /**
* Repair step * Repair step
* @since 9.1.0
*/ */
interface RepairStep { interface IRepairStep {
/** /**
* Returns the step's name * Returns the step's name
* *
* @return string * @return string
* @since 9.1.0
*/ */
public function getName(); public function getName();
@ -36,8 +38,9 @@ interface RepairStep {
* Run repair step. * Run repair step.
* Must throw exception on error. * Must throw exception on error.
* *
* @since 9.1.0
* @throws \Exception in case of failure * @throws \Exception in case of failure
*/ */
public function run(); public function run(IOutput $output);
} }

View File

@ -6,9 +6,9 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
use OC\Hooks\BasicEmitter; use OCP\Migration\IRepairStep;
class TestRepairStep extends BasicEmitter implements \OC\RepairStep{ class TestRepairStep implements IRepairStep {
private $warning; private $warning;
public function __construct($warning = false) { public function __construct($warning = false) {
@ -19,12 +19,12 @@ class TestRepairStep extends BasicEmitter implements \OC\RepairStep{
return 'Test Name'; return 'Test Name';
} }
public function run() { public function run(\OCP\Migration\IOutput $out) {
if ($this->warning) { if ($this->warning) {
$this->emit('\OC\Repair', 'warning', array('Simulated warning')); $out->warning('Simulated warning');
} }
else { else {
$this->emit('\OC\Repair', 'info', array('Simulated info')); $out->info('Simulated info');
} }
} }
} }

View File

@ -8,6 +8,7 @@
namespace Test\Repair; namespace Test\Repair;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Migration\IOutput;
/** /**
* Tests for the cleaning the tags tables * Tests for the cleaning the tags tables
@ -18,7 +19,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
*/ */
class CleanTags extends \Test\TestCase { class CleanTags extends \Test\TestCase {
/** @var \OC\RepairStep */ /** @var \OC\Repair\CleanTags */
protected $repair; protected $repair;
/** @var \OCP\IDBConnection */ /** @var \OCP\IDBConnection */
@ -27,9 +28,16 @@ class CleanTags extends \Test\TestCase {
/** @var int */ /** @var int */
protected $createdFile; protected $createdFile;
/** @var IOutput */
private $outputMock;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
->getMock();
$this->connection = \OC::$server->getDatabaseConnection(); $this->connection = \OC::$server->getDatabaseConnection();
$this->repair = new \OC\Repair\CleanTags($this->connection); $this->repair = new \OC\Repair\CleanTags($this->connection);
$this->cleanUpTables(); $this->cleanUpTables();
@ -67,15 +75,15 @@ class CleanTags extends \Test\TestCase {
$this->assertEntryCount('vcategory_to_object', 4, 'Assert tag entries count before repair step'); $this->assertEntryCount('vcategory_to_object', 4, 'Assert tag entries count before repair step');
$this->assertEntryCount('vcategory', 4, 'Assert tag categories count before repair step'); $this->assertEntryCount('vcategory', 4, 'Assert tag categories count before repair step');
self::invokePrivate($this->repair, 'deleteOrphanFileEntries'); self::invokePrivate($this->repair, 'deleteOrphanFileEntries', [$this->outputMock]);
$this->assertEntryCount('vcategory_to_object', 3, 'Assert tag entries count after cleaning file entries'); $this->assertEntryCount('vcategory_to_object', 3, 'Assert tag entries count after cleaning file entries');
$this->assertEntryCount('vcategory', 4, 'Assert tag categories count after cleaning file entries'); $this->assertEntryCount('vcategory', 4, 'Assert tag categories count after cleaning file entries');
self::invokePrivate($this->repair, 'deleteOrphanTagEntries'); self::invokePrivate($this->repair, 'deleteOrphanTagEntries', [$this->outputMock]);
$this->assertEntryCount('vcategory_to_object', 2, 'Assert tag entries count after cleaning tag entries'); $this->assertEntryCount('vcategory_to_object', 2, 'Assert tag entries count after cleaning tag entries');
$this->assertEntryCount('vcategory', 4, 'Assert tag categories count after cleaning tag entries'); $this->assertEntryCount('vcategory', 4, 'Assert tag categories count after cleaning tag entries');
self::invokePrivate($this->repair, 'deleteOrphanCategoryEntries'); self::invokePrivate($this->repair, 'deleteOrphanCategoryEntries', [$this->outputMock]);
$this->assertEntryCount('vcategory_to_object', 2, 'Assert tag entries count after cleaning category entries'); $this->assertEntryCount('vcategory_to_object', 2, 'Assert tag entries count after cleaning category entries');
$this->assertEntryCount('vcategory', 2, 'Assert tag categories count after cleaning category entries'); $this->assertEntryCount('vcategory', 2, 'Assert tag categories count after cleaning category entries');
} }

View File

@ -9,6 +9,7 @@
namespace Test\Repair; namespace Test\Repair;
use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\IJobList;
use OCP\Migration\IOutput;
/** /**
* Tests for the dropping old tables * Tests for the dropping old tables
@ -33,8 +34,13 @@ class DropOldJobs extends \Test\TestCase {
$this->assertTrue($this->jobList->has('OC\Cache\FileGlobalGC', null), 'Asserting that the job OC\Cache\FileGlobalGC exists before repairing'); $this->assertTrue($this->jobList->has('OC\Cache\FileGlobalGC', null), 'Asserting that the job OC\Cache\FileGlobalGC exists before repairing');
$this->assertTrue($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC exists before repairing'); $this->assertTrue($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC exists before repairing');
/** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
->getMock();
$repair = new \OC\Repair\DropOldJobs($this->jobList); $repair = new \OC\Repair\DropOldJobs($this->jobList);
$repair->run(); $repair->run($outputMock);
$this->assertFalse($this->jobList->has('OC\Cache\FileGlobalGC', null), 'Asserting that the job OC\Cache\FileGlobalGC does not exist after repairing'); $this->assertFalse($this->jobList->has('OC\Cache\FileGlobalGC', null), 'Asserting that the job OC\Cache\FileGlobalGC does not exist after repairing');
$this->assertFalse($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC does not exist after repairing'); $this->assertFalse($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC does not exist after repairing');

View File

@ -7,6 +7,7 @@
*/ */
namespace Test\Repair; namespace Test\Repair;
use OCP\Migration\IOutput;
/** /**
* Tests for the dropping old tables * Tests for the dropping old tables
@ -31,8 +32,13 @@ class DropOldTables extends \Test\TestCase {
$this->assertFalse($this->connection->tableExists('sharing'), 'Asserting that the table oc_sharing does not exist before repairing'); $this->assertFalse($this->connection->tableExists('sharing'), 'Asserting that the table oc_sharing does not exist before repairing');
$this->assertTrue($this->connection->tableExists('permissions'), 'Asserting that the table oc_permissions does exist before repairing'); $this->assertTrue($this->connection->tableExists('permissions'), 'Asserting that the table oc_permissions does exist before repairing');
/** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
->getMock();
$repair = new \OC\Repair\DropOldTables($this->connection); $repair = new \OC\Repair\DropOldTables($this->connection);
$repair->run(); $repair->run($outputMock);
$this->assertFalse($this->connection->tableExists('sharing'), 'Asserting that the table oc_sharing does not exist after repairing'); $this->assertFalse($this->connection->tableExists('sharing'), 'Asserting that the table oc_sharing does not exist after repairing');
$this->assertFalse($this->connection->tableExists('permissions'), 'Asserting that the table oc_permissions does not exist after repairing'); $this->assertFalse($this->connection->tableExists('permissions'), 'Asserting that the table oc_permissions does not exist after repairing');

View File

@ -10,6 +10,7 @@ namespace Test\Repair;
use OC\Repair\OldGroupMembershipShares; use OC\Repair\OldGroupMembershipShares;
use OC\Share\Constants; use OC\Share\Constants;
use OCP\Migration\IOutput;
/** /**
* Class OldGroupMembershipSharesTest * Class OldGroupMembershipSharesTest
@ -82,7 +83,12 @@ class OldGroupMembershipSharesTest extends \Test\TestCase {
$this->assertEquals([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member], ['id' => $notAMember]], $rows); $this->assertEquals([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member], ['id' => $notAMember]], $rows);
$result->closeCursor(); $result->closeCursor();
$repair->run(); /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
->getMock();
$repair->run($outputMock);
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$result = $query->select('id') $result = $query->select('id')

View File

@ -22,6 +22,7 @@
namespace Test\Repair; namespace Test\Repair;
use OC\Repair\RemoveGetETagEntries; use OC\Repair\RemoveGetETagEntries;
use OCP\Migration\IOutput;
use Test\TestCase; use Test\TestCase;
/** /**
@ -65,9 +66,14 @@ class RemoveGetETagEntriesTest extends TestCase {
$this->assertTrue(in_array($entry, $data), 'Asserts that the entries are the ones from the test data set'); $this->assertTrue(in_array($entry, $data), 'Asserts that the entries are the ones from the test data set');
} }
/** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
->getMock();
// run repair step // run repair step
$repair = new RemoveGetETagEntries($this->connection); $repair = new RemoveGetETagEntries($this->connection);
$repair->run(); $repair->run($outputMock);
// check if test data is correctly modified in DB // check if test data is correctly modified in DB
$stmt = $this->connection->executeQuery($sqlToFetchProperties, [$userName]); $stmt = $this->connection->executeQuery($sqlToFetchProperties, [$userName]);

View File

@ -1,4 +1,6 @@
<?php <?php
use OCP\Migration\IOutput;
/** /**
* Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com> * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or * This file is licensed under the Affero General Public License version 3 or
@ -70,7 +72,12 @@ class TestRepairCollation extends \Test\TestCase {
$tables = $this->repair->getAllNonUTF8BinTables($this->connection); $tables = $this->repair->getAllNonUTF8BinTables($this->connection);
$this->assertGreaterThanOrEqual(1, count($tables)); $this->assertGreaterThanOrEqual(1, count($tables));
$this->repair->run(); /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
->getMock();
$this->repair->run($outputMock);
$tables = $this->repair->getAllNonUTF8BinTables($this->connection); $tables = $this->repair->getAllNonUTF8BinTables($this->connection);
$this->assertCount(0, $tables); $this->assertCount(0, $tables);

View File

@ -6,6 +6,8 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
namespace Test\Repair; namespace Test\Repair;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
/** /**
* Tests for the converting of MySQL tables to InnoDB engine * Tests for the converting of MySQL tables to InnoDB engine
@ -16,7 +18,7 @@ namespace Test\Repair;
*/ */
class RepairInnoDB extends \Test\TestCase { class RepairInnoDB extends \Test\TestCase {
/** @var \OC\RepairStep */ /** @var IRepairStep */
private $repair; private $repair;
/** @var \Doctrine\DBAL\Connection */ /** @var \Doctrine\DBAL\Connection */
@ -49,7 +51,12 @@ class RepairInnoDB extends \Test\TestCase {
$result = $this->countMyIsamTables(); $result = $this->countMyIsamTables();
$this->assertEquals(1, $result); $this->assertEquals(1, $result);
$this->repair->run(); /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
->getMock();
$this->repair->run($outputMock);
$result = $this->countMyIsamTables(); $result = $this->countMyIsamTables();
$this->assertEquals(0, $result); $this->assertEquals(0, $result);

View File

@ -11,6 +11,8 @@ namespace Test\Repair;
use OC\Repair\RepairInvalidShares; use OC\Repair\RepairInvalidShares;
use OC\Share\Constants; use OC\Share\Constants;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use Test\TestCase; use Test\TestCase;
/** /**
@ -22,7 +24,7 @@ use Test\TestCase;
*/ */
class RepairInvalidSharesTest extends TestCase { class RepairInvalidSharesTest extends TestCase {
/** @var \OC\RepairStep */ /** @var IRepairStep */
private $repair; private $repair;
/** @var \OCP\IDBConnection */ /** @var \OCP\IDBConnection */
@ -98,7 +100,12 @@ class RepairInvalidSharesTest extends TestCase {
'token' => $qb->expr()->literal('abcdefg') 'token' => $qb->expr()->literal('abcdefg')
])->execute(); ])->execute();
$this->repair->run(); /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
->getMock();
$this->repair->run($outputMock);
$results = $this->connection->getQueryBuilder() $results = $this->connection->getQueryBuilder()
->select('*') ->select('*')
@ -167,7 +174,12 @@ class RepairInvalidSharesTest extends TestCase {
$this->assertEquals([['id' => $parent], ['id' => $validChild], ['id' => $invalidChild]], $rows); $this->assertEquals([['id' => $parent], ['id' => $validChild], ['id' => $invalidChild]], $rows);
$result->closeCursor(); $result->closeCursor();
$this->repair->run(); /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
->getMock();
$this->repair->run($outputMock);
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$result = $query->select('id') $result = $query->select('id')

View File

@ -10,6 +10,8 @@ namespace Test\Repair;
use OC\Files\Cache\Cache; use OC\Files\Cache\Cache;
use OC\Files\Cache\Storage; use OC\Files\Cache\Storage;
use OCP\Migration\IOutput;
use PHPUnit_Framework_MockObject_MockObject;
use Test\TestCase; use Test\TestCase;
/** /**
@ -34,7 +36,8 @@ class RepairLegacyStorages extends TestCase {
private $legacyStorageId; private $legacyStorageId;
private $newStorageId; private $newStorageId;
private $warnings; /** @var IOutput | PHPUnit_Framework_MockObject_MockObject */
private $outputMock;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
@ -45,11 +48,9 @@ class RepairLegacyStorages extends TestCase {
$this->repair = new \OC\Repair\RepairLegacyStorages($this->config, $this->connection); $this->repair = new \OC\Repair\RepairLegacyStorages($this->config, $this->connection);
$this->warnings = []; $this->outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
$this->repair->listen('\OC\Repair', 'warning', function ($description){ ->getMock();
$this->warnings[] = $description;
});
} }
protected function tearDown() { protected function tearDown() {
@ -141,7 +142,7 @@ class RepairLegacyStorages extends TestCase {
$this->prepareSettings($dataDir, $userId); $this->prepareSettings($dataDir, $userId);
$newStorageNumId = $this->createStorage($this->newStorageId); $newStorageNumId = $this->createStorage($this->newStorageId);
$this->repair->run(); $this->repair->run($this->outputMock);
$this->assertNull($this->getStorageId($this->legacyStorageId)); $this->assertNull($this->getStorageId($this->legacyStorageId));
$this->assertEquals($newStorageNumId, $this->getStorageId($this->newStorageId)); $this->assertEquals($newStorageNumId, $this->getStorageId($this->newStorageId));
@ -160,7 +161,7 @@ class RepairLegacyStorages extends TestCase {
$this->prepareSettings($dataDir, $userId); $this->prepareSettings($dataDir, $userId);
$legacyStorageNumId = $this->createStorage($this->legacyStorageId); $legacyStorageNumId = $this->createStorage($this->legacyStorageId);
$this->repair->run(); $this->repair->run($this->outputMock);
$this->assertNull($this->getStorageId($this->legacyStorageId)); $this->assertNull($this->getStorageId($this->legacyStorageId));
$this->assertEquals($legacyStorageNumId, $this->getStorageId($this->newStorageId)); $this->assertEquals($legacyStorageNumId, $this->getStorageId($this->newStorageId));
@ -182,7 +183,7 @@ class RepairLegacyStorages extends TestCase {
$this->createData($this->legacyStorageId); $this->createData($this->legacyStorageId);
$this->repair->run(); $this->repair->run($this->outputMock);
$this->assertNull($this->getStorageId($this->legacyStorageId)); $this->assertNull($this->getStorageId($this->legacyStorageId));
$this->assertEquals($legacyStorageNumId, $this->getStorageId($this->newStorageId)); $this->assertEquals($legacyStorageNumId, $this->getStorageId($this->newStorageId));
@ -205,7 +206,7 @@ class RepairLegacyStorages extends TestCase {
$this->createData($this->newStorageId); $this->createData($this->newStorageId);
$this->repair->run(); $this->repair->run($this->outputMock);
$this->assertNull($this->getStorageId($this->legacyStorageId)); $this->assertNull($this->getStorageId($this->legacyStorageId));
$this->assertEquals($newStorageNumId, $this->getStorageId($this->newStorageId)); $this->assertEquals($newStorageNumId, $this->getStorageId($this->newStorageId));
@ -228,10 +229,8 @@ class RepairLegacyStorages extends TestCase {
$this->createData($this->legacyStorageId); $this->createData($this->legacyStorageId);
$this->createData($this->newStorageId); $this->createData($this->newStorageId);
$this->repair->run(); $this->outputMock->expects($this->exactly(2))->method('warning');
$this->repair->run($this->outputMock);
$this->assertEquals(2, count($this->warnings));
$this->assertEquals('Could not repair legacy storage ', substr(current($this->warnings), 0, 32));
// storages left alone // storages left alone
$this->assertEquals($legacyStorageNumId, $this->getStorageId($this->legacyStorageId)); $this->assertEquals($legacyStorageNumId, $this->getStorageId($this->legacyStorageId));
@ -254,7 +253,7 @@ class RepairLegacyStorages extends TestCase {
$storageId = 'local::' . $this->dataDir; $storageId = 'local::' . $this->dataDir;
$numId = $this->createStorage($storageId); $numId = $this->createStorage($storageId);
$this->repair->run(); $this->repair->run($this->outputMock);
$this->assertEquals($numId, $this->getStorageId($storageId)); $this->assertEquals($numId, $this->getStorageId($storageId));
} }
@ -272,7 +271,7 @@ class RepairLegacyStorages extends TestCase {
$storageId = 'local::/tmp/somedir/' . $this->user; $storageId = 'local::/tmp/somedir/' . $this->user;
$numId = $this->createStorage($storageId); $numId = $this->createStorage($storageId);
$this->repair->run(); $this->repair->run($this->outputMock);
$this->assertEquals($numId, $this->getStorageId($storageId)); $this->assertEquals($numId, $this->getStorageId($storageId));
} }
@ -290,7 +289,7 @@ class RepairLegacyStorages extends TestCase {
$storageId = 'smb::user@password/tmp/somedir/' . $this->user; $storageId = 'smb::user@password/tmp/somedir/' . $this->user;
$numId = $this->createStorage($storageId); $numId = $this->createStorage($storageId);
$this->repair->run(); $this->repair->run($this->outputMock);
$this->assertEquals($numId, $this->getStorageId($storageId)); $this->assertEquals($numId, $this->getStorageId($storageId));
} }
@ -322,21 +321,15 @@ class RepairLegacyStorages extends TestCase {
* Only run the repair once * Only run the repair once
*/ */
public function testOnlyRunOnce() { public function testOnlyRunOnce() {
$output = array(); $this->outputMock->expects($this->exactly(1))->method('info');
$this->repair->listen('\OC\Repair', 'info', function ($description) use (&$output) {
$output[] = 'info: ' . $description;
});
$this->prepareSettings('/tmp/oc-autotest/datadir', $this->getUniqueID('user_')); $this->prepareSettings('/tmp/oc-autotest/datadir', $this->getUniqueID('user_'));
$this->assertNotEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone')); $this->assertNotEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone'));
$this->repair->run(); $this->repair->run($this->outputMock);
$this->assertEquals(1, count($output));
$this->assertEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone')); $this->assertEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone'));
$output = array(); $this->outputMock->expects($this->never())->method('info');
$this->repair->run(); $this->repair->run($this->outputMock);
// no output which means it did not run
$this->assertEquals(0, count($output));
$this->assertEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone')); $this->assertEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone'));
} }
} }

View File

@ -8,6 +8,12 @@
*/ */
namespace Test\Repair; namespace Test\Repair;
use OC\Files\Storage\Temporary;
use OCP\Files\IMimeTypeLoader;
use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
/** /**
* Tests for the converting of legacy storages to home storages. * Tests for the converting of legacy storages to home storages.
* *
@ -17,17 +23,22 @@ namespace Test\Repair;
*/ */
class RepairMimeTypes extends \Test\TestCase { class RepairMimeTypes extends \Test\TestCase {
/** @var \OC\RepairStep */ /** @var IRepairStep */
private $repair; private $repair;
/** @var Temporary */
private $storage; private $storage;
/** @var IMimeTypeLoader */
private $mimetypeLoader;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->savedMimetypeLoader = \OC::$server->getMimeTypeLoader(); $this->savedMimetypeLoader = \OC::$server->getMimeTypeLoader();
$this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); $this->mimetypeLoader = \OC::$server->getMimeTypeLoader();
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject $config */
$config = $this->getMockBuilder('OCP\IConfig') $config = $this->getMockBuilder('OCP\IConfig')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@ -96,7 +107,12 @@ class RepairMimeTypes extends \Test\TestCase {
private function renameMimeTypes($currentMimeTypes, $fixedMimeTypes) { private function renameMimeTypes($currentMimeTypes, $fixedMimeTypes) {
$this->addEntries($currentMimeTypes); $this->addEntries($currentMimeTypes);
$this->repair->run(); /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
->getMock();
$this->repair->run($outputMock);
// force mimetype reload // force mimetype reload
$this->mimetypeLoader->reset(); $this->mimetypeLoader->reset();

View File

@ -9,6 +9,7 @@
namespace Test\Repair; namespace Test\Repair;
use OC\Repair\SharePropagation; use OC\Repair\SharePropagation;
use OCP\Migration\IOutput;
class RepairSharePropagation extends \Test\TestCase { class RepairSharePropagation extends \Test\TestCase {
public function keyProvider() { public function keyProvider() {
@ -40,8 +41,13 @@ class RepairSharePropagation extends \Test\TestCase {
$removedKeys[] = $key; $removedKeys[] = $key;
})); }));
/** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
->getMock();
$step = new SharePropagation($config); $step = new SharePropagation($config);
$step->run(); $step->run($outputMock);
sort($expectedRemovedKeys); sort($expectedRemovedKeys);
sort($removedKeys); sort($removedKeys);

View File

@ -7,6 +7,7 @@
*/ */
namespace Test\Repair; namespace Test\Repair;
use OCP\Migration\IOutput;
/** /**
* Tests for fixing the SQLite id recycling * Tests for fixing the SQLite id recycling
@ -76,7 +77,12 @@ class RepairSqliteAutoincrement extends \Test\TestCase {
public function testConvertIdColumn() { public function testConvertIdColumn() {
$this->assertFalse($this->checkAutoincrement()); $this->assertFalse($this->checkAutoincrement());
$this->repair->run(); /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
->disableOriginalConstructor()
->getMock();
$this->repair->run($outputMock);
$this->assertTrue($this->checkAutoincrement()); $this->assertTrue($this->checkAutoincrement());
} }

View File

@ -30,7 +30,7 @@ use Test\TestCase;
* @package Test\Repair * @package Test\Repair
*/ */
class UpdateOutdatedOcsIds extends TestCase { class UpdateOutdatedOcsIds extends TestCase {
/** @var IConfig */ /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
private $config; private $config;
/** @var \OC\Repair\UpdateOutdatedOcsIds */ /** @var \OC\Repair\UpdateOutdatedOcsIds */
private $updateOutdatedOcsIds; private $updateOutdatedOcsIds;