Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@
'OC\\Repair\\AddCleanupUpdaterBackupsJob' => $baseDir . '/lib/private/Repair/AddCleanupUpdaterBackupsJob.php',
'OC\\Repair\\CleanTags' => $baseDir . '/lib/private/Repair/CleanTags.php',
'OC\\Repair\\ClearFrontendCaches' => $baseDir . '/lib/private/Repair/ClearFrontendCaches.php',
'OC\\Repair\\ClearGeneratedAvatarCache' => $baseDir . '/lib/private/Repair/ClearGeneratedAvatarCache.php',
'OC\\Repair\\Collation' => $baseDir . '/lib/private/Repair/Collation.php',
'OC\\Repair\\MoveUpdaterStepFile' => $baseDir . '/lib/private/Repair/MoveUpdaterStepFile.php',
'OC\\Repair\\NC11\\FixMountStorages' => $baseDir . '/lib/private/Repair/NC11/FixMountStorages.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Repair\\AddCleanupUpdaterBackupsJob' => __DIR__ . '/../../..' . '/lib/private/Repair/AddCleanupUpdaterBackupsJob.php',
'OC\\Repair\\CleanTags' => __DIR__ . '/../../..' . '/lib/private/Repair/CleanTags.php',
'OC\\Repair\\ClearFrontendCaches' => __DIR__ . '/../../..' . '/lib/private/Repair/ClearFrontendCaches.php',
'OC\\Repair\\ClearGeneratedAvatarCache' => __DIR__ . '/../../..' . '/lib/private/Repair/ClearGeneratedAvatarCache.php',
'OC\\Repair\\Collation' => __DIR__ . '/../../..' . '/lib/private/Repair/Collation.php',
'OC\\Repair\\MoveUpdaterStepFile' => __DIR__ . '/../../..' . '/lib/private/Repair/MoveUpdaterStepFile.php',
'OC\\Repair\\NC11\\FixMountStorages' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/FixMountStorages.php',
Expand Down
8 changes: 4 additions & 4 deletions lib/private/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ class Avatar implements IAvatar {
* @param IConfig $config
*/
public function __construct(ISimpleFolder $folder,
IL10N $l,
$user,
ILogger $logger,
IConfig $config) {
IL10N $l,
$user,
ILogger $logger,
IConfig $config) {
$this->folder = $folder;
$this->l = $l;
$this->user = $user;
Expand Down
16 changes: 16 additions & 0 deletions lib/private/AvatarManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,20 @@ public function getAvatar(string $userId) : IAvatar {

return new Avatar($folder, $this->l, $user, $this->logger, $this->config);
}

/**
* Clear generated avatars
*/
public function clearCachedAvatars() {
$users = $this->config->getUsersForUserValue('avatar', 'generated', 'true');
foreach($users as $userId) {
try {
$folder = $this->appData->getFolder($userId);
$folder->delete();
} catch (NotFoundException $e) {
$this->logger->debug("No cache for the user $userId. Ignoring...");
}
$this->config->setUserValue($userId, 'avatar', 'generated', 'false');
}
}
}
35 changes: 21 additions & 14 deletions lib/private/Repair.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,42 @@

namespace OC;

use OCP\AppFramework\QueryException;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use OC\AvatarManager;
use OC\Repair\AddCleanupUpdaterBackupsJob;
use OC\Repair\CleanTags;
use OC\Repair\ClearGeneratedAvatarCache;
use OC\Repair\ClearFrontendCaches;
use OC\Repair\Collation;
use OC\Repair\MoveUpdaterStepFile;
use OC\Repair\NC11\FixMountStorages;
use OC\Repair\NC13\AddLogRotateJob;
use OC\Repair\NC13\RepairInvalidPaths;
use OC\Repair\NC14\AddPreviewBackgroundCleanupJob;
use OC\Repair\NC14\RepairPendingCronJobs;
use OC\Repair\NC15\SetVcardDatabaseUID;
use OC\Repair\OldGroupMembershipShares;
use OC\Repair\Owncloud\DropAccountTermsTable;
use OC\Repair\Owncloud\SaveAccountsTableData;
use OC\Repair\RemoveRootShares;
use OC\Repair\NC13\RepairInvalidPaths;
use OC\Repair\SqliteAutoincrement;
use OC\Repair\RepairMimeTypes;
use OC\Repair\RepairInvalidShares;
use OC\Repair\RepairMimeTypes;
use OC\Repair\SqliteAutoincrement;
use OC\Template\JSCombiner;
use OC\Template\SCSSCacher;
use OCP\AppFramework\QueryException;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;

class Repair implements IOutput{
/* @var IRepairStep[] */
class Repair implements IOutput {

/** @var IRepairStep[] */
private $repairSteps;

/** @var EventDispatcher */
private $dispatcher;

/** @var string */
private $currentStep;

Expand All @@ -72,7 +77,7 @@ class Repair implements IOutput{
*/
public function __construct($repairSteps = [], EventDispatcher $dispatcher = null) {
$this->repairSteps = $repairSteps;
$this->dispatcher = $dispatcher;
$this->dispatcher = $dispatcher;
}

/**
Expand All @@ -81,6 +86,7 @@ public function __construct($repairSteps = [], EventDispatcher $dispatcher = nul
public function run() {
if (count($this->repairSteps) === 0) {
$this->emit('\OC\Repair', 'info', array('No repair steps available'));

return;
}
// run each repair step
Expand Down Expand Up @@ -137,10 +143,11 @@ public static function getRepairSteps() {
new RepairInvalidPaths(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
new AddLogRotateJob(\OC::$server->getJobList()),
new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)),
new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)),
new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()),
new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()),
new RepairPendingCronJobs(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always kept a trailing , in arrays to make the diff for adding a new entry nicer. It then only has this one line added instead of also appending a , to the previous line.

];
}

Expand All @@ -152,7 +159,7 @@ public static function getRepairSteps() {
*/
public static function getExpensiveRepairSteps() {
return [
new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()),
new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager())
];
}

Expand All @@ -164,12 +171,12 @@ public static function getExpensiveRepairSteps() {
*/
public static function getBeforeUpgradeRepairSteps() {
$connection = \OC::$server->getDatabaseConnection();
$config = \OC::$server->getConfig();
$steps = [
$config = \OC::$server->getConfig();
$steps = [
new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true),
new SqliteAutoincrement($connection),
new SaveAccountsTableData($connection, $config),
new DropAccountTermsTable($connection),
new DropAccountTermsTable($connection)
];

return $steps;
Expand Down
8 changes: 4 additions & 4 deletions lib/private/Repair/ClearFrontendCaches.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

namespace OC\Repair;

use OC\Template\JSCombiner;
use OC\Template\SCSSCacher;
use OCP\ICacheFactory;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use OC\Template\JSCombiner;
use OC\Template\SCSSCacher;

class ClearFrontendCaches implements IRepairStep {

Expand All @@ -44,8 +44,8 @@ public function __construct(ICacheFactory $cacheFactory,
SCSSCacher $SCSSCacher,
JSCombiner $JSCombiner) {
$this->cacheFactory = $cacheFactory;
$this->scssCacher = $SCSSCacher;
$this->jsCombiner = $JSCombiner;
$this->scssCacher = $SCSSCacher;
$this->jsCombiner = $JSCombiner;
}

public function getName() {
Expand Down
72 changes: 72 additions & 0 deletions lib/private/Repair/ClearGeneratedAvatarCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* @copyright Copyright (c) 2018 John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OC\Repair;

use OC\AvatarManager;
use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use OCP\Util;

class ClearGeneratedAvatarCache implements IRepairStep {

/** @var AvatarManager */
protected $avatarManager;

/** @var IConfig */
private $config;

public function __construct(IConfig $config, AvatarManager $avatarManager) {
$this->config = $config;
$this->avatarManager = $avatarManager;
}

public function getName() {
return 'Clear every generated avatar on major updates';
}

/**
* Check if this repair step should run
*
* @return boolean
*/
private function shouldRun() {
$versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0');

// was added to 15.0.0.4
return version_compare($versionFromBeforeUpdate, '15.0.0.4', '<=');
}

public function run(IOutput $output) {
if ($this->shouldRun()) {
try {
$this->avatarManager->clearCachedAvatars();
$output->info('Avatar cache cleared');
} catch (\Exception $e) {
$output->warning('Unable to clear the avatar cache');
}

}
}
}
5 changes: 3 additions & 2 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public function __construct($webRoot, \OC\Config $config) {
});
$this->registerAlias(IValidator::class, Validator::class);

$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
$this->registerService(AvatarManager::class, function(Server $c) {
return new AvatarManager(
$c->query(\OC\User\Manager::class),
$c->getAppDataDir('avatar'),
Expand All @@ -548,7 +548,8 @@ public function __construct($webRoot, \OC\Config $config) {
$c->getConfig()
);
});
$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
$this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class);
$this->registerAlias('AvatarManager', AvatarManager::class);

$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);

Expand Down
1 change: 1 addition & 0 deletions lib/public/IAvatarManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ interface IAvatarManager {
* @since 6.0.0
*/
public function getAvatar(string $user) : IAvatar;

}
82 changes: 82 additions & 0 deletions tests/lib/Repair/ClearGeneratedAvatarCacheTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* @copyright Copyright (c) 2018 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace Test\Repair;

use OCP\IConfig;
use OCP\Migration\IOutput;
use OC\AvatarManager;
use OC\Repair\ClearGeneratedAvatarCache;

class ClearGeneratedAvatarCacheTest extends \Test\TestCase {

/** @var AvatarManager */
private $avatarManager;

/** @var IOutput */
private $outputMock;

/** @var IConfig */
private $config;

/** @var ClearGeneratedAvatarCache */
protected $repair;

protected function setUp() {
parent::setUp();

$this->outputMock = $this->createMock(IOutput::class);
$this->avatarManager = $this->createMock(AvatarManager::class);
$this->config = $this->createMock(IConfig::class);

$this->repair = new ClearGeneratedAvatarCache($this->config, $this->avatarManager);
}

public function shouldRunDataProvider() {
return [
['11.0.0.0', true],
['15.0.0.3', true],
['13.0.5.2', true],
['12.0.0.0', true],
['16.0.0.1', false],
['15.0.0.2', true],
['13.0.0.0', true],
['15.0.0.5', false]
];
}

/**
* @dataProvider shouldRunDataProvider
*
* @param string $from
* @param boolean $expected
*/
public function testShouldRun($from, $expected) {
$this->config->expects($this->any())
->method('getSystemValue')
->with('version', '0.0.0.0')
->willReturn($from);

$this->assertEquals($expected, $this->invokePrivate($this->repair, 'shouldRun'));
}
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
// when updating major/minor version number.

$OC_Version = array(15, 0, 0, 3);
$OC_Version = array(15, 0, 0, 4);

// The human readable string
$OC_VersionString = '15.0.0 alpha';
Expand Down