Skip to content

Commit

Permalink
fix(deprecation): Avoid using deprecated IConfig#getAppValue
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Jan 25, 2024
1 parent 500b91a commit e419097
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 91 deletions.
10 changes: 5 additions & 5 deletions lib/Classifiers/Audio/MusicnnClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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());
}
}
}
20 changes: 10 additions & 10 deletions lib/Classifiers/Classifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
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;
use OCP\Files\IRootFolder;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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,
];
}
Expand All @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Classifiers/Images/ClusteringFaceClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/Classifiers/Images/ImagenetClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions lib/Classifiers/Images/LandmarksClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -45,8 +45,8 @@ public function classify(array $queueFiles): void {
/** @var list<string> $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());
}
}
}
10 changes: 5 additions & 5 deletions lib/Classifiers/Video/MovinetClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -44,8 +44,8 @@ public function classify(array $queueFiles): void {
/** @var list<string> $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());
}
}
}
14 changes: 7 additions & 7 deletions lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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]);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Db/FaceDetectionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit e419097

Please sign in to comment.