diff --git a/lib/Classifiers/Audio/MusicnnClassifier.php b/lib/Classifiers/Audio/MusicnnClassifier.php index bf80ca07..dd9ee869 100644 --- a/lib/Classifiers/Audio/MusicnnClassifier.php +++ b/lib/Classifiers/Audio/MusicnnClassifier.php @@ -10,8 +10,8 @@ use OCA\Recognize\Service\Logger; use OCA\Recognize\Service\QueueService; use OCA\Recognize\Service\TagManager; +use OCP\AppFramework\Services\IAppConfig; use OCP\Files\IRootFolder; -use OCP\IConfig; use OCP\IPreview; use OCP\ITempManager; @@ -22,7 +22,7 @@ class MusicnnClassifier extends Classifier { private TagManager $tagManager; - public function __construct(Logger $logger, IConfig $config, TagManager $tagManager, QueueService $queue, IRootFolder $rootFolder, ITempManager $tempManager, IPreview $previewProvider) { + public function __construct(Logger $logger, IAppConfig $config, TagManager $tagManager, QueueService $queue, IRootFolder $rootFolder, ITempManager $tempManager, IPreview $previewProvider) { parent::__construct($logger, $config, $rootFolder, $queue, $tempManager, $previewProvider); $this->tagManager = $tagManager; } @@ -33,7 +33,7 @@ public function __construct(Logger $logger, IConfig $config, TagManager $tagMana * @throws \ErrorException|\RuntimeException */ public function classify(array $queueFiles): void { - if ($this->config->getAppValue('recognize', 'tensorflow.purejs', 'false') === 'true') { + if ($this->config->getAppValue('tensorflow.purejs', 'false') === 'true') { $timeout = self::AUDIO_PUREJS_TIMEOUT; } else { $timeout = self::AUDIO_TIMEOUT; @@ -45,8 +45,8 @@ public function classify(array $queueFiles): void { */ foreach ($classifierProcess as $queueFile => $results) { $this->tagManager->assignTags($queueFile->getFileId(), $results); - $this->config->setAppValue('recognize', self::MODEL_NAME.'.status', 'true'); - $this->config->setAppValue('recognize', self::MODEL_NAME.'.lastFile', time()); + $this->config->setAppValue(self::MODEL_NAME.'.status', 'true'); + $this->config->setAppValue(self::MODEL_NAME.'.lastFile', time()); } } } diff --git a/lib/Classifiers/Classifier.php b/lib/Classifiers/Classifier.php index 07f7adab..de57b199 100644 --- a/lib/Classifiers/Classifier.php +++ b/lib/Classifiers/Classifier.php @@ -12,6 +12,7 @@ use OCA\Recognize\Constants; use OCA\Recognize\Db\QueueFile; use OCA\Recognize\Service\QueueService; +use OCP\AppFramework\Services\IAppConfig; use OCP\DB\Exception; use OCP\Files\File; use OCP\Files\InvalidPathException; @@ -19,7 +20,6 @@ use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; -use OCP\IConfig; use OCP\IPreview; use OCP\ITempManager; use Psr\Log\LoggerInterface; @@ -32,14 +32,14 @@ abstract class Classifier { public const MAX_EXECUTION_TIME = 0; protected LoggerInterface $logger; - protected IConfig $config; + protected IAppConfig $config; private IRootFolder $rootFolder; protected QueueService $queue; private ITempManager $tempManager; private IPreview $previewProvider; private int $maxExecutionTime = self::MAX_EXECUTION_TIME; - public function __construct(LoggerInterface $logger, IConfig $config, IRootFolder $rootFolder, QueueService $queue, ITempManager $tempManager, IPreview $previewProvider) { + public function __construct(LoggerInterface $logger, IAppConfig $config, IRootFolder $rootFolder, QueueService $queue, ITempManager $tempManager, IPreview $previewProvider) { $this->logger = $logger; $this->config = $config; $this->rootFolder = $rootFolder; @@ -146,15 +146,15 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \ $this->logger->debug('Classifying '.var_export($paths, true)); $command = [ - $this->config->getAppValue('recognize', 'node_binary'), + $this->config->getAppValue('node_binary'), dirname(__DIR__, 2) . '/src/classifier_'.$model.'.js', '-' ]; - if (trim($this->config->getAppValue('recognize', 'nice_binary', '')) !== '') { + if (trim($this->config->getAppValue('nice_binary', '')) !== '') { $command = [ - $this->config->getAppValue('recognize', 'nice_binary'), - "-" . $this->config->getAppValue('recognize', 'nice_value', '0'), + $this->config->getAppValue('nice_binary'), + "-" . $this->config->getAppValue('nice_value', '0'), ...$command, ]; } @@ -163,14 +163,14 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \ $proc = new Process($command, __DIR__); $env = []; - if ($this->config->getAppValue('recognize', 'tensorflow.gpu', 'false') === 'true') { + if ($this->config->getAppValue('tensorflow.gpu', 'false') === 'true') { $env['RECOGNIZE_GPU'] = 'true'; } - if ($this->config->getAppValue('recognize', 'tensorflow.purejs', 'false') === 'true') { + if ($this->config->getAppValue('tensorflow.purejs', 'false') === 'true') { $env['RECOGNIZE_PUREJS'] = 'true'; } // Set cores - $cores = $this->config->getAppValue('recognize', 'tensorflow.cores', '0'); + $cores = $this->config->getAppValue('tensorflow.cores', '0'); if ($cores !== '0') { $env['RECOGNIZE_CORES'] = $cores; } diff --git a/lib/Classifiers/Images/ClusteringFaceClassifier.php b/lib/Classifiers/Images/ClusteringFaceClassifier.php index 5480881b..29a1fdec 100644 --- a/lib/Classifiers/Images/ClusteringFaceClassifier.php +++ b/lib/Classifiers/Images/ClusteringFaceClassifier.php @@ -12,12 +12,12 @@ use OCA\Recognize\Db\FaceDetectionMapper; use OCA\Recognize\Service\Logger; use OCA\Recognize\Service\QueueService; +use OCP\AppFramework\Services\IAppConfig; use OCP\BackgroundJob\IJobList; use OCP\DB\Exception; use OCP\Files\Config\ICachedMountInfo; use OCP\Files\Config\IUserMountCache; use OCP\Files\IRootFolder; -use OCP\IConfig; use OCP\IPreview; use OCP\ITempManager; @@ -35,7 +35,7 @@ class ClusteringFaceClassifier extends Classifier { private IUserMountCache $userMountCache; private IJobList $jobList; - public function __construct(Logger $logger, IConfig $config, FaceDetectionMapper $faceDetections, QueueService $queue, IRootFolder $rootFolder, IUserMountCache $userMountCache, IJobList $jobList, ITempManager $tempManager, IPreview $previewProvider) { + public function __construct(Logger $logger, IAppConfig $config, FaceDetectionMapper $faceDetections, QueueService $queue, IRootFolder $rootFolder, IUserMountCache $userMountCache, IJobList $jobList, ITempManager $tempManager, IPreview $previewProvider) { parent::__construct($logger, $config, $rootFolder, $queue, $tempManager, $previewProvider); $this->faceDetections = $faceDetections; $this->userMountCache = $userMountCache; @@ -49,7 +49,7 @@ public function __construct(Logger $logger, IConfig $config, FaceDetectionMapper * @return void */ public function classify(array $queueFiles): void { - if ($this->config->getAppValue('recognize', 'tensorflow.purejs', 'false') === 'true') { + if ($this->config->getAppValue('tensorflow.purejs', 'false') === 'true') { $timeout = self::IMAGE_PUREJS_TIMEOUT; } else { $timeout = self::IMAGE_TIMEOUT; @@ -117,8 +117,8 @@ public function classify(array $queueFiles): void { } $usersToCluster[$userId] = true; } - $this->config->setAppValue('recognize', self::MODEL_NAME.'.status', 'true'); - $this->config->setAppValue('recognize', self::MODEL_NAME.'.lastFile', time()); + $this->config->setAppValue(self::MODEL_NAME.'.status', 'true'); + $this->config->setAppValue(self::MODEL_NAME.'.lastFile', time()); } } diff --git a/lib/Classifiers/Images/ImagenetClassifier.php b/lib/Classifiers/Images/ImagenetClassifier.php index e526e1b1..ae3dee7e 100644 --- a/lib/Classifiers/Images/ImagenetClassifier.php +++ b/lib/Classifiers/Images/ImagenetClassifier.php @@ -10,9 +10,9 @@ use OCA\Recognize\Service\Logger; use OCA\Recognize\Service\QueueService; use OCA\Recognize\Service\TagManager; +use OCP\AppFramework\Services\IAppConfig; use OCP\DB\Exception; use OCP\Files\IRootFolder; -use OCP\IConfig; use OCP\IPreview; use OCP\ITempManager; @@ -24,7 +24,7 @@ class ImagenetClassifier extends Classifier { private TagManager $tagManager; protected QueueService $queue; - public function __construct(Logger $logger, IConfig $config, TagManager $tagManager, QueueService $queue, IRootFolder $rootFolder, ITempManager $tempManager, IPreview $previewProvider) { + public function __construct(Logger $logger, IAppConfig $config, TagManager $tagManager, QueueService $queue, IRootFolder $rootFolder, ITempManager $tempManager, IPreview $previewProvider) { parent::__construct($logger, $config, $rootFolder, $queue, $tempManager, $previewProvider); $this->tagManager = $tagManager; $this->queue = $queue; @@ -36,7 +36,7 @@ public function __construct(Logger $logger, IConfig $config, TagManager $tagMana * @throws \ErrorException|\RuntimeException */ public function classify(array $queueFiles): void { - if ($this->config->getAppValue('recognize', 'tensorflow.purejs', 'false') === 'true') { + if ($this->config->getAppValue('tensorflow.purejs', 'false') === 'true') { $timeout = self::IMAGE_PUREJS_TIMEOUT; } else { $timeout = self::IMAGE_TIMEOUT; @@ -50,8 +50,8 @@ public function classify(array $queueFiles): void { $landmarkTags = array_filter($results, static function ($tagName) { return in_array($tagName, LandmarksClassifier::PRECONDITION_TAGS); }); - $this->config->setAppValue('recognize', self::MODEL_NAME.'.status', 'true'); - $this->config->setAppValue('recognize', self::MODEL_NAME.'.lastFile', time()); + $this->config->setAppValue(self::MODEL_NAME.'.status', 'true'); + $this->config->setAppValue(self::MODEL_NAME.'.lastFile', time()); if (count($landmarkTags) > 0) { try { diff --git a/lib/Classifiers/Images/LandmarksClassifier.php b/lib/Classifiers/Images/LandmarksClassifier.php index 8f992749..2ca87eb8 100644 --- a/lib/Classifiers/Images/LandmarksClassifier.php +++ b/lib/Classifiers/Images/LandmarksClassifier.php @@ -10,8 +10,8 @@ use OCA\Recognize\Service\Logger; use OCA\Recognize\Service\QueueService; use OCA\Recognize\Service\TagManager; +use OCP\AppFramework\Services\IAppConfig; use OCP\Files\IRootFolder; -use OCP\IConfig; use OCP\IPreview; use OCP\ITempManager; @@ -23,7 +23,7 @@ class LandmarksClassifier extends Classifier { private TagManager $tagManager; - public function __construct(Logger $logger, IConfig $config, TagManager $tagManager, QueueService $queue, IRootFolder $rootFolder, ITempManager $tempManager, IPreview $previewProvider) { + public function __construct(Logger $logger, IAppConfig $config, TagManager $tagManager, QueueService $queue, IRootFolder $rootFolder, ITempManager $tempManager, IPreview $previewProvider) { parent::__construct($logger, $config, $rootFolder, $queue, $tempManager, $previewProvider); $this->tagManager = $tagManager; } @@ -34,7 +34,7 @@ public function __construct(Logger $logger, IConfig $config, TagManager $tagMana * @throws \ErrorException|\RuntimeException */ public function classify(array $queueFiles): void { - if ($this->config->getAppValue('recognize', 'tensorflow.purejs', 'false') === 'true') { + if ($this->config->getAppValue('tensorflow.purejs', 'false') === 'true') { $timeout = self::IMAGE_PUREJS_TIMEOUT; } else { $timeout = self::IMAGE_TIMEOUT; @@ -45,8 +45,8 @@ public function classify(array $queueFiles): void { /** @var list $results */ foreach ($classifierProcess as $queueFile => $results) { $this->tagManager->assignTags($queueFile->getFileId(), $results); - $this->config->setAppValue('recognize', self::MODEL_NAME.'.status', 'true'); - $this->config->setAppValue('recognize', self::MODEL_NAME.'.lastFile', time()); + $this->config->setAppValue(self::MODEL_NAME.'.status', 'true'); + $this->config->setAppValue(self::MODEL_NAME.'.lastFile', time()); } } } diff --git a/lib/Classifiers/Video/MovinetClassifier.php b/lib/Classifiers/Video/MovinetClassifier.php index 3e50416d..ee3fcc67 100644 --- a/lib/Classifiers/Video/MovinetClassifier.php +++ b/lib/Classifiers/Video/MovinetClassifier.php @@ -11,8 +11,8 @@ use OCA\Recognize\Service\Logger; use OCA\Recognize\Service\QueueService; use OCA\Recognize\Service\TagManager; +use OCP\AppFramework\Services\IAppConfig; use OCP\Files\IRootFolder; -use OCP\IConfig; use OCP\IPreview; use OCP\ITempManager; @@ -22,7 +22,7 @@ class MovinetClassifier extends Classifier { private TagManager $tagManager; - public function __construct(Logger $logger, IConfig $config, TagManager $tagManager, QueueService $queue, IRootFolder $rootFolder, ITempManager $tempManager, IPreview $previewProvider) { + public function __construct(Logger $logger, IAppConfig $config, TagManager $tagManager, QueueService $queue, IRootFolder $rootFolder, ITempManager $tempManager, IPreview $previewProvider) { parent::__construct($logger, $config, $rootFolder, $queue, $tempManager, $previewProvider); $this->tagManager = $tagManager; } @@ -33,7 +33,7 @@ public function __construct(Logger $logger, IConfig $config, TagManager $tagMana * @throws \ErrorException|\RuntimeException|Exception */ public function classify(array $queueFiles): void { - if ($this->config->getAppValue('recognize', 'tensorflow.purejs', 'false') === 'true') { + if ($this->config->getAppValue('tensorflow.purejs', 'false') === 'true') { throw new Exception('Movinet does not support WASM mode'); } else { $timeout = self::VIDEO_TIMEOUT; @@ -44,8 +44,8 @@ public function classify(array $queueFiles): void { /** @var list $results */ foreach ($classifierProcess as $queueFile => $results) { $this->tagManager->assignTags($queueFile->getFileId(), $results); - $this->config->setAppValue('recognize', self::MODEL_NAME.'.status', 'true'); - $this->config->setAppValue('recognize', self::MODEL_NAME.'.lastFile', time()); + $this->config->setAppValue(self::MODEL_NAME.'.status', 'true'); + $this->config->setAppValue(self::MODEL_NAME.'.lastFile', time()); } } } diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index bb29efdd..0a1e181e 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -25,10 +25,10 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Services\IAppConfig; use OCP\BackgroundJob\IJobList; use OCP\DB\Exception; use OCP\IBinaryFinder; -use OCP\IConfig; use OCP\IRequest; class AdminController extends Controller { @@ -38,11 +38,11 @@ class AdminController extends Controller { private QueueService $queue; private FaceClusterMapper $clusterMapper; private FaceDetectionMapper $detectionMapper; - private IConfig $config; + private IAppConfig $config; private FaceDetectionMapper $faceDetections; private IBinaryFinder $binaryFinder; - public function __construct(string $appName, IRequest $request, TagManager $tagManager, IJobList $jobList, SettingsService $settingsService, QueueService $queue, FaceClusterMapper $clusterMapper, FaceDetectionMapper $detectionMapper, IConfig $config, FaceDetectionMapper $faceDetections, IBinaryFinder $binaryFinder) { + public function __construct(string $appName, IRequest $request, TagManager $tagManager, IJobList $jobList, SettingsService $settingsService, QueueService $queue, FaceClusterMapper $clusterMapper, FaceDetectionMapper $detectionMapper, IAppConfig $config, FaceDetectionMapper $faceDetections, IBinaryFinder $binaryFinder) { parent::__construct($appName, $request); $this->tagManager = $tagManager; $this->jobList = $jobList; @@ -186,17 +186,17 @@ public function musl(): JSONResponse { public function nice(): JSONResponse { /* use nice binary from settings if available */ - if ($this->config->getAppValue('recognize', 'nice_binary', '') !== '') { - $nice_path = $this->config->getAppValue('recognize', 'nice_binary'); + if ($this->config->getAppValue('nice_binary', '') !== '') { + $nice_path = $this->config->getAppValue('nice_binary'); } else { /* returns the path to the nice binary or false if not found */ $nice_path = $this->binaryFinder->findBinaryPath('nice'); } if ($nice_path !== false) { - $this->config->setAppValue('recognize', 'nice_binary', $nice_path); + $this->config->setAppValue('nice_binary', $nice_path); } else { - $this->config->setAppValue('recognize', 'nice_binary', ''); + $this->config->setAppValue('nice_binary', ''); return new JSONResponse(['nice' => false]); } diff --git a/lib/Db/FaceDetectionMapper.php b/lib/Db/FaceDetectionMapper.php index 32a7fbb9..3605b189 100644 --- a/lib/Db/FaceDetectionMapper.php +++ b/lib/Db/FaceDetectionMapper.php @@ -10,14 +10,14 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\QBMapper; +use OCP\AppFramework\Services\IAppConfig; use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\IConfig; use OCP\IDBConnection; class FaceDetectionMapper extends QBMapper { - private IConfig $config; + private IAppConfig $config; - public function __construct(IDBConnection $db, IConfig $config) { + public function __construct(IDBConnection $db, IAppConfig $config) { parent::__construct($db, 'recognize_face_detections', FaceDetection::class); $this->db = $db; $this->config = $config; diff --git a/lib/Migration/InstallDeps.php b/lib/Migration/InstallDeps.php index 3186ca69..a5dc6fc8 100644 --- a/lib/Migration/InstallDeps.php +++ b/lib/Migration/InstallDeps.php @@ -1,8 +1,4 @@ . * */ -declare(strict_types=1); namespace OCA\Recognize\Migration; use OCA\Recognize\Helper\TAR; +use OCP\AppFramework\Services\IAppConfig; use OCP\Http\Client\IClientService; use OCP\IBinaryFinder; -use OCP\IConfig; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; use Psr\Log\LoggerInterface; @@ -43,7 +38,7 @@ class InstallDeps implements IRepairStep { public const NODE_SERVER_OFFICIAL = 'https://nodejs.org/dist/'; public const NODE_SERVER_UNOFFICIAL = 'https://unofficial-builds.nodejs.org/download/release/'; - protected IConfig $config; + protected IAppConfig $config; private string $binaryDir; private string $preGypBinaryDir; private string $ffmpegDir; @@ -56,7 +51,7 @@ class InstallDeps implements IRepairStep { private string $tfjsGPUPath; private IBinaryFinder $binaryFinder; - public function __construct(IConfig $config, IClientService $clientService, LoggerInterface $logger, IBinaryFinder $binaryFinder) { + public function __construct(IAppConfig $config, IClientService $clientService, LoggerInterface $logger, IBinaryFinder $binaryFinder) { $this->config = $config; $this->binaryDir = dirname(__DIR__, 2) . '/bin/'; $this->preGypBinaryDir = dirname(__DIR__, 2) . '/node_modules/@mapbox/node-pre-gyp/bin/'; @@ -77,7 +72,7 @@ public function getName(): string { public function run(IOutput $output): void { try { - $existingBinary = $this->config->getAppValue('recognize', 'node_binary', ''); + $existingBinary = $this->config->getAppValue('node_binary', ''); if ($existingBinary !== '') { $version = $this->testBinary($existingBinary); if ($version === null) { @@ -89,7 +84,7 @@ public function run(IOutput $output): void { $this->setBinariesPermissions(); - $binaryPath = $this->config->getAppValue('recognize', 'node_binary', ''); + $binaryPath = $this->config->getAppValue('node_binary', ''); $this->runTfjsInstall($binaryPath); $this->runFfmpegInstall($binaryPath); @@ -103,17 +98,17 @@ public function run(IOutput $output): void { protected function setNiceBinaryPath() : void { /* use nice binary from settings if available */ - if ($this->config->getAppValue('recognize', 'nice_binary', '') !== '') { - $nice_path = $this->config->getAppValue('recognize', 'nice_binary'); + if ($this->config->getAppValue('nice_binary', '') !== '') { + $nice_path = $this->config->getAppValue('nice_binary'); } else { /* returns the path to the nice binary or false if not found */ $nice_path = $this->binaryFinder->findBinaryPath('nice'); } if ($nice_path !== false) { - $this->config->setAppValue('recognize', 'nice_binary', $nice_path); + $this->config->setAppValue('nice_binary', $nice_path); } else { - $this->config->setAppValue('recognize', 'nice_binary', ''); + $this->config->setAppValue('nice_binary', ''); } } @@ -156,12 +151,12 @@ protected function installNodeBinary(IOutput $output) : void { } // Write the app config - $this->config->setAppValue('recognize', 'node_binary', $binaryPath); + $this->config->setAppValue('node_binary', $binaryPath); $supportsAVX = $this->isAVXSupported(); if ($isARM || $isMusl || !$supportsAVX) { $output->info('Enabling purejs mode (isMusl='.$isMusl.', isARM='.$isARM.', supportsAVX='.$supportsAVX.')'); - $this->config->setAppValue('recognize', 'tensorflow.purejs', 'true'); + $this->config->setAppValue('tensorflow.purejs', 'true'); } } diff --git a/lib/Service/QueueService.php b/lib/Service/QueueService.php index f5e522e3..35db1739 100644 --- a/lib/Service/QueueService.php +++ b/lib/Service/QueueService.php @@ -18,8 +18,8 @@ use OCA\Recognize\Classifiers\Video\MovinetClassifier; use OCA\Recognize\Db\QueueFile; use OCA\Recognize\Db\QueueMapper; +use OCP\AppFramework\Services\IAppConfig; use OCP\BackgroundJob\IJobList; -use OCP\IConfig; class QueueService { /** @@ -35,9 +35,9 @@ class QueueService { private QueueMapper $queueMapper; private IJobList $jobList; - private IConfig $config; + private IAppConfig $config; - public function __construct(QueueMapper $queueMapper, IJobList $jobList, IConfig $config) { + public function __construct(QueueMapper $queueMapper, IJobList $jobList, IAppConfig $config) { $this->queueMapper = $queueMapper; $this->jobList = $jobList; $this->config = $config; @@ -48,7 +48,7 @@ public function __construct(QueueMapper $queueMapper, IJobList $jobList, IConfig */ public function insertIntoQueue(string $model, QueueFile $file) : void { // Only add to queue if this model is actually enabled - if ($this->config->getAppValue('recognize', $model.'.enabled', 'false') !== 'true') { + if ($this->config->getAppValue($model.'.enabled', 'false') !== 'true') { return; } diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index 1e5692d2..f2281e3e 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -16,8 +16,8 @@ use OCA\Recognize\Classifiers\Images\LandmarksClassifier; use OCA\Recognize\Classifiers\Video\MovinetClassifier; use OCA\Recognize\Exception\Exception; +use OCP\AppFramework\Services\IAppConfig; use OCP\BackgroundJob\IJobList; -use OCP\IConfig; class SettingsService { /** @var array */ @@ -63,10 +63,10 @@ class SettingsService { 'musicnn.batchSize' => '20', ]; - private IConfig $config; + private IAppConfig $config; private IJobList $jobList; - public function __construct(IConfig $config, IJobList $jobList) { + public function __construct(IAppConfig $config, IJobList $jobList) { $this->config = $config; $this->jobList = $jobList; } @@ -77,9 +77,9 @@ public function __construct(IConfig $config, IJobList $jobList) { */ public function getSetting(string $key): string { if (strpos($key, 'batchSize') !== false) { - return $this->config->getAppValue('recognize', $key, $this->getSetting('tensorflow.purejs') === 'false' ? self::DEFAULTS[$key] : self::PUREJS_DEFAULTS[$key]); + return $this->config->getAppValue($key, $this->getSetting('tensorflow.purejs') === 'false' ? self::DEFAULTS[$key] : self::PUREJS_DEFAULTS[$key]); } - return $this->config->getAppValue('recognize', $key, self::DEFAULTS[$key]); + return $this->config->getAppValue($key, self::DEFAULTS[$key]); } /** @@ -92,7 +92,7 @@ public function setSetting(string $key, string $value): void { if (!array_key_exists($key, self::DEFAULTS)) { throw new Exception('Unknown settings key '.$key); } - if ($value === 'true' && $this->config->getAppValue('recognize', $key, 'false') === 'false') { + if ($value === 'true' && $this->config->getAppValue($key, 'false') === 'false') { // Additional model enabled: Schedule new crawl run for the affected mime types switch ($key) { case ClusteringFaceClassifier::MODEL_NAME . '.enabled': @@ -114,7 +114,7 @@ public function setSetting(string $key, string $value): void { break; } } - $this->config->setAppValue('recognize', $key, $value); + $this->config->setAppValue($key, $value); } /** diff --git a/scoper.inc.php b/scoper.inc.php index 85f58168..d7e99f5f 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -18,7 +18,7 @@ 'psr' ]) ->in('.'), - ], + ], 'patchers' => [ static function (string $filePath, string $prefix, string $content): string { // diff --git a/tests/ClassifierTest.php b/tests/ClassifierTest.php index 59d7266b..4e4db58e 100644 --- a/tests/ClassifierTest.php +++ b/tests/ClassifierTest.php @@ -20,10 +20,10 @@ use OCA\Recognize\Service\FaceClusterAnalyzer; use OCA\Recognize\Service\Logger; use OCA\Recognize\Service\QueueService; +use OCP\AppFramework\Services\IAppConfig; use OCP\BackgroundJob\IJobList; use OCP\Files\Folder; use OCP\Files\IRootFolder; -use OCP\IConfig; use OCP\SystemTag\ISystemTagObjectMapper; use Test\TestCase; @@ -57,7 +57,7 @@ class ClassifierTest extends TestCase { private QueueService $queue; private FaceDetectionMapper $faceDetectionMapper; private IJobList $jobList; - private IConfig $config; + private IAppConfig $config; public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); @@ -90,10 +90,10 @@ public function setUp(): void { $this->queue->clearQueue(LandmarksClassifier::MODEL_NAME); $this->queue->clearQueue(MovinetClassifier::MODEL_NAME); $this->queue->clearQueue(MusicnnClassifier::MODEL_NAME); - $this->config->setAppValue('recognize', 'imagenet.enabled', 'false'); - $this->config->setAppValue('recognize', 'faces.enabled', 'false'); - $this->config->setAppValue('recognize', 'movinet.enabled', 'false'); - $this->config->setAppValue('recognize', 'musicnn.enabled', 'false'); + $this->config->setAppValue('imagenet.enabled', 'false'); + $this->config->setAppValue('faces.enabled', 'false'); + $this->config->setAppValue('movinet.enabled', 'false'); + $this->config->setAppValue('musicnn.enabled', 'false'); $faceClusterAnalyzer = \OC::$server->get(FaceClusterAnalyzer::class); $faceClusterAnalyzer->setMinDatasetSize(30); @@ -138,7 +138,7 @@ public function testSchedulerJob() : void { * @throws \OCP\Files\NotPermittedException */ public function testFileListener(string $ignoreFileName) : void { - $this->config->setAppValue('recognize', 'imagenet.enabled', 'true'); + $this->config->setAppValue('imagenet.enabled', 'true'); $this->queue->clearQueue(ImagenetClassifier::MODEL_NAME); $this->testFile = $this->userFolder->newFile('/alpine.jpg', file_get_contents(__DIR__.'/res/alpine.JPG')); @@ -202,7 +202,7 @@ public function testClassifyCommand(string $ignoreFileName) : void { ->willReturnCallback(fn ($msg) => print($msg."\n")); $cliInput = $this->createMock(Symfony\Component\Console\Input\InputInterface::class); - $this->config->setAppValue('recognize', 'imagenet.enabled', 'true'); + $this->config->setAppValue('imagenet.enabled', 'true'); $classifyCommand->run($cliInput, $cliOutput); /** @var \OCP\SystemTag\ISystemTagObjectMapper $objectMapper */ @@ -245,7 +245,7 @@ public function testImagenetPipeline(string $ignoreFileName) : void { $this->ignoredFile = $this->userFolder->newFile('/test/ignore/alpine.jpg', file_get_contents(__DIR__.'/res/alpine.JPG')); $this->userFolder->newFile('/test/' . $ignoreFileName, ''); - $this->config->setAppValue('recognize', 'imagenet.enabled', 'true'); + $this->config->setAppValue('imagenet.enabled', 'true'); /** @var StorageCrawlJob $scheduler */ $crawler = \OC::$server->get(StorageCrawlJob::class); @@ -309,13 +309,13 @@ public function testImagenetPipeline(string $ignoreFileName) : void { } public function testLandmarksPipeline() : void { - if ($this->config->getAppValue('recognize', 'tensorflow.purejs', 'false') === 'true') { + if ($this->config->getAppValue('tensorflow.purejs', 'false') === 'true') { // landmarks will fail with purejs/WASM mode, sadly, because we use a worse imagenet model in WASM mode self::markTestSkipped(); } $this->testFile = $this->userFolder->newFile('/eiffeltower.jpg', file_get_contents(__DIR__.'/res/eiffeltower.jpg')); - $this->config->setAppValue('recognize', 'imagenet.enabled', 'true'); - $this->config->setAppValue('recognize', 'landmarks.enabled', 'true'); + $this->config->setAppValue('imagenet.enabled', 'true'); + $this->config->setAppValue('landmarks.enabled', 'true'); /** @var StorageCrawlJob $scheduler */ $crawler = \OC::$server->get(StorageCrawlJob::class); /** @var IJobList $this->jobList */ @@ -403,7 +403,7 @@ public function testFacesPipeline() : void { } } - $this->config->setAppValue('recognize', 'faces.enabled', 'true'); + $this->config->setAppValue('faces.enabled', 'true'); /** @var StorageCrawlJob $scheduler */ $crawler = \OC::$server->get(StorageCrawlJob::class); @@ -496,7 +496,7 @@ public function testFacesPipeline() : void { * @throws \Psr\Container\NotFoundExceptionInterface */ public function testMovinetPipeline(string $ignoreFileName) : void { - if ($this->config->getAppValue('recognize', 'tensorflow.purejs', 'false') === 'true') { + if ($this->config->getAppValue('tensorflow.purejs', 'false') === 'true') { // Cannot run musicnn with purejs/WASM mode self::markTestSkipped(); } @@ -504,7 +504,7 @@ public function testMovinetPipeline(string $ignoreFileName) : void { $this->userFolder->newFolder('/test/ignore/'); $this->ignoredFile = $this->userFolder->newFile('/test/ignore/jumpingjack.gif', file_get_contents(__DIR__.'/res/jumpingjack.gif')); $this->userFolder->newFile('/test/' . $ignoreFileName, ''); - $this->config->setAppValue('recognize', 'movinet.enabled', 'true'); + $this->config->setAppValue('movinet.enabled', 'true'); /** @var StorageCrawlJob $scheduler */ $crawler = \OC::$server->get(StorageCrawlJob::class); @@ -578,7 +578,7 @@ public function testMovinetPipeline(string $ignoreFileName) : void { * @throws \Psr\Container\NotFoundExceptionInterface */ public function testMusicnnPipeline(string $ignoreFileName) : void { - if ($this->config->getAppValue('recognize', 'tensorflow.purejs', 'false') === 'true') { + if ($this->config->getAppValue('tensorflow.purejs', 'false') === 'true') { // Cannot run musicnn with purejs/WASM mode self::markTestSkipped(); } @@ -586,7 +586,7 @@ public function testMusicnnPipeline(string $ignoreFileName) : void { $this->userFolder->newFolder('/test/ignore/'); $this->ignoredFile = $this->userFolder->newFile('/test/ignore/Rock_Rejam.mp3', file_get_contents(__DIR__.'/res/Rock_Rejam.mp3')); $this->userFolder->newFile('/test/' . $ignoreFileName, ''); - $this->config->setAppValue('recognize', 'musicnn.enabled', 'true'); + $this->config->setAppValue('musicnn.enabled', 'true'); /** @var StorageCrawlJob $scheduler */ $crawler = \OC::$server->get(StorageCrawlJob::class); /** @var IJobList $this->jobList */ @@ -650,7 +650,7 @@ public function testMusicnnPipeline(string $ignoreFileName) : void { * @throws \OCP\Files\NotPermittedException */ public function testClassifier($file, $model, $tag) : void { - if ($this->config->getAppValue('recognize', 'tensorflow.purejs', 'false') === 'true' && in_array($model, ['movinet', 'musicnn'])) { + if ($this->config->getAppValue('tensorflow.purejs', 'false') === 'true' && in_array($model, ['movinet', 'musicnn'])) { // Cannot run musicnn/movinet with purejs/WASM mode self::markTestSkipped(); }