refactor: move to PHP 8 syntax for constructors

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/877/head
Varun Patil 2023-10-14 18:51:17 -07:00
parent 6965d0214f
commit fb32a94e2e
29 changed files with 139 additions and 360 deletions

View File

@ -31,19 +31,11 @@ use OCP\IRequest;
class AlbumsBackend extends Backend
{
protected AlbumsQuery $albumsQuery;
protected IRequest $request;
protected TimelineQuery $tq;
public function __construct(
AlbumsQuery $albumsQuery,
IRequest $request,
TimelineQuery $tq
) {
$this->albumsQuery = $albumsQuery;
$this->request = $request;
$this->tq = $tq;
}
protected AlbumsQuery $albumsQuery,
protected IRequest $request,
protected TimelineQuery $tq,
) {}
public static function appName(): string
{

View File

@ -32,19 +32,11 @@ class FaceRecognitionBackend extends Backend
{
use PeopleBackendUtils;
protected IRequest $request;
protected TimelineQuery $tq;
protected IConfig $config;
public function __construct(
IRequest $request,
TimelineQuery $tq,
IConfig $config
) {
$this->request = $request;
$this->tq = $tq;
$this->config = $config;
}
protected IRequest $request,
protected TimelineQuery $tq,
protected IConfig $config,
) {}
public static function appName(): string
{

View File

@ -29,14 +29,10 @@ use OCP\IRequest;
class PlacesBackend extends Backend
{
protected TimelineQuery $tq;
protected IRequest $request;
public function __construct(TimelineQuery $tq, IRequest $request)
{
$this->tq = $tq;
$this->request = $request;
}
public function __construct(
protected TimelineQuery $tq,
protected IRequest $request,
) {}
public static function appName(): string
{

View File

@ -31,14 +31,10 @@ class RecognizeBackend extends Backend
{
use PeopleBackendUtils;
protected TimelineQuery $tq;
protected IRequest $request;
public function __construct(TimelineQuery $tq, IRequest $request)
{
$this->tq = $tq;
$this->request = $request;
}
public function __construct(
protected TimelineQuery $tq,
protected IRequest $request,
) {}
public static function appName(): string
{

View File

@ -30,14 +30,10 @@ use OCP\IRequest;
class TagsBackend extends Backend
{
protected TimelineQuery $tq;
protected IRequest $request;
public function __construct(TimelineQuery $tq, IRequest $request)
{
$this->tq = $tq;
$this->request = $request;
}
public function __construct(
protected TimelineQuery $tq,
protected IRequest $request,
) {}
public static function appName(): string
{

View File

@ -57,13 +57,6 @@ class IndexOpts
class Index extends Command
{
protected IUserManager $userManager;
protected IGroupManager $groupManager;
protected IRootFolder $rootFolder;
protected IConfig $config;
protected Service\Index $indexer;
protected TimelineWrite $timelineWrite;
// IO
private InputInterface $input;
private OutputInterface $output;
@ -72,21 +65,14 @@ class Index extends Command
private IndexOpts $opts;
public function __construct(
IRootFolder $rootFolder,
IUserManager $userManager,
IGroupManager $groupManager,
IConfig $config,
Service\Index $indexer,
TimelineWrite $timelineWrite
protected IRootFolder $rootFolder,
protected IUserManager $userManager,
protected IGroupManager $groupManager,
protected IConfig $config,
protected Service\Index $indexer,
protected TimelineWrite $tw,
) {
parent::__construct();
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->rootFolder = $rootFolder;
$this->config = $config;
$this->indexer = $indexer;
$this->timelineWrite = $timelineWrite;
}
protected function configure(): void
@ -163,7 +149,7 @@ class Index extends Command
}
}
$this->timelineWrite->clear();
$this->tw->clear();
$this->output->writeln('<info>Cleared existing index</info>');
}
@ -178,7 +164,7 @@ class Index extends Command
$this->output->writeln('Forcing refresh of existing index entries');
$this->timelineWrite->orphanAll();
$this->tw->orphanAll();
}
/**

View File

@ -47,34 +47,20 @@ class MigrateGoogleTakeout extends Command
protected OutputInterface $output;
protected InputInterface $input;
protected IUserManager $userManager;
protected IRootFolder $rootFolder;
protected IConfig $config;
protected IDBConnection $connection;
protected TimelineWrite $timelineWrite;
protected ITempManager $tempManager;
// Stats
private int $nProcessed = 0;
private array $mimeTypes = [];
public function __construct(
IRootFolder $rootFolder,
IUserManager $userManager,
IConfig $config,
IDBConnection $connection,
ITempManager $tempManager,
TimelineWrite $timelineWrite
protected IRootFolder $rootFolder,
protected IUserManager $userManager,
protected IConfig $config,
protected IDBConnection $connection,
protected ITempManager $tempManager,
protected TimelineWrite $timelineWrite
) {
parent::__construct();
$this->userManager = $userManager;
$this->rootFolder = $rootFolder;
$this->config = $config;
$this->connection = $connection;
$this->tempManager = $tempManager;
$this->timelineWrite = $timelineWrite;
}
protected function configure(): void

View File

@ -32,13 +32,10 @@ use Symfony\Component\Console\Output\OutputInterface;
class PlacesSetup extends Command
{
protected OutputInterface $output;
protected Places $places;
public function __construct(
Places $places
) {
public function __construct(protected Places $places)
{
parent::__construct();
$this->places = $places;
}
protected function configure(): void

View File

@ -37,35 +37,17 @@ use Psr\Log\LoggerInterface;
abstract class GenericApiController extends ApiController
{
protected IConfig $config;
protected IUserSession $userSession;
protected IRootFolder $rootFolder;
protected IAppManager $appManager;
protected IDBConnection $connection;
protected LoggerInterface $logger;
protected TimelineQuery $tq;
protected FsManager $fs;
public function __construct(
IRequest $request,
IConfig $config,
IUserSession $userSession,
IDBConnection $connection,
IRootFolder $rootFolder,
IAppManager $appManager,
LoggerInterface $logger,
TimelineQuery $tq,
FsManager $fs
protected IConfig $config,
protected IUserSession $userSession,
protected IDBConnection $connection,
protected IRootFolder $rootFolder,
protected IAppManager $appManager,
protected LoggerInterface $logger,
protected TimelineQuery $tq,
protected FsManager $fs
) {
parent::__construct(Application::APPNAME, $request);
$this->config = $config;
$this->userSession = $userSession;
$this->connection = $connection;
$this->rootFolder = $rootFolder;
$this->appManager = $appManager;
$this->logger = $logger;
$this->tq = $tq;
$this->fs = $fs;
}
}

View File

@ -3,6 +3,7 @@
namespace OCA\Memories\Controller;
use OCA\Files\Event\LoadSidebar;
use OCA\Memories\AppInfo\Application;
use OCA\Memories\Service\BinExt;
use OCA\Memories\Util;
use OCP\AppFramework\Controller;
@ -14,17 +15,11 @@ use OCP\IRequest;
class PageController extends Controller
{
protected $appName;
protected IEventDispatcher $eventDispatcher;
public function __construct(
string $AppName,
IRequest $request,
IEventDispatcher $eventDispatcher
protected IEventDispatcher $eventDispatcher
) {
parent::__construct($AppName, $request);
$this->appName = $AppName;
$this->eventDispatcher = $eventDispatcher;
parent::__construct(Application::APPNAME, $request);
}
/**
@ -37,11 +32,11 @@ class PageController extends Controller
// Check native version if available
$nativeVer = Util::callerNativeVersion();
if (null !== $nativeVer && version_compare($nativeVer, BinExt::NX_VER_MIN, '<')) {
return new PublicTemplateResponse($this->appName, 'native-old');
return new PublicTemplateResponse(Application::APPNAME, 'native-old');
}
// Scripts
\OCP\Util::addScript($this->appName, 'memories-main');
\OCP\Util::addScript(Application::APPNAME, 'memories-main');
// Extra translations
if (Util::recognizeIsEnabled()) {
@ -49,7 +44,7 @@ class PageController extends Controller
\OCP\Util::addTranslations('recognize');
}
$response = new TemplateResponse($this->appName, 'main', self::getMainParams());
$response = new TemplateResponse(Application::APPNAME, 'main', self::getMainParams());
$response->setContentSecurityPolicy(self::getCSP());
$response->cacheFor(0);

View File

@ -2,6 +2,7 @@
namespace OCA\Memories\Controller;
use OCA\Memories\AppInfo\Application;
use OCA\Memories\Db\AlbumsQuery;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
@ -15,45 +16,26 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Util;
class PublicAlbumController extends Controller
{
protected $appName;
protected IEventDispatcher $eventDispatcher;
protected IInitialState $initialState;
protected IAppManager $appManager;
protected IConfig $config;
protected IUserSession $userSession;
protected IRootFolder $rootFolder;
protected IURLGenerator $urlGenerator;
protected AlbumsQuery $albumsQuery;
protected IL10N $l10n;
public function __construct(
string $appName,
IEventDispatcher $eventDispatcher,
IInitialState $initialState,
IAppManager $appManager,
IConfig $config,
IUserSession $userSession,
IRootFolder $rootFolder,
IURLGenerator $urlGenerator,
AlbumsQuery $albumsQuery,
IL10N $l10n
IRequest $request,
protected IEventDispatcher $eventDispatcher,
protected IInitialState $initialState,
protected IAppManager $appManager,
protected IConfig $config,
protected IUserSession $userSession,
protected IRootFolder $rootFolder,
protected IURLGenerator $urlGenerator,
protected AlbumsQuery $albumsQuery,
protected IL10N $l10n
) {
$this->appName = $appName;
$this->eventDispatcher = $eventDispatcher;
$this->initialState = $initialState;
$this->appManager = $appManager;
$this->config = $config;
$this->userSession = $userSession;
$this->rootFolder = $rootFolder;
$this->urlGenerator = $urlGenerator;
$this->albumsQuery = $albumsQuery;
$this->l10n = $l10n;
parent::__construct(Application::APPNAME, $request);
}
/**
@ -93,13 +75,13 @@ class PublicAlbumController extends Controller
$this->addOgMetadata($album, $token);
// Scripts
Util::addScript($this->appName, 'memories-main');
Util::addScript(Application::APPNAME, 'memories-main');
// Share info
$this->initialState->provideInitialState('share_title', $album['name']);
// Render main template
$response = new PublicTemplateResponse($this->appName, 'main', PageController::getMainParams());
$response = new PublicTemplateResponse(Application::APPNAME, 'main', PageController::getMainParams());
$response->setHeaderTitle($album['name']);
$response->setFooterVisible(false); // wth is that anyway?
$response->setContentSecurityPolicy(PageController::getCSP());

View File

@ -23,38 +23,21 @@ use OCP\Share\IShare;
class PublicController extends AuthPublicShareController
{
protected $appName;
protected IEventDispatcher $eventDispatcher;
protected IInitialState $initialState;
protected IUserSession $userSession;
protected IRootFolder $rootFolder;
protected IShareManager $shareManager;
protected IConfig $config;
protected TimelineQuery $tq;
protected IShare $share;
public function __construct(
string $AppName,
IRequest $request,
ISession $session,
IURLGenerator $urlGenerator,
IEventDispatcher $eventDispatcher,
IInitialState $initialState,
IUserSession $userSession,
IRootFolder $rootFolder,
IShareManager $shareManager,
IConfig $config,
TimelineQuery $tq
protected IEventDispatcher $eventDispatcher,
protected IInitialState $initialState,
protected IUserSession $userSession,
protected IRootFolder $rootFolder,
protected IShareManager $shareManager,
protected IConfig $config,
protected TimelineQuery $tq
) {
parent::__construct($AppName, $request, $session, $urlGenerator);
$this->eventDispatcher = $eventDispatcher;
$this->initialState = $initialState;
$this->userSession = $userSession;
$this->rootFolder = $rootFolder;
$this->shareManager = $shareManager;
$this->config = $config;
$this->tq = $tq;
parent::__construct(Application::APPNAME, $request, $session, $urlGenerator);
}
/**
@ -110,7 +93,7 @@ class PublicController extends AuthPublicShareController
\OC_User::setIncognitoMode(true);
// Scripts
\OCP\Util::addScript($this->appName, 'memories-main');
\OCP\Util::addScript(Application::APPNAME, 'memories-main');
// Share info
$this->initialState->provideInitialState('no_download', $share->getHideDownload());

View File

@ -16,29 +16,25 @@ const INTERVAL = 900; // seconds (don't set this too low)
class IndexJob extends TimedJob
{
private Service\Index $service;
private IUserManager $userManager;
private LoggerInterface $logger;
private IConfig $config;
private bool $_hasError = false;
public function __construct(
ITimeFactory $time,
Service\Index $service,
IUserManager $userManager,
LoggerInterface $logger,
IConfig $config
private Service\Index $service,
private IUserManager $userManager,
private LoggerInterface $logger,
private IConfig $config
) {
parent::__construct($time);
$this->service = $service;
$this->userManager = $userManager;
$this->logger = $logger;
$this->config = $config;
$this->setInterval(INTERVAL);
}
/**
* Run the background indexing job.
*
* @param mixed $argument
*/
protected function run($argument)
{
// Check if indexing is enabled

View File

@ -9,12 +9,7 @@ use OCP\IDBConnection;
class AlbumsQuery
{
protected IDBConnection $connection;
public function __construct(IDBConnection $connection)
{
$this->connection = $connection;
}
public function __construct(private IDBConnection $connection) {}
/**
* Get list of albums.
@ -96,9 +91,9 @@ class AlbumsQuery
/**
* Check if an album has a file.
*
* @return bool|string owner of file
* @return ?string owner of file
*/
public function hasFile(int $albumId, int $fileId)
public function hasFile(int $albumId, int $fileId): ?string
{
$query = $this->connection->getQueryBuilder();
$query->select('owner')->from('photos_albums_files')->where(
@ -108,7 +103,7 @@ class AlbumsQuery
)
);
return $query->executeQuery()->fetchOne();
return $query->executeQuery()->fetchOne() ?: null;
}
/**

View File

@ -45,26 +45,16 @@ use OCP\Share\IShare;
class FsManager
{
protected IConfig $config;
protected IUserSession $userSession;
protected IRootFolder $rootFolder;
protected AlbumsQuery $albumsQuery;
protected IRequest $request;
protected ICache $nomediaCache;
private ICache $nomediaCache;
public function __construct(
IConfig $config,
IUserSession $userSession,
IRootFolder $rootFolder,
AlbumsQuery $albumsQuery,
IRequest $request,
private IConfig $config,
private IUserSession $userSession,
private IRootFolder $rootFolder,
private AlbumsQuery $albumsQuery,
private IRequest $request,
ICacheFactory $cacheFactory
) {
$this->config = $config;
$this->userSession = $userSession;
$this->rootFolder = $rootFolder;
$this->albumsQuery = $albumsQuery;
$this->request = $request;
$this->nomediaCache = $cacheFactory->createLocal('memories:nomedia');
}

View File

@ -11,12 +11,7 @@ use OCP\IDBConnection;
class LivePhoto
{
protected IDBConnection $connection;
public function __construct(IDBConnection $connection)
{
$this->connection = $connection;
}
public function __construct(private IDBConnection $connection) {}
/**
* Check if a given Exif data is the video part of a Live Photo.

View File

@ -26,16 +26,13 @@ class TimelineQuery
'mimetypes.mimetype',
];
protected IDBConnection $connection;
protected IRequest $request;
protected ?TimelineRoot $_root = null; // cache
protected bool $_rootEmptyAllowed = false;
public function __construct(IDBConnection $connection, IRequest $request)
{
$this->connection = $connection;
$this->request = $request;
}
public function __construct(
protected IDBConnection $connection,
protected IRequest $request,
) {}
public function allowEmptyRoot(bool $value = true): void
{

View File

@ -8,15 +8,8 @@ use OCP\Files\FileInfo;
class TimelineRoot
{
protected array $folders;
protected array $folderPaths;
/** Initialize */
public function __construct()
{
$this->folders = [];
$this->folderPaths = [];
}
protected array $folders = [];
protected array $folderPaths = [];
/**
* Add a folder to the root.

View File

@ -21,19 +21,12 @@ class TimelineWrite
use TimelineWriteMap;
use TimelineWriteOrphans;
use TimelineWritePlaces;
protected IDBConnection $connection;
protected LivePhoto $livePhoto;
protected ILockingProvider $lockingProvider;
public function __construct(
IDBConnection $connection,
LivePhoto $livePhoto,
ILockingProvider $lockingProvider
) {
$this->connection = $connection;
$this->livePhoto = $livePhoto;
$this->lockingProvider = $lockingProvider;
}
protected IDBConnection $connection,
protected LivePhoto $livePhoto,
protected ILockingProvider $lockingProvider,
) {}
/**
* Process a file to insert Exif data into the database.

View File

@ -6,10 +6,5 @@ use OCP\AppFramework\Http;
class HttpResponseException extends \Exception
{
public Http\Response $response;
public function __construct(Http\Response $response)
{
$this->response = $response;
}
public function __construct(public Http\Response $response) {}
}

View File

@ -31,12 +31,7 @@ use OCP\ISession;
*/
class BeforeTemplateListener implements IEventListener
{
private ISession $session;
public function __construct(ISession $session)
{
$this->session = $session;
}
public function __construct(private ISession $session) {}
public function handle(Event $event): void
{

View File

@ -25,19 +25,14 @@ use OCA\Memories\Db\TimelineWrite;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Events\Node\NodeDeletedEvent;
use OCP\Files\Folder;
use OCP\Files\File;
/**
* @template-implements IEventListener<Event>
*/
class PostDeleteListener implements IEventListener
{
private TimelineWrite $util;
public function __construct(TimelineWrite $util)
{
$this->util = $util;
}
public function __construct(private TimelineWrite $tw) {}
public function handle(Event $event): void
{
@ -46,10 +41,10 @@ class PostDeleteListener implements IEventListener
}
$node = $event->getNode();
if ($node instanceof Folder) {
if (!$node instanceof File) {
return;
}
$this->util->deleteFile($node);
$this->tw->deleteFile($node);
}
}

View File

@ -32,12 +32,7 @@ class PostLogoutListener implements IEventListener
{
public const CLEAR_CACHE_KEY = 'memories_clear_cache';
private ISession $session;
public function __construct(ISession $session)
{
$this->session = $session;
}
public function __construct(private ISession $session) {}
public function handle(Event $event): void
{

View File

@ -27,6 +27,7 @@ use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Events\Node\NodeTouchedEvent;
use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\File;
use Psr\Log\LoggerInterface;
/**
@ -34,16 +35,10 @@ use Psr\Log\LoggerInterface;
*/
class PostWriteListener implements IEventListener
{
private TimelineWrite $timelineWrite;
private LoggerInterface $logger;
public function __construct(
TimelineWrite $timelineWrite,
LoggerInterface $logger
) {
$this->timelineWrite = $timelineWrite;
$this->logger = $logger;
}
private TimelineWrite $tw,
private LoggerInterface $logger
) {}
public function handle(Event $event): void
{
@ -55,7 +50,7 @@ class PostWriteListener implements IEventListener
$node = $event->getNode();
// Check the mime type first
if (!Index::isSupported($node)) {
if (!($node instanceof File) || !Index::isSupported($node)) {
return;
}
@ -73,7 +68,7 @@ class PostWriteListener implements IEventListener
}
try {
$this->timelineWrite->processFile($node);
$this->tw->processFile($node);
} catch (\Exception $e) {
$this->logger->error('Memories failed to process file: {message}', [
'message' => $e->getMessage(),

View File

@ -13,12 +13,7 @@ use OCP\Migration\IRepairStep;
class Repair implements IRepairStep
{
protected IConfig $config;
public function __construct(IConfig $config)
{
$this->config = $config;
}
public function __construct(protected IConfig $config) {}
public function getName(): string
{

View File

@ -49,27 +49,15 @@ class Index
*/
public ?\Closure $continueCheck = null;
protected IRootFolder $rootFolder;
protected TimelineWrite $timelineWrite;
protected IDBConnection $db;
protected ITempManager $tempManager;
protected LoggerInterface $logger;
private static ?array $mimeList = null;
public function __construct(
IRootFolder $rootFolder,
TimelineWrite $timelineWrite,
IDBConnection $db,
ITempManager $tempManager,
LoggerInterface $logger
) {
$this->rootFolder = $rootFolder;
$this->timelineWrite = $timelineWrite;
$this->db = $db;
$this->tempManager = $tempManager;
$this->logger = $logger;
}
protected IRootFolder $rootFolder,
protected TimelineWrite $tw,
protected IDBConnection $db,
protected ITempManager $tempManager,
protected LoggerInterface $logger
) {}
/**
* Index all files for a user.
@ -202,7 +190,7 @@ class Index
try {
$this->log("Indexing file {$path}", true);
$this->timelineWrite->processFile($file);
$this->tw->processFile($file);
} catch (\OCP\Lock\LockedException $e) {
$this->log("Skipping file {$path} due to lock", true);
} catch (\Exception $e) {
@ -218,7 +206,7 @@ class Index
public function cleanupStale(): void
{
$this->log('<info>Cleaning up stale index entries</info>'.PHP_EOL);
$this->timelineWrite->cleanupStale();
$this->tw->cleanupStale();
}
/**

View File

@ -16,19 +16,11 @@ const PLANET_URL = 'https://github.com/pulsejet/memories-assets/releases/downloa
class Places
{
protected IConfig $config;
protected IDBConnection $connection;
protected TimelineWrite $timelineWrite;
public function __construct(
IConfig $config,
IDBConnection $connection,
TimelineWrite $timelineWrite
) {
$this->config = $config;
$this->connection = $connection;
$this->timelineWrite = $timelineWrite;
}
protected IConfig $config,
protected IDBConnection $connection,
protected TimelineWrite $tw
) {}
/**
* Make SQL query to detect GIS type.
@ -385,7 +377,7 @@ class Places
flush();
$count = 0;
$this->timelineWrite->orphanAndRun(['fileid', 'lat', 'lon'], 20, function (array $row) use (&$count) {
$this->tw->orphanAndRun(['fileid', 'lat', 'lon'], 20, function (array $row) use (&$count) {
++$count;
// Only proceed if we have a valid location
@ -395,7 +387,7 @@ class Places
// Update places
if ($lat || $lon) {
$this->timelineWrite->updatePlacesData($fileid, $lat, $lon);
$this->tw->updatePlacesData($fileid, $lat, $lon);
}
// Print every 500 files

View File

@ -2,32 +2,28 @@
namespace OCA\Memories\Settings;
use OCA\Memories\AppInfo\Application;
use OCA\Memories\Controller\PageController;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Settings\ISettings;
class Admin implements ISettings
{
protected $appName;
public function __construct(string $AppName)
{
$this->appName = $AppName;
}
public function __construct() {}
/**
* @return TemplateResponse
*/
public function getForm()
{
\OCP\Util::addScript($this->appName, 'memories-admin');
\OCP\Util::addScript(Application::APPNAME, 'memories-admin');
return new TemplateResponse('memories', 'main', PageController::getMainParams());
}
public function getSection()
{
return $this->appName;
return Application::APPNAME;
}
public function getPriority()

View File

@ -9,19 +9,10 @@ use OCP\Settings\IIconSection;
class AdminSection implements IIconSection
{
/** @var IL10N */
private $l;
/** @var IURLGenerator */
private $urlGenerator;
public function __construct(
IL10N $l,
IURLGenerator $urlGenerator
) {
$this->l = $l;
$this->urlGenerator = $urlGenerator;
}
private IL10N $l,
private IURLGenerator $urlGenerator
) {}
/**
* @return TemplateResponse