Skip to content

Commit

Permalink
move string to constant APP_ID
Browse files Browse the repository at this point in the history
Signed-off-by: dartcafe <[email protected]>
  • Loading branch information
dartcafe committed Aug 12, 2023
1 parent bd51f23 commit d9b293a
Show file tree
Hide file tree
Showing 34 changed files with 164 additions and 152 deletions.
7 changes: 4 additions & 3 deletions lib/Activity/PollChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
namespace OCA\Polls\Activity;

use OCA\Polls\AppInfo\AppConstants;
use OCP\Activity\IFilter;
use OCP\IL10N;
use OCP\IURLGenerator;
Expand All @@ -34,23 +35,23 @@ public function __construct(
}

public function getIdentifier() : string {
return 'polls';
return AppConstants::APP_ID;
}

public function getName() : string {
return $this->l10n->t('Poll changes');
}

public function getIcon() : string {
return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('polls', 'polls.svg'));
return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath(AppConstants::APP_ID, 'polls.svg'));
}

public function getPriority() : int {
return 70;
}

public function allowedApps() : array {
return ['polls'];
return [AppConstants::APP_ID];
}

public function filterTypes(array $types) : array {
Expand Down
30 changes: 30 additions & 0 deletions lib/AppInfo/AppConstants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* @copyright Copyright (c) 2023 René Gieling <[email protected]>
*
* @author René Gieling <[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 OCA\Polls\AppInfo;

abstract class AppConstants {
/** @var string */
public const APP_ID = 'polls';
}
4 changes: 2 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@

class Application extends App implements IBootstrap {
/** @var string */
public const APP_ID = 'polls';
public const APP_ID = AppConstants::APP_ID;

public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
parent::__construct(AppConstants::APP_ID, $urlParams);
}

public function boot(IBootContext $context): void {
Expand Down
3 changes: 2 additions & 1 deletion lib/Command/Poll/TransferOwnership.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Polls\Command\Poll;

use OCA\Polls\AppInfo\AppConstants;
use OCA\Polls\Service\PollService;
use OCP\IUser;
use OCP\IUserManager;
Expand All @@ -42,7 +43,7 @@ public function __construct(

protected function configure(): void {
$this
->setName('polls:poll:transfer-ownership')
->setName(AppConstants::APP_ID . ':poll:transfer-ownership')
->setDescription('Transfer the ownership of one user\'s polls to another user.')
->addArgument(
'source-user',
Expand Down
3 changes: 2 additions & 1 deletion lib/Command/Share/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace OCA\Polls\Command\Share;

use OC\Core\Command\Base;
use OCA\Polls\AppInfo\AppConstants;
use OCA\Polls\Db\Poll;
use OCA\Polls\Exceptions\ShareAlreadyExistsException;
use OCA\Polls\Model\Group\Group;
Expand All @@ -41,7 +42,7 @@ class Add extends Base {

protected function configure(): void {
$this
->setName('polls:share:add')
->setName(AppConstants::APP_ID . ':share:add')
->setDescription('Invites users to a poll')
->addArgument(
'id',
Expand Down
3 changes: 2 additions & 1 deletion lib/Command/Share/Remove.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace OCA\Polls\Command\Share;

use OC\Core\Command\Base;
use OCA\Polls\AppInfo\AppConstants;
use OCA\Polls\Db\Poll;
use OCA\Polls\Db\Share;
use OCA\Polls\Model\Group\Group;
Expand All @@ -42,7 +43,7 @@ class Remove extends Base {

protected function configure(): void {
$this
->setName('polls:share:remove')
->setName(AppConstants::APP_ID . ':share:remove')
->setDescription('Remove user invitations from a poll')
->addArgument(
'id',
Expand Down
3 changes: 2 additions & 1 deletion lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Polls\Controller;

use OCA\Polls\AppInfo\AppConstants;
use OCA\Polls\Service\PollService;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
Expand All @@ -45,7 +46,7 @@ public function __construct(
* @NoCSRFRequired
*/
public function index(): TemplateResponse {
return new TemplateResponse('polls', 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
return new TemplateResponse(AppConstants::APP_ID, 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace OCA\Polls\Controller;

use OCA\Polls\AppInfo\AppConstants;
use OCA\Polls\Service\NotificationService;
use OCP\AppFramework\Controller;

Expand All @@ -46,7 +47,7 @@ public function __construct(
* @NoCSRFRequired
*/
public function index(): TemplateResponse {
return new TemplateResponse('polls', 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
return new TemplateResponse(AppConstants::APP_ID, 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
}

/**
Expand All @@ -55,6 +56,6 @@ public function index(): TemplateResponse {
*/
public function vote(int $id): TemplateResponse {
$this->notificationService->removeNotification($id);
return new TemplateResponse('polls', 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
return new TemplateResponse(AppConstants::APP_ID, 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
}
}
3 changes: 2 additions & 1 deletion lib/Controller/PollApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Polls\Controller;

use OCA\Polls\AppInfo\AppConstants;
use OCA\Polls\Exceptions\Exception;
use OCA\Polls\Model\Acl;
use OCA\Polls\Service\PollService;
Expand All @@ -49,7 +50,7 @@ public function __construct(
*/
public function list(): JSONResponse {
try {
return new JSONResponse(['polls' => $this->pollService->list()], Http::STATUS_OK);
return new JSONResponse([AppConstants::APP_ID => $this->pollService->list()], Http::STATUS_OK);
} catch (DoesNotExistException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
} catch (Exception $e) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public function __construct(
*/
public function votePage(string $token) {
if ($this->userSession->isLoggedIn()) {
return new TemplateResponse('polls', 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
return new TemplateResponse(AppConstants::APP_ID, 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);

Check failure on line 73 in lib/Controller/PublicController.php

View workflow job for this annotation

GitHub Actions / Psalm (stable27, 8.1)

UndefinedClass

lib/Controller/PublicController.php:73:32: UndefinedClass: Class, interface or enum named OCA\Polls\Controller\AppConstants does not exist (see https://psalm.dev/019)
} else {
$template = new PublicTemplateResponse('polls', 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
$template = new PublicTemplateResponse(AppConstants::APP_ID, 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);

Check failure on line 75 in lib/Controller/PublicController.php

View workflow job for this annotation

GitHub Actions / Psalm (stable27, 8.1)

UndefinedClass

lib/Controller/PublicController.php:75:43: UndefinedClass: Class, interface or enum named OCA\Polls\Controller\AppConstants does not exist (see https://psalm.dev/019)
$template->setFooterVisible(false);
return $template;
}
Expand Down
7 changes: 4 additions & 3 deletions lib/Dashboard/PollWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Polls\Dashboard;

use OCA\Polls\AppInfo\AppConstants;
use OCP\Dashboard\IWidget;
use OCP\IL10N;
use OCP\IURLGenerator;
Expand All @@ -35,7 +36,7 @@ public function __construct(
}

public function getId(): string {
return 'polls';
return AppConstants::APP_ID;
}

public function getTitle(): string {
Expand All @@ -51,10 +52,10 @@ public function getIconClass(): string {
}

public function getUrl(): ?string {
return $this->urlGenerator->linkToRouteAbsolute('polls.page.index');
return $this->urlGenerator->linkToRouteAbsolute(AppConstants::APP_ID . '.page.index');
}

public function load(): void {
\OCP\Util::addScript('polls', 'polls-dashboard');
\OCP\Util::addScript(AppConstants::APP_ID, 'polls-dashboard');
}
}
3 changes: 2 additions & 1 deletion lib/Db/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace OCA\Polls\Db;

use JsonSerializable;
use OCA\Polls\AppInfo\AppConstants;
use OCA\Polls\Exceptions\NoDeadLineException;
use OCA\Polls\Helper\Container;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -216,7 +217,7 @@ public function getUri(): string {

public function getVoteUrl() : string {
return $this->urlGenerator->linkToRouteAbsolute(
'polls.page.vote',
AppConstants::APP_ID . '.page.vote',
['id' => $this->getId()]
);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Db/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace OCA\Polls\Db;

use JsonSerializable;

use OCA\Polls\AppInfo\AppConstants;
use OCA\Polls\Helper\Container;
use OCA\Polls\Model\Settings\AppSettings;
use OCP\AppFramework\Db\Entity;
Expand Down Expand Up @@ -162,12 +162,12 @@ public function setLanguage(string $value): void {
public function getURL(): string {
if (in_array($this->type, [self::TYPE_USER, self::TYPE_ADMIN, self::TYPE_GROUP], true)) {
return $this->urlGenerator->linkToRouteAbsolute(
'polls.page.vote',
AppConstants::APP_ID . '.page.vote',
['id' => $this->pollId]
);
} elseif ($this->token) {
return $this->urlGenerator->linkToRouteAbsolute(
'polls.public.vote_page',
AppConstants::APP_ID . '.public.vote_page',
['token' => $this->token]
);
} else {
Expand Down
7 changes: 4 additions & 3 deletions lib/Db/TableManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type;
use OCA\Polls\AppInfo\AppConstants;
use OCA\Polls\Migration\TableSchema;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
Expand Down Expand Up @@ -98,7 +99,7 @@ public function purgeTables(): array {
$query = $this->connection->getQueryBuilder();
$query->delete('migrations')
->where('app = :appName')
->setParameter('appName', 'polls')
->setParameter('appName', AppConstants::APP_ID)
->executeStatement();

$this->logger->info('Removed all migration records from ' . $this->dbPrefix . 'migrations');
Expand All @@ -108,7 +109,7 @@ public function purgeTables(): array {
// $query = $this->connection->getQueryBuilder();
$query->delete('appconfig')
->where('appid = :appid')
->setParameter('appid', 'polls')
->setParameter('appid', AppConstants::APP_ID)
->executeStatement();

$this->logger->info('Removed all app config records from '. $this->dbPrefix . 'appconfig');
Expand Down Expand Up @@ -351,7 +352,7 @@ public function removeObsoleteMigrations(): array {
$query->delete('migrations')
->where('app = :appName')
->andWhere('version = :version')
->setParameter('appName', 'polls')
->setParameter('appName', AppConstants::APP_ID)
->setParameter('version', $version)
->executeStatement();
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Db/WatchMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Polls\Db;

use OCA\Polls\AppInfo\AppConstants;
use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection;
use OCP\ISession;
Expand Down Expand Up @@ -55,7 +56,7 @@ public function findUpdatesForPollId(int $pollId, int $offset): array {
)
->andWhere($qb->expr()->orX(
$qb->expr()->eq('poll_id', $qb->createNamedParameter($pollId)),
$qb->expr()->eq('table', $qb->createNamedParameter('polls'))
$qb->expr()->eq('table', $qb->createNamedParameter(AppConstants::APP_ID))
));

return $this->findEntities($qb);
Expand Down
5 changes: 3 additions & 2 deletions lib/Helper/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace OCA\Polls\Helper;

use OCA\Polls\AppInfo\AppConstants;
use OCA\Polls\Db\Poll;
use OCA\Polls\Db\PollMapper;
use OCA\Polls\Db\Share;
Expand All @@ -36,7 +37,7 @@

abstract class Container {
public static function getContainer(): ContainerInterface {
$app = new App('polls');
$app = new App(AppConstants::APP_ID);
return $app->getContainer();
}

Expand All @@ -54,7 +55,7 @@ public static function findShare(int $pollId, string $userId): Share {
}

public static function getL10N(string $lang = null): IL10N {
return self::queryClass(IFactory::class)->get('polls', $lang);
return self::queryClass(IFactory::class)->get(AppConstants::APP_ID, $lang);
}
public static function isAppEnabled(string $app): bool {
return self::queryClass(IAppManager::class)->isEnabledForUser($app);
Expand Down
13 changes: 4 additions & 9 deletions lib/Listener/BaseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,10 @@ protected function getPollId() : int {
* Default for activity notification.
*/
protected function addActivity() : void {
if (!($this->event instanceof BaseEvent)) {
return;
}
if ($this->event->getActivityType() && $this->event->getActivityObjectType()) {
$activityEvent = $this->activityService->createActivityEvent($this->event);
$this->activityService->publishActivityEvent($activityEvent, $this->event->getActor());
if ($this->event->getActor() !== $this->event->getPollOwner()) {
$this->activityService->publishActivityEvent($activityEvent, $this->event->getPollOwner());
}
if (($this->event instanceof BaseEvent)
&& $this->event->getActivityType()
&& $this->event->getActivityObjectType()) {
$this->activityService->addActivity($this->event);
}
}

Expand Down
Loading

0 comments on commit d9b293a

Please sign in to comment.