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 class AlbumsBackend extends Backend
{ {
protected AlbumsQuery $albumsQuery;
protected IRequest $request;
protected TimelineQuery $tq;
public function __construct( public function __construct(
AlbumsQuery $albumsQuery, protected AlbumsQuery $albumsQuery,
IRequest $request, protected IRequest $request,
TimelineQuery $tq protected TimelineQuery $tq,
) { ) {}
$this->albumsQuery = $albumsQuery;
$this->request = $request;
$this->tq = $tq;
}
public static function appName(): string public static function appName(): string
{ {

View File

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

View File

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

View File

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

View File

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

View File

@ -57,13 +57,6 @@ class IndexOpts
class Index extends Command class Index extends Command
{ {
protected IUserManager $userManager;
protected IGroupManager $groupManager;
protected IRootFolder $rootFolder;
protected IConfig $config;
protected Service\Index $indexer;
protected TimelineWrite $timelineWrite;
// IO // IO
private InputInterface $input; private InputInterface $input;
private OutputInterface $output; private OutputInterface $output;
@ -72,21 +65,14 @@ class Index extends Command
private IndexOpts $opts; private IndexOpts $opts;
public function __construct( public function __construct(
IRootFolder $rootFolder, protected IRootFolder $rootFolder,
IUserManager $userManager, protected IUserManager $userManager,
IGroupManager $groupManager, protected IGroupManager $groupManager,
IConfig $config, protected IConfig $config,
Service\Index $indexer, protected Service\Index $indexer,
TimelineWrite $timelineWrite protected TimelineWrite $tw,
) { ) {
parent::__construct(); parent::__construct();
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->rootFolder = $rootFolder;
$this->config = $config;
$this->indexer = $indexer;
$this->timelineWrite = $timelineWrite;
} }
protected function configure(): void 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>'); $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->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 OutputInterface $output;
protected InputInterface $input; protected InputInterface $input;
protected IUserManager $userManager;
protected IRootFolder $rootFolder;
protected IConfig $config;
protected IDBConnection $connection;
protected TimelineWrite $timelineWrite;
protected ITempManager $tempManager;
// Stats // Stats
private int $nProcessed = 0; private int $nProcessed = 0;
private array $mimeTypes = []; private array $mimeTypes = [];
public function __construct( public function __construct(
IRootFolder $rootFolder, protected IRootFolder $rootFolder,
IUserManager $userManager, protected IUserManager $userManager,
IConfig $config, protected IConfig $config,
IDBConnection $connection, protected IDBConnection $connection,
ITempManager $tempManager, protected ITempManager $tempManager,
TimelineWrite $timelineWrite protected TimelineWrite $timelineWrite
) { ) {
parent::__construct(); parent::__construct();
$this->userManager = $userManager;
$this->rootFolder = $rootFolder;
$this->config = $config;
$this->connection = $connection;
$this->tempManager = $tempManager;
$this->timelineWrite = $timelineWrite;
} }
protected function configure(): void protected function configure(): void

View File

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

View File

@ -37,35 +37,17 @@ use Psr\Log\LoggerInterface;
abstract class GenericApiController extends ApiController 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( public function __construct(
IRequest $request, IRequest $request,
IConfig $config, protected IConfig $config,
IUserSession $userSession, protected IUserSession $userSession,
IDBConnection $connection, protected IDBConnection $connection,
IRootFolder $rootFolder, protected IRootFolder $rootFolder,
IAppManager $appManager, protected IAppManager $appManager,
LoggerInterface $logger, protected LoggerInterface $logger,
TimelineQuery $tq, protected TimelineQuery $tq,
FsManager $fs protected FsManager $fs
) { ) {
parent::__construct(Application::APPNAME, $request); 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; namespace OCA\Memories\Controller;
use OCA\Files\Event\LoadSidebar; use OCA\Files\Event\LoadSidebar;
use OCA\Memories\AppInfo\Application;
use OCA\Memories\Service\BinExt; use OCA\Memories\Service\BinExt;
use OCA\Memories\Util; use OCA\Memories\Util;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
@ -14,17 +15,11 @@ use OCP\IRequest;
class PageController extends Controller class PageController extends Controller
{ {
protected $appName;
protected IEventDispatcher $eventDispatcher;
public function __construct( public function __construct(
string $AppName,
IRequest $request, IRequest $request,
IEventDispatcher $eventDispatcher protected IEventDispatcher $eventDispatcher
) { ) {
parent::__construct($AppName, $request); parent::__construct(Application::APPNAME, $request);
$this->appName = $AppName;
$this->eventDispatcher = $eventDispatcher;
} }
/** /**
@ -37,11 +32,11 @@ class PageController extends Controller
// Check native version if available // Check native version if available
$nativeVer = Util::callerNativeVersion(); $nativeVer = Util::callerNativeVersion();
if (null !== $nativeVer && version_compare($nativeVer, BinExt::NX_VER_MIN, '<')) { 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 // Scripts
\OCP\Util::addScript($this->appName, 'memories-main'); \OCP\Util::addScript(Application::APPNAME, 'memories-main');
// Extra translations // Extra translations
if (Util::recognizeIsEnabled()) { if (Util::recognizeIsEnabled()) {
@ -49,7 +44,7 @@ class PageController extends Controller
\OCP\Util::addTranslations('recognize'); \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->setContentSecurityPolicy(self::getCSP());
$response->cacheFor(0); $response->cacheFor(0);

View File

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

View File

@ -23,38 +23,21 @@ use OCP\Share\IShare;
class PublicController extends AuthPublicShareController 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; protected IShare $share;
public function __construct( public function __construct(
string $AppName,
IRequest $request, IRequest $request,
ISession $session, ISession $session,
IURLGenerator $urlGenerator, IURLGenerator $urlGenerator,
IEventDispatcher $eventDispatcher, protected IEventDispatcher $eventDispatcher,
IInitialState $initialState, protected IInitialState $initialState,
IUserSession $userSession, protected IUserSession $userSession,
IRootFolder $rootFolder, protected IRootFolder $rootFolder,
IShareManager $shareManager, protected IShareManager $shareManager,
IConfig $config, protected IConfig $config,
TimelineQuery $tq protected TimelineQuery $tq
) { ) {
parent::__construct($AppName, $request, $session, $urlGenerator); parent::__construct(Application::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;
} }
/** /**
@ -110,7 +93,7 @@ class PublicController extends AuthPublicShareController
\OC_User::setIncognitoMode(true); \OC_User::setIncognitoMode(true);
// Scripts // Scripts
\OCP\Util::addScript($this->appName, 'memories-main'); \OCP\Util::addScript(Application::APPNAME, 'memories-main');
// Share info // Share info
$this->initialState->provideInitialState('no_download', $share->getHideDownload()); $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 class IndexJob extends TimedJob
{ {
private Service\Index $service;
private IUserManager $userManager;
private LoggerInterface $logger;
private IConfig $config;
private bool $_hasError = false; private bool $_hasError = false;
public function __construct( public function __construct(
ITimeFactory $time, ITimeFactory $time,
Service\Index $service, private Service\Index $service,
IUserManager $userManager, private IUserManager $userManager,
LoggerInterface $logger, private LoggerInterface $logger,
IConfig $config private IConfig $config
) { ) {
parent::__construct($time); parent::__construct($time);
$this->service = $service;
$this->userManager = $userManager;
$this->logger = $logger;
$this->config = $config;
$this->setInterval(INTERVAL); $this->setInterval(INTERVAL);
} }
/**
* Run the background indexing job.
*
* @param mixed $argument
*/
protected function run($argument) protected function run($argument)
{ {
// Check if indexing is enabled // Check if indexing is enabled

View File

@ -9,12 +9,7 @@ use OCP\IDBConnection;
class AlbumsQuery class AlbumsQuery
{ {
protected IDBConnection $connection; public function __construct(private IDBConnection $connection) {}
public function __construct(IDBConnection $connection)
{
$this->connection = $connection;
}
/** /**
* Get list of albums. * Get list of albums.
@ -96,9 +91,9 @@ class AlbumsQuery
/** /**
* Check if an album has a file. * 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 = $this->connection->getQueryBuilder();
$query->select('owner')->from('photos_albums_files')->where( $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 class FsManager
{ {
protected IConfig $config; private ICache $nomediaCache;
protected IUserSession $userSession;
protected IRootFolder $rootFolder;
protected AlbumsQuery $albumsQuery;
protected IRequest $request;
protected ICache $nomediaCache;
public function __construct( public function __construct(
IConfig $config, private IConfig $config,
IUserSession $userSession, private IUserSession $userSession,
IRootFolder $rootFolder, private IRootFolder $rootFolder,
AlbumsQuery $albumsQuery, private AlbumsQuery $albumsQuery,
IRequest $request, private IRequest $request,
ICacheFactory $cacheFactory ICacheFactory $cacheFactory
) { ) {
$this->config = $config;
$this->userSession = $userSession;
$this->rootFolder = $rootFolder;
$this->albumsQuery = $albumsQuery;
$this->request = $request;
$this->nomediaCache = $cacheFactory->createLocal('memories:nomedia'); $this->nomediaCache = $cacheFactory->createLocal('memories:nomedia');
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -49,27 +49,15 @@ class Index
*/ */
public ?\Closure $continueCheck = null; public ?\Closure $continueCheck = null;
protected IRootFolder $rootFolder;
protected TimelineWrite $timelineWrite;
protected IDBConnection $db;
protected ITempManager $tempManager;
protected LoggerInterface $logger;
private static ?array $mimeList = null; private static ?array $mimeList = null;
public function __construct( public function __construct(
IRootFolder $rootFolder, protected IRootFolder $rootFolder,
TimelineWrite $timelineWrite, protected TimelineWrite $tw,
IDBConnection $db, protected IDBConnection $db,
ITempManager $tempManager, protected ITempManager $tempManager,
LoggerInterface $logger protected LoggerInterface $logger
) { ) {}
$this->rootFolder = $rootFolder;
$this->timelineWrite = $timelineWrite;
$this->db = $db;
$this->tempManager = $tempManager;
$this->logger = $logger;
}
/** /**
* Index all files for a user. * Index all files for a user.
@ -202,7 +190,7 @@ class Index
try { try {
$this->log("Indexing file {$path}", true); $this->log("Indexing file {$path}", true);
$this->timelineWrite->processFile($file); $this->tw->processFile($file);
} catch (\OCP\Lock\LockedException $e) { } catch (\OCP\Lock\LockedException $e) {
$this->log("Skipping file {$path} due to lock", true); $this->log("Skipping file {$path} due to lock", true);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -218,7 +206,7 @@ class Index
public function cleanupStale(): void public function cleanupStale(): void
{ {
$this->log('<info>Cleaning up stale index entries</info>'.PHP_EOL); $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 class Places
{ {
protected IConfig $config;
protected IDBConnection $connection;
protected TimelineWrite $timelineWrite;
public function __construct( public function __construct(
IConfig $config, protected IConfig $config,
IDBConnection $connection, protected IDBConnection $connection,
TimelineWrite $timelineWrite protected TimelineWrite $tw
) { ) {}
$this->config = $config;
$this->connection = $connection;
$this->timelineWrite = $timelineWrite;
}
/** /**
* Make SQL query to detect GIS type. * Make SQL query to detect GIS type.
@ -385,7 +377,7 @@ class Places
flush(); flush();
$count = 0; $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; ++$count;
// Only proceed if we have a valid location // Only proceed if we have a valid location
@ -395,7 +387,7 @@ class Places
// Update places // Update places
if ($lat || $lon) { if ($lat || $lon) {
$this->timelineWrite->updatePlacesData($fileid, $lat, $lon); $this->tw->updatePlacesData($fileid, $lat, $lon);
} }
// Print every 500 files // Print every 500 files

View File

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

View File

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