Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Nextcloud 20 #599

Merged
merged 7 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
mysql -u root -proot -e "GRANT ALL ON nextcloud.* TO 'nextcloud'@'localhost';"
- name: Select Nextcloud server branch
if: matrix.version == 'min'
run: echo "::set-env name=SERVER_BRANCH::stable$(php tests/nextcloud-version.php --appinfo)"
run: echo "::set-env name=SERVER_BRANCH::$(php tests/nextcloud-version.php --serverbranch)"
- name: Prepare Nextcloud server using ${{ env.SERVER_BRANCH }}
working-directory: ../
run: |
Expand Down
6 changes: 0 additions & 6 deletions appinfo/app.php

This file was deleted.

2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The Notes app is a distraction free notes taking app for [Nextcloud](https://www
<screenshot small-thumbnail="https://raw.githubusercontent.com/nextcloud/screenshots/master/apps/Notes/notes-thumbnail.jpg">https://raw.githubusercontent.com/nextcloud/screenshots/master/apps/Notes/notes.png</screenshot>
<dependencies>
<php min-version="7.2" max-version="7.4" />
<nextcloud min-version="16" max-version="21" />
<nextcloud min-version="20" max-version="22" />
</dependencies>
<repair-steps>
<post-migration>
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require-dev": {
"christophwurst/nextcloud": "^16.0",
"christophwurst/nextcloud": "^20.0",
"nextcloud/coding-standard": "^0.3.0",
"squizlabs/php_codesniffer": "3.*",
"phan/phan": "^3.0",
Expand All @@ -11,5 +11,7 @@
"psr-4": {
"OCA\\Notes\\Tests\\API\\": "tests/api/"
}
}
},
"minimum-stability": "beta",
"prefer-stable": true
}
27 changes: 27 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace OCA\Notes\AppInfo;

use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IRegistrationContext;

class Application extends App implements IBootstrap {
public const APP_ID = 'notes';
public static $API_VERSIONS = [ '0.2', '1.1' ];

public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
}

public function register(IRegistrationContext $context): void {
$context->registerCapability(Capabilities::class);
}

public function boot(IBootContext $context): void {
$context->getAppContainer()->get(NotesHooks::class)->register();
}
}
6 changes: 3 additions & 3 deletions lib/Capabilities.php → lib/AppInfo/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace OCA\Notes;
namespace OCA\Notes\AppInfo;

use OCP\Capabilities\ICapability;
use OCP\App\IAppManager;
Expand All @@ -18,9 +18,9 @@ public function __construct(IAppManager $appManager) {

public function getCapabilities() {
return [
'notes' => [
Application::APP_ID => [
'api_version' => Application::$API_VERSIONS,
'version' => $this->appManager->getAppVersion('notes'),
'version' => $this->appManager->getAppVersion(Application::APP_ID),
],
];
}
Expand Down
16 changes: 9 additions & 7 deletions lib/NotesHooks.php → lib/AppInfo/NotesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

declare(strict_types=1);

namespace OCA\Notes;
namespace OCA\Notes\AppInfo;

use OCA\Notes\Service\MetaService;

use OCP\ILogger;
use OCP\Files\IRootFolder;
use OCP\Files\Node;

use Psr\Log\LoggerInterface;

class NotesHooks {
private $logger;
private $rootFolder;
private $metaService;

public function __construct(
ILogger $logger,
LoggerInterface $logger,
IRootFolder $rootFolder,
MetaService $metaService
) {
Expand All @@ -31,7 +32,7 @@ public function register() : void {
'\OC\Files',
'preWrite',
function (Node $node) {
// $this->logger->warning('preWrite: ' . $node->getPath(), ['app'=>'notes']);
// $this->logger->debug('preWrite: ' . $node->getPath());
$this->onFileModified($node);
}
);
Expand All @@ -40,7 +41,7 @@ function (Node $node) {
'\OC\Files',
'preTouch',
function (Node $node) {
// $this->logger->warning('preTouch: ' . $node->getPath(), ['app'=>'notes']);
// $this->logger->debug('preTouch: ' . $node->getPath());
$this->onFileModified($node);
}
);
Expand All @@ -49,7 +50,7 @@ function (Node $node) {
'\OC\Files',
'preDelete',
function (Node $node) {
// $this->logger->warning('preDelete: ' . $node->getPath(), ['app'=>'notes']);
// $this->logger->debug('preDelete: ' . $node->getPath());
$this->onFileModified($node);
}
);
Expand All @@ -58,7 +59,7 @@ function (Node $node) {
'\OC\Files',
'preRename',
function (Node $source, Node $target) {
// $this->logger->warning('preRename: ' . $source->getPath(), ['app'=>'notes']);
// $this->logger->debug('preRename: ' . $source->getPath());
$this->onFileModified($source);
}
);
Expand All @@ -70,6 +71,7 @@ private function listenTo($service, string $scope, string $method, callable $cal
}

private function onFileModified(Node $node) : void {
// $this->logger->debug('NotesHook for ' . $node->getPath());
try {
$this->metaService->deleteByNote($node->getId());
} catch (\Throwable $e) {
Expand Down
21 changes: 0 additions & 21 deletions lib/Application.php

This file was deleted.

15 changes: 6 additions & 9 deletions lib/Controller/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,36 @@

namespace OCA\Notes\Controller;

use OCA\Notes\Application;
use OCA\Notes\AppInfo\Application;
use OCA\Notes\Service\Util;

use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\ILogger;
use OCP\IUserSession;

use Psr\Log\LoggerInterface;

class Helper {

/** @var ILogger */
/** @var LoggerInterface */
public $logger;
/** @var string */
private $appName;
/** @var IUserSession */
private $userSession;

public function __construct(
IUserSession $userSession,
ILogger $logger,
string $appName
LoggerInterface $logger
) {
$this->userSession = $userSession;
$this->logger = $logger;
$this->appName = $appName;
}

public function getUID() : string {
return $this->userSession->getUser()->getUID();
}

public function logException(\Throwable $e) : void {
$this->logger->logException($e, ['app' => $this->appName]);
$this->logger->error('Controller failed with '.get_class($e), [ 'exception' => $e ]);
}

public function createErrorResponse(\Throwable $e, int $statusCode) : JSONResponse {
Expand Down
11 changes: 7 additions & 4 deletions lib/Service/MetaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
*/
class MetaService {
private $metaMapper;
private $noteUtil;
private $util;

public function __construct(MetaMapper $metaMapper, NoteUtil $noteUtil) {
public function __construct(MetaMapper $metaMapper, Util $util) {
$this->metaMapper = $metaMapper;
$this->noteUtil = $noteUtil;
$this->util = $util;
}

public function deleteByNote(int $id) : void {
Expand Down Expand Up @@ -162,7 +162,10 @@ private function generateContentEtag(Note $note) : string {
return md5($note->getContent());
}, 3);
} catch (\Throwable $t) {
$this->noteUtil->logException($t);
$this->util->logger->error(
'Could not generate Content Etag for note '.$note->getId(),
[ 'exception' => $t ]
);
return '';
}
}
Expand Down
11 changes: 9 additions & 2 deletions lib/Service/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
class Note {
private $file;
private $notesFolder;
/** @var NoteUtil */
private $noteUtil;
/** @var Util */
private $util;

public function __construct(File $file, Folder $notesFolder, NoteUtil $noteUtil) {
$this->file = $file;
$this->notesFolder = $notesFolder;
$this->noteUtil = $noteUtil;
$this->util = $noteUtil->util;
}


Expand Down Expand Up @@ -82,8 +86,11 @@ public function getData(array $exclude = []) : array {
try {
$data['content'] = $this->getContent();
} catch (\Throwable $e) {
$this->noteUtil->logException($e);
$message = $this->noteUtil->getL10N()->t('Error').': ('.$this->file->getName().') '.$e->getMessage();
$this->util->logger->error(
'Could not read content for file: '.$this->file->getPath(),
[ 'exception' => $e ]
);
$message = $this->util->l10n->t('Error').': ('.$this->file->getName().') '.$e->getMessage();
$data['content'] = $message;
$data['error'] = true;
$data['errorMessage'] = $message;
Expand Down
38 changes: 9 additions & 29 deletions lib/Service/NoteUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,25 @@
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;

class NoteUtil {
/** @var Util */
public $util;
private $db;
private $l10n;
private $root;
private $tagService;
private $cachedTags;
private $logger;
private $appName;

public function __construct(
Util $util,
IRootFolder $root,
IDBConnection $db,
TagService $tagService,
IL10N $l10n,
ILogger $logger,
string $appName
TagService $tagService
) {
$this->util = $util;
$this->root = $root;
$this->db = $db;
$this->tagService = $tagService;
$this->l10n = $l10n;
$this->logger = $logger;
$this->appName = $appName;
}

public function getRoot() : IRootFolder {
Expand All @@ -43,18 +36,6 @@ public function getTagService() : TagService {
return $this->tagService;
}

public function getL10N() : IL10N {
return $this->l10n;
}

public function getLogger() : ILogger {
return $this->logger;
}

public function logException(\Throwable $e) : void {
$this->logger->logException($e, ['app' => $this->appName]);
}

public function getCategoryFolder(Folder $notesFolder, string $category) {
$path = $notesFolder->getPath();
// sanitise path
Expand Down Expand Up @@ -118,7 +99,7 @@ public function getSafeTitle(string $content) : string {

// ensure that title is not empty
if (empty($title)) {
$title = $this->l10n->t('New note');
$title = $this->util->l10n->t('New note');
}

return $title;
Expand Down Expand Up @@ -173,7 +154,7 @@ public function deleteEmptyFolder(Folder $folder, Folder $notesFolder) : void {
$isEmpty = !count($content);
$isNotesFolder = $folder->getPath()===$notesFolder->getPath();
if ($isEmpty && !$isNotesFolder) {
$this->logger->info('Deleting empty category folder '.$folder->getPath(), ['app' => $this->appName]);
$this->util->logger->debug('Deleting empty category folder '.$folder->getPath());
$parent = $folder->getParent();
$folder->delete();
$this->deleteEmptyFolder($parent, $notesFolder);
Expand All @@ -189,11 +170,10 @@ public function deleteEmptyFolder(Folder $folder, Folder $notesFolder) : void {
public function ensureSufficientStorage(Folder $folder, int $requiredBytes) : void {
$availableBytes = $folder->getFreeSpace();
if ($availableBytes >= 0 && $availableBytes < $requiredBytes) {
$this->logger->error(
$this->util->logger->error(
'Insufficient storage in '.$folder->getPath().': '.
'available are '.$availableBytes.'; '.
'required are '.$requiredBytes,
['app' => $this->appName]
'required are '.$requiredBytes
);
throw new InsufficientStorageException($requiredBytes.' are required in '.$folder->getPath());
}
Expand Down
6 changes: 4 additions & 2 deletions lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace OCA\Notes\Service;

use OCA\Notes\AppInfo\Application;

use OCP\IConfig;
use OCP\IL10N;
use OCP\Files\IRootFolder;
Expand Down Expand Up @@ -55,11 +57,11 @@ public function set(string $uid, array $settings) : void {
unset($settings[$name]);
}
}
$this->config->setUserValue($uid, 'notes', 'settings', json_encode($settings));
$this->config->setUserValue($uid, Application::APP_ID, 'settings', json_encode($settings));
}

public function getAll(string $uid) : \stdClass {
$settings = json_decode($this->config->getUserValue($uid, 'notes', 'settings'));
$settings = json_decode($this->config->getUserValue($uid, Application::APP_ID, 'settings'));
if (!is_object($settings)) {
$settings = new \stdClass();
}
Expand Down
Loading