-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from owncloud/fix-absolute-urls
Add command to repair notifications and properly handle mail sending …
- Loading branch information
Showing
6 changed files
with
203 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* @author Jannik Stehle <[email protected]> | ||
* @author Jan Ackermann <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2021, ownCloud GmbH | ||
* @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 OCA\Notifications\Command; | ||
|
||
use OCA\Notifications\Handler; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class RepairNotifications extends Command { | ||
|
||
/** @var Handler */ | ||
protected $handler; | ||
|
||
public static $availableSubjects = [ | ||
'relativeLinks' | ||
]; | ||
|
||
/** | ||
* @param Handler $handler | ||
*/ | ||
public function __construct(Handler $handler) { | ||
parent::__construct(); | ||
$this->handler = $handler; | ||
} | ||
|
||
protected function configure() { | ||
$this | ||
->setName('notifications:repairNotifications') | ||
->setDescription('Repair existing notifications') | ||
->addArgument('subject', InputArgument::REQUIRED, 'Subject to repair') | ||
; | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
$subject = $input->getArgument('subject'); | ||
|
||
if (!\in_array($subject, self::$availableSubjects)) { | ||
$output->writeln('Invalid subject'); | ||
return 1; | ||
} | ||
|
||
$updatedNotificationsCount = $this->handler->removeBaseUrlFromAbsoluteLinks(); | ||
|
||
$output->writeln("$updatedNotificationsCount notifications were updated"); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* @author Jannik Stehle <[email protected]> | ||
* @author Jan Ackermann <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2021, ownCloud GmbH | ||
* @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 OCA\Notifications\Tests\Unit\Command; | ||
|
||
use OCA\Notifications\Command\Generate; | ||
use OCA\Notifications\Command\RepairNotifications; | ||
use OCA\Notifications\Handler; | ||
use OCA\Notifications\Tests\Unit\TestCase; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class RepairNotificationsTest extends TestCase { | ||
|
||
/** @var Handler | \PHPUnit\Framework\MockObject\MockObject */ | ||
protected $handler; | ||
/** @var Generate */ | ||
protected $command; | ||
/** @var CommandTester */ | ||
protected $tester; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->handler = $this->createMock(Handler::class); | ||
$this->command = new RepairNotifications($this->handler); | ||
$this->tester = new CommandTester($this->command); | ||
} | ||
|
||
public function testInvalidSubject() { | ||
$options = []; | ||
$input = ['subject' => 'test']; | ||
$response = $this->tester->execute($input, $options); | ||
$this->assertEquals(1, $response); | ||
} | ||
|
||
public function testRepairLinks() { | ||
$options = []; | ||
$input = ['subject' => RepairNotifications::$availableSubjects[0]]; | ||
|
||
$this->handler->expects($this->once())->method('removeBaseUrlFromAbsoluteLinks'); | ||
|
||
$response = $this->tester->execute($input, $options); | ||
$this->assertEquals(0, $response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters