Skip to content

Commit

Permalink
clarify and refactor named service injections
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
Julien Veyssier committed Jul 6, 2020
1 parent c0d818d commit ce5ec9e
Show file tree
Hide file tree
Showing 22 changed files with 218 additions and 409 deletions.
25 changes: 13 additions & 12 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: ubuntu:18.10
image: ubuntu:19.10

stages:
- test
Expand All @@ -7,7 +7,8 @@ stages:
before_script:
- export DEBIAN_FRONTEND=noninteractive
- apt-get update -yqq
- apt-get install git sudo make php-xdebug php7.2-sqlite3 php7.2-curl php7.2-xml php7.2-mbstring php7.2-json php7.2-zip php7.2-gd php7.2-intl unzip curl wget nodejs npm sed -yqq > /dev/null 2>&1
- apt-get install git sudo make php-xdebug php7.3-sqlite3 php7.3-curl php7.3-xml php7.3-mbstring php7.3-json php7.3-zip php7.3-gd php7.3-intl unzip curl wget nodejs npm sed -yqq > /dev/null 2>&1
- npm install -g npm
- npm install -g jshint > /dev/null 2>&1
- curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar
- chmod +x /usr/local/bin/phpunit
Expand Down Expand Up @@ -48,8 +49,8 @@ test_nc17_sqlite:
# check JS code
- jshint --verbose maps/js/script.js && echo "jshint OK" || echo "jshint has complaints"
- cd /var/www/html/nextcloud/apps/maps
- sudo -u www-data php7.2 /usr/local/bin/phpunit --configuration /var/www/html/nextcloud/apps/maps/phpunit.xml > /dev/null 2>&1 || echo "FIRST TEST FAILED as expected..."
- sudo -u www-data php7.2 /usr/local/bin/phpunit --configuration /var/www/html/nextcloud/apps/maps/phpunit.xml --coverage-text --color=never --coverage-html /builds/eneiluj/maps/coverage
- sudo -u www-data php7.3 /usr/local/bin/phpunit --configuration /var/www/html/nextcloud/apps/maps/phpunit.xml > /dev/null 2>&1 || echo "FIRST TEST FAILED as expected..."
- sudo -u www-data php7.3 /usr/local/bin/phpunit --configuration /var/www/html/nextcloud/apps/maps/phpunit.xml --coverage-text --color=never --coverage-html /builds/eneiluj/maps/coverage

test_nc17_pgsql:
stage: test
Expand All @@ -62,9 +63,9 @@ test_nc17_pgsql:
variables:
POSTGRES_DB: plop
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ""
POSTGRES_PASSWORD: "toto"
script:
- DEBIAN_FRONTEND=noninteractive apt-get install php7.2-pgsql postgresql-client -yqq > /dev/null 2>&1
- DEBIAN_FRONTEND=noninteractive apt-get install php7.3-pgsql postgresql-client -yqq > /dev/null 2>&1
# copy local copy that has been cloned already
- cp -r . /tmp/maps
- mkdir -p /var/www/html ; pushd /var/www/html
Expand All @@ -73,7 +74,7 @@ test_nc17_pgsql:
- sed -i $'s|if (substr($fullPath, 0, strlen($root) + 1) === $root . \'/\')|if (is_string($root) and substr($fullPath, 0, strlen($root) + 1) === $root . \'/\')|g' nextcloud/lib/autoloader.php
- pushd nextcloud/apps && mv /tmp/maps ./
- cd maps ; make ; cd .. && chown -R www-data:www-data /var/www/html/nextcloud
- sudo -u www-data php /var/www/html/nextcloud/occ maintenance:install --database "pgsql" --database-host "postgres:5432" --database-name oc_autotest --database-user postgres --database-pass="" --admin-user "admin" --admin-pass "password" --data-dir /var/www/html/nextcloud/data
- sudo -u www-data php /var/www/html/nextcloud/occ maintenance:install --database "pgsql" --database-host "postgres:5432" --database-name oc_autotest --database-user postgres --database-pass="toto" --admin-user "admin" --admin-pass "password" --data-dir /var/www/html/nextcloud/data
- sudo -u www-data OC_PASS=newpassword php /var/www/html/nextcloud/occ user:add --password-from-env --display-name="Test 1" --group="users" test
- sudo -u www-data OC_PASS=newpassword php /var/www/html/nextcloud/occ user:add --password-from-env --display-name="Test 2" --group="users" test2
- sudo -u www-data OC_PASS=newpassword php /var/www/html/nextcloud/occ user:add --password-from-env --display-name="Test 3" --group="users" test3
Expand All @@ -84,8 +85,8 @@ test_nc17_pgsql:
# check JS code
- jshint --verbose maps/js/script.js && echo "jshint OK" || echo "jshint has complaints"
- cd /var/www/html/nextcloud/apps/maps
- sudo -u www-data php7.2 /usr/local/bin/phpunit --configuration /var/www/html/nextcloud/apps/maps/phpunit.xml > /dev/null 2>&1 || echo "FIRST TEST FAILED as expected..."
- sudo -u www-data php7.2 /usr/local/bin/phpunit --configuration /var/www/html/nextcloud/apps/maps/phpunit.xml --coverage-text --color=never
- sudo -u www-data php7.3 /usr/local/bin/phpunit --configuration /var/www/html/nextcloud/apps/maps/phpunit.xml > /dev/null 2>&1 || echo "FIRST TEST FAILED as expected..."
- sudo -u www-data php7.3 /usr/local/bin/phpunit --configuration /var/www/html/nextcloud/apps/maps/phpunit.xml --coverage-text --color=never

test_nc17_mysql:
stage: test
Expand All @@ -95,7 +96,7 @@ test_nc17_mysql:
- test
script:
# DB
- DEBIAN_FRONTEND=noninteractive apt-get install mariadb-server php7.2-mysql -yqq > /dev/null 2>&1
- DEBIAN_FRONTEND=noninteractive apt-get install mariadb-server php7.3-mysql -yqq > /dev/null 2>&1
- service mysql start
- mysql -u root -e 'create database oc_autotest;'
- mysql -u root -e "CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY '';"
Expand All @@ -119,8 +120,8 @@ test_nc17_mysql:
# check JS code
- jshint --verbose maps/js/script.js && echo "jshint OK" || echo "jshint has complaints"
- cd /var/www/html/nextcloud/apps/maps
- sudo -u www-data php7.2 /usr/local/bin/phpunit --configuration /var/www/html/nextcloud/apps/maps/phpunit.xml > /dev/null 2>&1 || echo "FIRST TEST FAILED as expected..."
- sudo -u www-data php7.2 /usr/local/bin/phpunit --configuration /var/www/html/nextcloud/apps/maps/phpunit.xml --coverage-text --color=never
- sudo -u www-data php7.3 /usr/local/bin/phpunit --configuration /var/www/html/nextcloud/apps/maps/phpunit.xml > /dev/null 2>&1 || echo "FIRST TEST FAILED as expected..."
- sudo -u www-data php7.3 /usr/local/bin/phpunit --configuration /var/www/html/nextcloud/apps/maps/phpunit.xml --coverage-text --color=never


pages:
Expand Down
204 changes: 0 additions & 204 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,9 @@


use OCA\Maps\DB\FavoriteShareMapper;
use OCA\Maps\Controller\PublicFavoritesApiController;
use \OCP\AppFramework\App;
use OCA\Maps\Controller\UtilsController;
use OCA\Maps\Controller\FavoritesController;
use OCA\Maps\Controller\FavoritesApiController;
use OCA\Maps\Controller\DevicesController;
use OCA\Maps\Controller\PublicPageController;
use OCA\Maps\Controller\DevicesApiController;
use OCA\Maps\Controller\RoutingController;
use OCA\Maps\Controller\TracksController;
use OCA\Maps\Hooks\FileHooks;
use OCA\Maps\Service\PhotofilesService;
use OCA\Maps\Service\FavoritesService;
use OCA\Maps\Service\DevicesService;
use OCA\Maps\Service\TracksService;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

Expand All @@ -50,199 +39,6 @@ public function __construct (array $urlParams=array()) {

$this->getContainer()->query('FileHooks')->register();

$container->registerService(
'FavoritesController', function ($c) {
return new FavoritesController(
$c->query('AppName'),
$c->query('Request'),
$c->query('UserId'),
$c->query('ServerContainer')->getUserFolder($c->query('UserId')),
$c->query('ServerContainer')->getConfig(),
$c->getServer()->getShareManager(),
$c->getServer()->getAppManager(),
$c->getServer()->getUserManager(),
$c->getServer()->getGroupManager(),
$c->query('ServerContainer')->getL10N($c->query('AppName')),
$c->query('ServerContainer')->getLogger(),
new FavoritesService(
$c->query('ServerContainer')->getLogger(),
$c->query('ServerContainer')->getL10N($c->query('AppName')),
$c->query('ServerContainer')->getSecureRandom(),
$c->query(\OCP\IDBConnection::class)
),
$c->query('ServerContainer')->getDateTimeZone(),
new FavoriteShareMapper(
$c->query(\OCP\IDBConnection::class),
$c->query('ServerContainer')->getSecureRandom()
)
);
}
);

$container->registerService(
'FavoritesApiController', function ($c) {
return new FavoritesApiController(
$c->query('AppName'),
$c->query('Request'),
$c->query('UserId'),
$c->query('ServerContainer')->getUserFolder($c->query('UserId')),
$c->query('ServerContainer')->getConfig(),
$c->getServer()->getShareManager(),
$c->getServer()->getAppManager(),
$c->getServer()->getUserManager(),
$c->getServer()->getGroupManager(),
$c->query('ServerContainer')->getL10N($c->query('AppName')),
$c->query('ServerContainer')->getLogger(),
new FavoritesService(
$c->query('ServerContainer')->getLogger(),
$c->query('ServerContainer')->getL10N($c->query('AppName')),
$c->query('ServerContainer')->getSecureRandom(),
$c->query(\OCP\IDBConnection::class)
)
);
}
);

$container->registerService(
'PublicFavoritesAPIController', function ($c) {
return new PublicFavoritesApiController(
$c->query('AppName'),
$c->query('Request'),
$c->query('Session'),
new FavoritesService(
$c->query('ServerContainer')->getLogger(),
$c->query('ServerContainer')->getL10N($c->query('AppName')),
$c->query('ServerContainer')->getSecureRandom(),
$c->query(\OCP\IDBConnection::class)
),
new FavoriteShareMapper(
$c->query(\OCP\IDBConnection::class),
$c->query('ServerContainer')->getSecureRandom()
)
);
}
);

$container->registerService(
'PublicPageController', function ($c) {
return new PublicPageController(
$c->query('AppName'),
$c->query('Request'),
$c->query('Session'),
$c->query('ServerContainer')->getConfig(),
$c->query('Logger'),
new FavoriteShareMapper(
$c->query(\OCP\IDBConnection::class),
$c->query('ServerContainer')->getSecureRandom()
)
);
}
);

$container->registerService(
'DevicesController', function ($c) {
return new DevicesController(
$c->query('AppName'),
$c->query('Request'),
$c->query('UserId'),
$c->query('ServerContainer')->getUserFolder($c->query('UserId')),
$c->query('ServerContainer')->getConfig(),
$c->getServer()->getShareManager(),
$c->getServer()->getAppManager(),
$c->getServer()->getUserManager(),
$c->getServer()->getGroupManager(),
$c->query('ServerContainer')->getL10N($c->query('AppName')),
$c->query('ServerContainer')->getLogger(),
new DevicesService(
$c->query('ServerContainer')->getLogger(),
$c->query('ServerContainer')->getL10N($c->query('AppName')),
$c->query(\OCP\IDBConnection::class)
),
$c->query('ServerContainer')->getDateTimeZone()
);
}
);

$container->registerService(
'DevicesApiController', function ($c) {
return new DevicesApiController(
$c->query('AppName'),
$c->query('Request'),
$c->query('UserId'),
$c->query('ServerContainer')->getUserFolder($c->query('UserId')),
$c->query('ServerContainer')->getConfig(),
$c->getServer()->getShareManager(),
$c->getServer()->getAppManager(),
$c->getServer()->getUserManager(),
$c->getServer()->getGroupManager(),
$c->query('ServerContainer')->getL10N($c->query('AppName')),
$c->query('ServerContainer')->getLogger(),
new DevicesService(
$c->query('ServerContainer')->getLogger(),
$c->query('ServerContainer')->getL10N($c->query('AppName')),
$c->query(\OCP\IDBConnection::class)
)
);
}
);

$container->registerService(
'RoutingController', function ($c) {
return new RoutingController(
$c->query('AppName'),
$c->query('Request'),
$c->query('UserId'),
$c->query('ServerContainer')->getUserFolder($c->query('UserId')),
$c->query('ServerContainer')->getConfig(),
$c->getServer()->getShareManager(),
$c->getServer()->getAppManager(),
$c->getServer()->getUserManager(),
$c->getServer()->getGroupManager(),
$c->query('ServerContainer')->getL10N($c->query('AppName')),
$c->query('ServerContainer')->getLogger(),
$c->query('ServerContainer')->getDateTimeZone()
);
}
);

$container->registerService(
'TracksController', function ($c) {
return new TracksController(
$c->query('AppName'),
$c->query('Request'),
$c->query('UserId'),
$c->query('ServerContainer')->getUserFolder($c->query('UserId')),
$c->query('ServerContainer')->getConfig(),
$c->getServer()->getShareManager(),
$c->getServer()->getAppManager(),
$c->getServer()->getUserManager(),
$c->getServer()->getGroupManager(),
$c->query('ServerContainer')->getL10N($c->query('AppName')),
$c->query('ServerContainer')->getLogger(),
new TracksService(
$c->query('ServerContainer')->getLogger(),
$c->query('ServerContainer')->getL10N($c->query('AppName')),
$c->query('ServerContainer')->getRootFolder(),
$c->getServer()->getShareManager(),
$c->query(\OCP\IDBConnection::class)
)
);
}
);

$container->registerService(
'UtilsController', function ($c) {
return new UtilsController(
$c->query('AppName'),
$c->query('Request'),
$c->query('UserId'),
$c->query('ServerContainer')->getUserFolder($c->query('UserId')),
$c->query('ServerContainer')->getConfig(),
$c->getServer()->getAppManager()
);
}
);

$this->registerFeaturePolicy();
}

Expand Down
25 changes: 19 additions & 6 deletions lib/Controller/DevicesApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
use OCP\AppFramework\ApiController;
use OCP\Constants;
use OCP\Share;
use OCP\IUserManager;
use OCP\Share\IManager;
use OCP\IServerContainer;
use OCP\IGroupManager;
use OCP\ILogger;

use OCA\Maps\Service\DevicesService;

Expand All @@ -49,10 +54,18 @@ class DevicesApiController extends ApiController {
private $devicesService;
protected $appName;

public function __construct($AppName, IRequest $request, $UserId,
$userfolder, $config, $shareManager,
IAppManager $appManager, $userManager,
$groupManager, IL10N $trans, $logger, DevicesService $devicesService){
public function __construct($AppName,
IRequest $request,
IServerContainer $serverContainer,
IConfig $config,
IManager $shareManager,
IAppManager $appManager,
IUserManager $userManager,
IGroupManager $groupManager,
IL10N $trans,
ILogger $logger,
DevicesService $devicesService,
$UserId){
parent::__construct($AppName, $request,
'PUT, POST, GET, DELETE, PATCH, OPTIONS',
'Authorization, Content-Type, Accept',
Expand All @@ -68,9 +81,9 @@ public function __construct($AppName, IRequest $request, $UserId,
$this->dbtype = $config->getSystemValue('dbtype');
// IConfig object
$this->config = $config;
if ($UserId !== '' and $userfolder !== null){
if ($UserId !== '' and $UserId !== null and $serverContainer !== null){
// path of user files folder relative to DATA folder
$this->userfolder = $userfolder;
$this->userfolder = $serverContainer->getUserFolder($UserId);
}
$this->shareManager = $shareManager;
}
Expand Down
27 changes: 20 additions & 7 deletions lib/Controller/DevicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
use OCP\AppFramework\ApiController;
use OCP\Constants;
use OCP\Share;
use OCP\IUserManager;
use OCP\Share\IManager;
use OCP\IServerContainer;
use OCP\IGroupManager;
use OCP\ILogger;

use OCP\IDateTimeZone;

Expand All @@ -54,11 +59,19 @@ class DevicesController extends Controller {
private $dateTimeZone;
protected $appName;

public function __construct($AppName, IRequest $request, $UserId,
$userfolder, $config, $shareManager,
IAppManager $appManager, $userManager,
$groupManager, IL10N $trans, $logger, DevicesService $devicesService,
IDateTimeZone $dateTimeZone){
public function __construct($AppName,
IRequest $request,
IServerContainer $serverContainer,
IConfig $config,
IManager $shareManager,
IAppManager $appManager,
IUserManager $userManager,
IGroupManager $groupManager,
IL10N $trans,
ILogger $logger,
DevicesService $devicesService,
IDateTimeZone $dateTimeZone,
$UserId){
parent::__construct($AppName, $request);
$this->devicesService = $devicesService;
$this->dateTimeZone = $dateTimeZone;
Expand All @@ -72,9 +85,9 @@ public function __construct($AppName, IRequest $request, $UserId,
$this->dbtype = $config->getSystemValue('dbtype');
// IConfig object
$this->config = $config;
if ($UserId !== '' and $userfolder !== null){
if ($UserId !== '' and $UserId !== null and $serverContainer !== null){
// path of user files folder relative to DATA folder
$this->userfolder = $userfolder;
$this->userfolder = $serverContainer->getUserFolder($UserId);
}
$this->shareManager = $shareManager;
}
Expand Down
Loading

0 comments on commit ce5ec9e

Please sign in to comment.