Skip to content
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
61 changes: 0 additions & 61 deletions appinfo/database.xml

This file was deleted.

47 changes: 26 additions & 21 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
<?xml version="1.0"?>
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<id>notes</id>
<name>Notes</name>
<summary>Distraction-free notes and writing</summary>
<description><![CDATA[
<id>notes</id>
<name>Notes</name>
<summary>Distraction-free notes and writing</summary>
<description><![CDATA[
The Notes app is a distraction free notes taking app for [Nextcloud](https://www.nextcloud.com/). It provides categories for better organization and supports formatting using [Markdown](https://en.wikipedia.org/wiki/Markdown) syntax. Notes are saved as files in your Nextcloud, so you can view and edit them with every Nextcloud client. Furthermore, a separate [REST API](docs/api/README.md) allows for an easy integration into third-party apps (currently, there are notes apps for [Android](https://github.com/stefan-niedermann/nextcloud-notes), [iOS](https://github.com/owncloud/notes-iOS-App) and the [console](https://git.danielmoch.com/nncli/about) which allow convenient access to your Nextcloud notes). Further features include marking notes as favorites.
]]></description>
<version>3.4.0</version>
<licence>agpl</licence>
<author>Kristof Hamann</author>
<author>Bernhard Posselt</author>
<author>Hendrik Leppelsack</author>
<author>Jan-Christoph Borchardt</author>
<namespace>Notes</namespace>
<category>office</category>
<category>organization</category>
<category>tools</category>
<website>https://github.com/nextcloud/notes</website>
<bugs>https://github.com/nextcloud/notes/issues</bugs>
<repository type="git">https://github.com/nextcloud/notes.git</repository>
<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>
<nextcloud min-version="16" max-version="21" />
</dependencies>
<version>3.5.0-dev</version>
<licence>agpl</licence>
<author>Kristof Hamann</author>
<author>Bernhard Posselt</author>
<author>Hendrik Leppelsack</author>
<author>Jan-Christoph Borchardt</author>
<namespace>Notes</namespace>
<category>office</category>
<category>organization</category>
<category>tools</category>
<website>https://github.com/nextcloud/notes</website>
<bugs>https://github.com/nextcloud/notes/issues</bugs>
<repository type="git">https://github.com/nextcloud/notes.git</repository>
<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>
<nextcloud min-version="16" max-version="21" />
</dependencies>
<repair-steps>
<post-migration>
<step>OCA\Notes\Migration\Cleanup</step>
</post-migration>
</repair-steps>
</info>
9 changes: 9 additions & 0 deletions lib/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public function __construct(array $urlParams = []) {
}

public function register() : void {
$this->registerNavigation();
$this->registerHooks();
}

private function registerNavigation() : void {
$container = $this->getContainer();
$container->registerCapability(Capabilities::class);
$server = $container->getServer();
Expand All @@ -28,4 +33,8 @@ public function register() : void {
];
});
}

public function registerHooks() : void {
$this->getContainer()->query('OCA\\Notes\\NotesHooks')->register();
}
}
2 changes: 1 addition & 1 deletion lib/Controller/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class Helper {

private $logger;
public $logger;
private $appName;

public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/NotesApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public function index(?string $category = null, string $exclude = '', int $prune
$exclude = explode(',', $exclude);
$now = new \DateTime(); // this must be before loading notes if there are concurrent changes possible
$notes = $this->service->getAll($this->getUID())['notes'];
$metas = $this->metaService->updateAll($this->getUID(), $notes);
if ($category !== null) {
$notes = array_values(array_filter($notes, function ($note) use ($category) {
return $note->getCategory() === $category;
}));
}
$metas = $this->metaService->updateAll($this->getUID(), $notes);
$notesData = array_map(function ($note) use ($metas, $pruneBefore, $exclude) {
$lastUpdate = $metas[$note->getId()]->getLastUpdate();
if ($pruneBefore && $lastUpdate<$pruneBefore) {
Expand Down
29 changes: 10 additions & 19 deletions lib/Db/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace OCA\Notes\Db;

use OCA\Notes\Service\Note;

use OCP\AppFramework\Db\Entity;

/**
Expand All @@ -16,25 +14,18 @@
* @method void setLastUpdate(integer $value)
* @method string getEtag()
* @method void setEtag(string $value)
* @method string getContentEtag()
* @method void setContentEtag(string $value)
* @method string getFileEtag()
* @method void setFileEtag(string $value)
* @package OCA\Notes\Db
*/
class Meta extends Entity {

public $userId;
public $fileId;
public $lastUpdate;
public $etag;

/**
* @param Note $note
* @return static
*/
public static function fromNote(Note $note, $userId) : Meta {
$meta = new static();
$meta->setUserId($userId);
$meta->setFileId($note->getId());
$meta->setLastUpdate(time());
$meta->setEtag($note->getEtag());
return $meta;
}
protected $userId;
protected $fileId;
protected $lastUpdate;
protected $etag;
protected $contentEtag;
protected $fileEtag;
}
27 changes: 26 additions & 1 deletion lib/Db/MetaMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,35 @@ public function __construct(IDBConnection $db) {
public function getAll($userId) : array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('*PREFIX*notes_meta')
->from($this->tableName)
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
);
return $this->findEntities($qb);
}

public function findById(string $userId, int $fileId) : Meta {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))
);
return $this->findEntity($qb);
}

public function deleteAll() : void {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)->execute();
}

public function deleteByNote(int $id) : void {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)
->where(
$qb->expr()->eq('file_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
)
->execute();
}
}
31 changes: 31 additions & 0 deletions lib/Migration/Cleanup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types=1);

namespace OCA\Notes\Migration;

use OCA\Notes\Db\MetaMapper;

use OCP\Migration\IRepairStep;
use OCP\Migration\IOutput;

class Cleanup implements IRepairStep {

private $metaMapper;

public function __construct(MetaMapper $metaMapper) {
$this->metaMapper = $metaMapper;
}

/*
* @inheritdoc
*/
public function getName() {
return 'Clean up meta table';
}

/**
* @inheritdoc
*/
public function run(IOutput $output) {
$this->metaMapper->deleteAll();
}
}
44 changes: 44 additions & 0 deletions lib/Migration/Version3005Date20200528204430.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);

namespace OCA\Notes\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version3005Date20200528204430 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if ($schema->hasTable('notes_meta')) {
$schema->dropTable('notes_meta');
}

return $schema;
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
}
}
72 changes: 72 additions & 0 deletions lib/Migration/Version3005Date20200528204431.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php declare(strict_types=1);

namespace OCA\Notes\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version3005Date20200528204431 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->createTable('notes_meta');
$table->addColumn('id', 'integer', [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('file_id', 'integer', [
'notnull' => true,
]);
$table->addColumn('user_id', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('last_update', 'integer', [
'notnull' => true,
]);
$table->addColumn('etag', 'string', [
'notnull' => true,
'length' => 32,
]);
$table->addColumn('content_etag', 'string', [
'notnull' => true,
'length' => 32,
]);
$table->addColumn('file_etag', 'string', [
'notnull' => true,
'length' => 40,
]);
$table->setPrimaryKey(['id']);
$table->addIndex(['file_id'], 'notes_meta_file_id_index');
$table->addIndex(['user_id'], 'notes_meta_user_id_index');
$table->addUniqueIndex(['file_id', 'user_id'], 'notes_meta_file_user_index');

return $schema;
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
}
}
Loading