diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 4658fadf1a2..0a044416950 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1669,7 +1669,6 @@ return array( 'OC\\Remote\\Instance' => $baseDir . '/lib/private/Remote/Instance.php', 'OC\\Remote\\InstanceFactory' => $baseDir . '/lib/private/Remote/InstanceFactory.php', 'OC\\Remote\\User' => $baseDir . '/lib/private/Remote/User.php', - 'OC\\Repair' => $baseDir . '/lib/private/Repair.php', 'OC\\RepairException' => $baseDir . '/lib/private/RepairException.php', 'OC\\Repair\\AddAppConfigLazyMigration' => $baseDir . '/lib/private/Repair/AddAppConfigLazyMigration.php', 'OC\\Repair\\AddBruteForceCleanupJob' => $baseDir . '/lib/private/Repair/AddBruteForceCleanupJob.php', @@ -1705,7 +1704,8 @@ return array( 'OC\\Repair\\NC22\\LookupServerSendCheck' => $baseDir . '/lib/private/Repair/NC22/LookupServerSendCheck.php', 'OC\\Repair\\NC24\\AddTokenCleanupJob' => $baseDir . '/lib/private/Repair/NC24/AddTokenCleanupJob.php', 'OC\\Repair\\NC25\\AddMissingSecretJob' => $baseDir . '/lib/private/Repair/NC25/AddMissingSecretJob.php', - 'OC\\Repair\\NC29\\ValidateAccountProperties' => $baseDir . '/lib/private/Repair/NC29/ValidateAccountProperties.php', + 'OC\\Repair\\NC29\\SanitizeAccountProperties' => $baseDir . '/lib/private/Repair/NC29/SanitizeAccountProperties.php', + 'OC\\Repair\\NC29\\SanitizeAccountPropertiesJob' => $baseDir . '/lib/private/Repair/NC29/SanitizeAccountPropertiesJob.php', 'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php', 'OC\\Repair\\Owncloud\\CleanPreviews' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviews.php', 'OC\\Repair\\Owncloud\\CleanPreviewsBackgroundJob' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 903ba3c6edb..a08eeb0d1ea 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1702,7 +1702,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Remote\\Instance' => __DIR__ . '/../../..' . '/lib/private/Remote/Instance.php', 'OC\\Remote\\InstanceFactory' => __DIR__ . '/../../..' . '/lib/private/Remote/InstanceFactory.php', 'OC\\Remote\\User' => __DIR__ . '/../../..' . '/lib/private/Remote/User.php', - 'OC\\Repair' => __DIR__ . '/../../..' . '/lib/private/Repair.php', 'OC\\RepairException' => __DIR__ . '/../../..' . '/lib/private/RepairException.php', 'OC\\Repair\\AddAppConfigLazyMigration' => __DIR__ . '/../../..' . '/lib/private/Repair/AddAppConfigLazyMigration.php', 'OC\\Repair\\AddBruteForceCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Repair/AddBruteForceCleanupJob.php', @@ -1738,7 +1737,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Repair\\NC22\\LookupServerSendCheck' => __DIR__ . '/../../..' . '/lib/private/Repair/NC22/LookupServerSendCheck.php', 'OC\\Repair\\NC24\\AddTokenCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC24/AddTokenCleanupJob.php', 'OC\\Repair\\NC25\\AddMissingSecretJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC25/AddMissingSecretJob.php', - 'OC\\Repair\\NC29\\ValidateAccountProperties' => __DIR__ . '/../../..' . '/lib/private/Repair/NC29/ValidateAccountProperties.php', + 'OC\\Repair\\NC29\\SanitizeAccountProperties' => __DIR__ . '/../../..' . '/lib/private/Repair/NC29/SanitizeAccountProperties.php', + 'OC\\Repair\\NC29\\SanitizeAccountPropertiesJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC29/SanitizeAccountPropertiesJob.php', 'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php', 'OC\\Repair\\Owncloud\\CleanPreviews' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/CleanPreviews.php', 'OC\\Repair\\Owncloud\\CleanPreviewsBackgroundJob' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php', diff --git a/lib/private/Repair.php b/lib/private/Repair.php index def22476a2b..f453f3e50de 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -68,7 +68,7 @@ use OC\Repair\NC21\AddCheckForUserCertificatesJob; use OC\Repair\NC22\LookupServerSendCheck; use OC\Repair\NC24\AddTokenCleanupJob; use OC\Repair\NC25\AddMissingSecretJob; -use OC\Repair\NC29\ValidateAccountProperties; +use OC\Repair\NC29\SanitizeAccountProperties; use OC\Repair\OldGroupMembershipShares; use OC\Repair\Owncloud\CleanPreviews; use OC\Repair\Owncloud\DropAccountTermsTable; @@ -215,6 +215,7 @@ class Repair implements IOutput { \OCP\Server::get(AddAppConfigLazyMigration::class), \OCP\Server::get(RepairLogoDimension::class), \OCP\Server::get(AddCleanupDeletedUsersBackgroundJob::class), + \OCP\Server::get(SanitizeAccountProperties::class), ]; } @@ -229,7 +230,6 @@ class Repair implements IOutput { new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), new RemoveBrokenProperties(\OC::$server->getDatabaseConnection()), new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), - \OC::$server->get(ValidateAccountProperties::class), \OC::$server->get(DeleteSchedulingObjects::class), ]; } diff --git a/lib/private/Repair/NC29/SanitizeAccountProperties.php b/lib/private/Repair/NC29/SanitizeAccountProperties.php new file mode 100644 index 00000000000..412570ba71d --- /dev/null +++ b/lib/private/Repair/NC29/SanitizeAccountProperties.php @@ -0,0 +1,30 @@ +jobList->add(SanitizeAccountPropertiesJob::class, null); + $output->info('Queued background to validate account properties.'); + } +} diff --git a/lib/private/Repair/NC29/ValidateAccountProperties.php b/lib/private/Repair/NC29/SanitizeAccountPropertiesJob.php similarity index 84% rename from lib/private/Repair/NC29/ValidateAccountProperties.php rename to lib/private/Repair/NC29/SanitizeAccountPropertiesJob.php index 640cd678ba0..55ec445e9da 100644 --- a/lib/private/Repair/NC29/ValidateAccountProperties.php +++ b/lib/private/Repair/NC29/SanitizeAccountPropertiesJob.php @@ -10,13 +10,13 @@ namespace OC\Repair\NC29; use InvalidArgumentException; use OCP\Accounts\IAccountManager; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\QueuedJob; use OCP\IUser; use OCP\IUserManager; -use OCP\Migration\IOutput; -use OCP\Migration\IRepairStep; use Psr\Log\LoggerInterface; -class ValidateAccountProperties implements IRepairStep { +class SanitizeAccountPropertiesJob extends QueuedJob { private const PROPERTIES_TO_CHECK = [ IAccountManager::PROPERTY_PHONE, @@ -26,17 +26,16 @@ class ValidateAccountProperties implements IRepairStep { ]; public function __construct( + ITimeFactory $timeFactory, private IUserManager $userManager, private IAccountManager $accountManager, private LoggerInterface $logger, ) { + parent::__construct($timeFactory); + $this->setAllowParallelRuns(false); } - public function getName(): string { - return 'Validate account properties and store phone numbers in a known format for search'; - } - - public function run(IOutput $output): void { + protected function run(mixed $argument): void { $numRemoved = 0; $this->userManager->callForSeenUsers(function (IUser $user) use (&$numRemoved) { @@ -70,7 +69,7 @@ class ValidateAccountProperties implements IRepairStep { }); if ($numRemoved > 0) { - $output->info('Cleaned ' . $numRemoved . ' invalid account property entries'); + $this->logger->info('Cleaned ' . $numRemoved . ' invalid account property entries'); } } } diff --git a/tests/lib/Repair/NC29/ValidateAccountPropertiesTest.php b/tests/lib/Repair/NC29/SanitizeAccountPropertiesJobTest.php similarity index 80% rename from tests/lib/Repair/NC29/ValidateAccountPropertiesTest.php rename to tests/lib/Repair/NC29/SanitizeAccountPropertiesJobTest.php index e113f180998..8d54175770e 100644 --- a/tests/lib/Repair/NC29/ValidateAccountPropertiesTest.php +++ b/tests/lib/Repair/NC29/SanitizeAccountPropertiesJobTest.php @@ -12,31 +12,36 @@ use InvalidArgumentException; use OCP\Accounts\IAccount; use OCP\Accounts\IAccountManager; use OCP\Accounts\IAccountProperty; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\IUser; use OCP\IUserManager; -use OCP\Migration\IOutput; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; -class ValidateAccountPropertiesTest extends TestCase { +class SanitizeAccountPropertiesJobTest extends TestCase { - private IUserManager&MockObject $userManager; - private IAccountManager&MockObject $accountManager; - private LoggerInterface&MockObject $logger; + private IUserManager|MockObject $userManager; + private IAccountManager|MockObject $accountManager; + private LoggerInterface|MockObject $logger; - private ValidateAccountProperties $repairStep; + private SanitizeAccountPropertiesJob $job; protected function setUp(): void { $this->userManager = $this->createMock(IUserManager::class); $this->accountManager = $this->createMock(IAccountManager::class); $this->logger = $this->createMock(LoggerInterface::class); - $this->repairStep = new ValidateAccountProperties($this->userManager, $this->accountManager, $this->logger); + $this->job = new SanitizeAccountPropertiesJob( + $this->createMock(ITimeFactory::class), + $this->userManager, + $this->accountManager, + $this->logger, + ); } - public function testGetName(): void { - self::assertStringContainsString('Validate account properties', $this->repairStep->getName()); + public function testParallel() { + self::assertFalse($this->job->getAllowParallelRuns()); } public function testRun(): void { @@ -106,9 +111,6 @@ class ValidateAccountPropertiesTest extends TestCase { } }); - $output = $this->createMock(IOutput::class); - $output->expects(self::once())->method('info')->with('Cleaned 1 invalid account property entries'); - - $this->repairStep->run($output); + self::invokePrivate($this->job, 'run', [null]); } } diff --git a/tests/lib/Repair/NC29/SanitizeAccountPropertiesTest.php b/tests/lib/Repair/NC29/SanitizeAccountPropertiesTest.php new file mode 100644 index 00000000000..778281885d8 --- /dev/null +++ b/tests/lib/Repair/NC29/SanitizeAccountPropertiesTest.php @@ -0,0 +1,43 @@ +jobList = $this->createMock(IJobList::class); + + $this->repairStep = new SanitizeAccountProperties($this->jobList); + } + + public function testGetName(): void { + self::assertStringContainsString('Validate account properties', $this->repairStep->getName()); + } + + public function testRun(): void { + $this->jobList->expects(self::once()) + ->method('add') + ->with(SanitizeAccountPropertiesJob::class, null); + + $output = $this->createMock(IOutput::class); + $output->expects(self::once()) + ->method('info') + ->with(self::matchesRegularExpression('/queued background/i')); + + $this->repairStep->run($output); + } +}