Skip to content

Commit

Permalink
Update to NC21 new requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
orzuionut committed Jun 15, 2021
1 parent 4c4a0f2 commit 4863196
Show file tree
Hide file tree
Showing 23 changed files with 428 additions and 134 deletions.
8 changes: 0 additions & 8 deletions w2g2/appinfo/app.php

This file was deleted.

4 changes: 2 additions & 2 deletions w2g2/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</description>
<licence>AGPL</licence>
<author>Ionut Orzu</author>
<version>3.0.3</version>
<version>3.0.5</version>
<category>social</category>
<category>files</category>

Expand All @@ -24,7 +24,7 @@
<screenshot>https://raw.githubusercontent.com/newroco/W2G2/master/screenshots/screenshot_01.PNG</screenshot>

<dependencies>
<nextcloud min-version="17.0" max-version="20.0"/>
<nextcloud min-version="17.0" max-version="21.0"/>
</dependencies>

<activity>
Expand Down
150 changes: 144 additions & 6 deletions w2g2/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,65 @@

namespace OCA\w2g2\AppInfo;

use OCA\w2g2\File;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Notification\IManager;
use Psr\Container\ContainerInterface;

use OCA\w2g2\Notification\Notifier;
use OCA\w2g2\Controller\AdminController;
use OCA\w2g2\Controller\ConfigController;
use OCA\w2g2\Controller\LockController;
use OCA\w2g2\Service\AdminService;
use OCA\w2g2\Service\ConfigService;
use OCA\w2g2\Service\LockService;
use OCA\w2g2\Service\UserService;
use OCA\w2g2\Db\AdminMapper;
use OCA\w2g2\Db\CategoryMapper;
use OCA\w2g2\Db\ConfigMapper;
use OCA\w2g2\Db\FavoriteMapper;
use OCA\w2g2\Db\FileMapper;
use OCA\w2g2\Db\GroupFolderMapper;
use OCA\w2g2\Db\Lock;
use OCA\w2g2\Db\LockMapper;

class Application extends App
class Application extends App implements IBootstrap
{
const name = 'w2g2';

public function __construct()
{
parent::__construct(self::name);

$container = $this->getContainer();

$this->registerMappers($container);
$this->registerServices($container);
$this->registerControllers($container);
}

public function boot()
public function boot(IBootContext $context): void
{
if ( ! \OC::$server->getAppManager()->isEnabledForUser(self::name)) {
return;
}

$this->registerHooks();
$this->registerHooks($context);
$this->registerScripts();
}

public function registerHooks()
public function register(IRegistrationContext $context): void
{
$notificationManager = \OC::$server->getNotificationManager();
//
}

$notificationManager->registerNotifierService(Notifier::class);
public function registerHooks($context)
{
$manager = $context->getAppContainer()->query(IManager::class);
$manager->registerNotifierService(Notifier::class);
}

public function registerScripts()
Expand All @@ -39,4 +71,110 @@ public function registerScripts()
style(self::name, 'styles');
});
}

protected function registerControllers($container)
{
$container->registerService('AdminController', function(ContainerInterface $c){
return new AdminController(
$c->get('AppName'),
$c->get('Request'),
$c->get('ConfigService'),
$c->get('AdminService')
);
});

$container->registerService('ConfigController', function(ContainerInterface $c){
return new ConfigController(
$c->get('AppName'),
$c->get('Request'),
$c->get('ConfigService')
);
});

$container->registerService('LockController', function(ContainerInterface $c){
return new LockController(
$c->get('AppName'),
$c->get('Request'),
$c->get('LockService')
);
});
}

protected function registerServices($container)
{
$container->registerService('AdminService', function(ContainerInterface $c){
return new AdminService(
$c->get('AdminMapper')
);
});

$container->registerService('ConfigService', function(ContainerInterface $c){
return new ConfigService(
$c->get('ConfigMapper')
);
});

$container->registerService('LockService', function(ContainerInterface $c){
return new LockService(
$c->get('LockMapper'),
$c->get('ConfigMapper'),
$c->get('File')
);
});
}

protected function registerMappers($container)
{
$container->registerService('LockMapper', function(ContainerInterface $c){
return new LockMapper(
$c->get('ServerContainer')->getDatabaseConnection()
);
});

$container->registerService('AdminMapper', function(ContainerInterface $c){
return new AdminMapper(
$c->get('LockMapper'),
$c->get('GroupFolderMapper')
);
});

$container->registerService('CategoryMapper', function(ContainerInterface $c){
return new CategoryMapper(
$c->get('ServerContainer')->getDatabaseConnection()
);
});

$container->registerService('ConfigMapper', function(ContainerInterface $c){
return new ConfigMapper(
$c->get('ServerContainer')->getDatabaseConnection()
);
});

$container->registerService('FavoriteMapper', function(ContainerInterface $c){
return new FavoriteMapper(
$c->get('CategoryMapper')
);
});

$container->registerService('FileMapper', function(ContainerInterface $c){
return new FileMapper(
$c->get('ServerContainer')->getDatabaseConnection()
);
});

$container->registerService('GroupFolderMapper', function(ContainerInterface $c){
return new GroupFolderMapper(
$c->get('ServerContainer')->getDatabaseConnection()
);
});

//
$container->registerService('File', function(ContainerInterface $c){
return new File(
$c->get('LockMapper'),
$c->get('GroupFolderMapper'),
$c->get('FileMapper')
);
});
}
}
10 changes: 5 additions & 5 deletions w2g2/lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace OCA\w2g2\Controller;

use OCA\w2g2\Db\ConfigMapper;
use OCP\IRequest;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;

use OCA\w2g2\Migration\UpdateDatabase;
use OCA\w2g2\Service\ConfigService;

class ConfigController extends Controller {
class ConfigController extends Controller
{
protected $appName;
protected $service;

Expand Down Expand Up @@ -67,13 +67,13 @@ public function update($type, $value)
$configValue = \OC::$server->getConfig()->getAppValue('w2g2', $type, '[unset]');

if ($configValue === '[unset]') {
ConfigMapper::store($type, $value);
$this->service->store($type, $value);

return new DataResponse($l->t($type) . " " . $l->t("has been set!"));
}

ConfigMapper::update($type, $value);
$this->service->update($type, $value);

return new DataResponse($l->t("Updated successfully!"));
}
}
}
22 changes: 22 additions & 0 deletions w2g2/lib/Controller/Errors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace OCA\w2g2\Controller;

use Closure;

use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;

use OCA\w2g2\Service\NotFoundException;

trait Errors {
protected function handleNotFound (Closure $callback)
{
try {
return new DataResponse($callback());
} catch(NotFoundException $e) {
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_NOT_FOUND);
}
}
}
6 changes: 1 addition & 5 deletions w2g2/lib/Controller/LockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace OCA\w2g2\Controller;

use Countable;
use OCA\w2g2\UIMessage;
use OCP\IRequest;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\JSONResponse;
Expand All @@ -16,15 +15,12 @@
class LockController extends Controller {
/** @var LockService */
private $service;
/** @var string */
private $userId;

public function __construct($AppName, IRequest $request, LockService $lockService, $UserId)
public function __construct($AppName, IRequest $request, LockService $lockService)
{
parent::__construct($AppName, $request);

$this->service = $lockService;
$this->userId = $UserId;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions w2g2/lib/Db/AdminMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace OCA\w2g2\Db;

class AdminMapper {
protected $tableName;
class AdminMapper
{
protected $lockMapper;
protected $groupFolderMapper;

public function __construct(LockMapper $lockMapper)
public function __construct(LockMapper $lockMapper, GroupFolderMapper $groupFolderMapper)
{
$this->tableName = 'locks_w2g2';
$this->lockMapper = $lockMapper;
$this->groupFolderMapper = $groupFolderMapper;
}

public function getLocks()
Expand All @@ -31,7 +32,7 @@ public function getLocks()
$groupFolderId = substr($path, 0, $slashIndex);
$file = substr($path, $slashIndex + 1);

$result = GroupFolderMapper::getMountPoints($groupFolderId);
$result = $this->groupFolderMapper->getMountPoints($groupFolderId);

if ($result && count($result) > 0) {
$path = $result[0]['mount_point'];
Expand Down
21 changes: 14 additions & 7 deletions w2g2/lib/Db/CategoryMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@

namespace OCA\w2g2\Db;

class CategoryMapper {
use OCP\IDbConnection;
use OCP\AppFramework\Db\Mapper;

class CategoryMapper extends Mapper
{
public function __construct(IDbConnection $db)
{
parent::__construct($db, 'locks_w2g2', '\OCA\w2g2\Db\Lock');
}

/**
* Get favorite data for the given category, like the userId
*
* @param $categoryId
* @return mixed
*/
public static function getFavoriteByCategoryId($categoryId)
public function getFavoriteByCategoryId($categoryId)
{
$db = \OC::$server->getDatabaseConnection();
$favorite = '_$!<Favorite>!$_' ;

$query = "SELECT * FROM *PREFIX*" . "vcategory" . " WHERE category = ? AND id = ?";

return $db->executeQuery($query, [$favorite, $categoryId])
return $this->db->executeQuery($query, [$favorite, $categoryId])
->fetchAll();
}

Expand All @@ -26,12 +34,11 @@ public static function getFavoriteByCategoryId($categoryId)
* @param $fileId
* @return mixed
*/
public static function getCategoriesForFile($fileId)
public function getCategoriesForFile($fileId)
{
$db = \OC::$server->getDatabaseConnection();
$query = "SELECT * FROM *PREFIX*" . "vcategory_to_object" . " WHERE objid = ?";

return $db->executeQuery($query, [$fileId])
return $this->db->executeQuery($query, [$fileId])
->fetchAll();
}
}
Loading

0 comments on commit 4863196

Please sign in to comment.