Skip to content

Commit

Permalink
Updates for Nextcloud 14
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 17, 2018
1 parent 8a98485 commit f8da882
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 39 deletions.
7 changes: 4 additions & 3 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace OCA\OwnNote\AppInfo;

use \OCP\IURLGenerator;

\OCP\App::registerAdmin('ownnote', 'admin');

\OC::$server->getNavigationManager()->add(array(
Expand All @@ -22,14 +24,13 @@
'order' => 10,

// the route that will be shown on startup
'href' => \OCP\Util::linkToRoute('ownnote.page.index'),
'href' => \OC::$server->getURLGenerator()->linkToRoute('ownnote.page.index'),

// the icon that will be shown in the navigation
// this file needs to exist in img/
'icon' => \OCP\Util::imagePath('ownnote', 'app.svg'),
'icon' => \OC::$server->getURLGenerator()->imagePath('ownnote', 'app.svg'),

// the title of your application. This will be used in the
// navigation or on the settings page of your app
//'name' => \OC_L10N::get('ownnote')->t('Own Note')
'name' => \OCP\Util::getL10N('ownnote')->t('Notes')
));
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<dependencies>
<lib>curl</lib>
<owncloud min-version="7.0.3" max-version="9.2" />
<nextcloud min-version="9.1" max-version="14" />
<nextcloud min-version="9.1" max-version="15" />
</dependencies>
</info>
7 changes: 7 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#app, #ownnote, #controls, #createform {
width: 100%;
}

.listing {
height: 40pt;
Expand Down Expand Up @@ -74,6 +77,10 @@
width: 60%;
}

.button {
display: inline-block;
}

.buttons {
float: right;
width: 40%;
Expand Down
76 changes: 41 additions & 35 deletions lib/backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

class Backend {

private $db;

public function __construct() {
$this->db = \OC::$server->getDatabaseConnection();
}

public function startsWith($haystack, $needle) {
return $needle === "" || strripos($haystack, $needle, -strlen($haystack)) !== FALSE;
}
Expand Down Expand Up @@ -131,8 +137,8 @@ public function getListing($FOLDER, $showdel) {
// Get the listing from the database
$requery = false;
$uid = \OCP\User::getUser();
$query = \OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name");
$results = $query->execute(Array($uid))->fetchAll();
$query = "SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name";
$results = $this->db->executeQuery($query, Array($uid))->fetchAll();
$results2 = $results;
if ($results)
foreach($results as $result)
Expand All @@ -153,14 +159,14 @@ public function getListing($FOLDER, $showdel) {
$delid = $result['id'];
}
if ($delid != -1) {
$delquery = \OCP\DB::prepare("DELETE FROM *PREFIX*ownnote WHERE id=?");
$delquery->execute(Array($delid));
$delquery = "DELETE FROM *PREFIX*ownnote WHERE id=?";
$this->db->executeQuery($delquery, Array($delid));
$requery = true;
}
}
if ($requery) {
$query = \OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name");
$results = $query->execute(Array($uid))->fetchAll();
$query = "SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name";
$results = $this->db->executeQuery($query, Array($uid))->fetchAll();
$requery = false;
}
// Tests to add a bunch of notes
Expand Down Expand Up @@ -242,8 +248,8 @@ public function getListing($FOLDER, $showdel) {
}
}
if ($requery) {
$query = \OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name");
$results = $query->execute(Array($uid))->fetchAll();
$query = "SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name";
$results = $this->db->executeQuery($query, Array($uid))->fetchAll();
}
// Now also make sure the files exist, they may not if the user switched folders in admin.
if ($results)
Expand Down Expand Up @@ -298,8 +304,8 @@ public function createNote($FOLDER, $in_name, $in_group) {
$fileindb = false;
$filedeldb = false;
$ret = -1;
$query = \OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?");
$results = $query->execute(Array($uid, $name, $group))->fetchAll();
$query = "SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?";
$results = $this->db->executeQuery($query, Array($uid, $name, $group))->fetchAll();
foreach($results as $result)
if ($result['deleted'] == 0) {
$fileindb = true;
Expand All @@ -308,8 +314,8 @@ public function createNote($FOLDER, $in_name, $in_group) {
$filedeldb = true;
}
if ($filedeldb) {
$query = \OCP\DB::prepare("DELETE FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?");
$results = $query->execute(Array($uid, $name, $group));
$query = "DELETE FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?";
$results = $this->db->executeQuery($query, Array($uid, $name, $group));
}
if (! $fileindb) {
if ($FOLDER != '') {
Expand All @@ -323,9 +329,9 @@ public function createNote($FOLDER, $in_name, $in_group) {
$mtime = $info['mtime'];
}
}
$query = \OCP\DB::prepare("INSERT INTO *PREFIX*ownnote (uid, name, grouping, mtime, note, shared) VALUES (?,?,?,?,?,?)");
$query->execute(Array($uid,$name,$group,$mtime,'',''));
$ret = \OCP\DB::insertid('*PREFIX*ownnote');
$query = "INSERT INTO *PREFIX*ownnote (uid, name, grouping, mtime, note, shared) VALUES (?,?,?,?,?,?)";
$this->db->executeQuery($query, Array($uid,$name,$group,$mtime,'',''));
$ret = $this->db->lastInsertId('*PREFIX*ownnote');
}
return $ret;
}
Expand All @@ -335,13 +341,13 @@ public function deleteNote($FOLDER, $name, $group) {
$now = new DateTime();
$mtime = $now->getTimestamp();
$uid = \OCP\User::getUser();
$query = \OCP\DB::prepare("UPDATE *PREFIX*ownnote set note='', deleted=1, mtime=? WHERE uid=? and name=? and grouping=?");
$results = $query->execute(Array($mtime, $uid, $name, $group));
$query = \OCP\DB::prepare("SELECT id FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?");
$results = $query->execute(Array($uid, $name, $group))->fetchAll();
$query = "UPDATE *PREFIX*ownnote set note='', deleted=1, mtime=? WHERE uid=? and name=? and grouping=?";
$results = $this->db->executeQuery($query, Array($mtime, $uid, $name, $group));
$query = "SELECT id FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?";
$results = $this->db->executeQuery($query, Array($uid, $name, $group))->fetchAll();
foreach($results as $result) {
$query2 = \OCP\DB::prepare("DELETE FROM *PREFIX*ownnote_parts WHERE id=?");
$results2 = $query2->execute(Array($result['id']));
$query2 = "DELETE FROM *PREFIX*ownnote_parts WHERE id=?";
$results2 = $this->db->executeQuery($query2, Array($result['id']));
}
if ($FOLDER != '') {
$tmpfile = $FOLDER."/".$name.".htm";
Expand All @@ -357,13 +363,13 @@ public function deleteNote($FOLDER, $name, $group) {
public function editNote($name, $group) {
$ret = "";
$uid = \OCP\User::getUser();
$query = \OCP\DB::prepare("SELECT id,note FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?");
$results = $query->execute(Array($uid, $name, $group))->fetchAll();
$query = "SELECT id,note FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?";
$results = $this->db->executeQuery($query, Array($uid, $name, $group))->fetchAll();
foreach($results as $result) {
$ret = $result['note'];
if ($ret == '') {
$query2 = \OCP\DB::prepare("SELECT note FROM *PREFIX*ownnote_parts WHERE id=? order by pid");
$results2 = $query2->execute(Array($result['id']))->fetchAll();
$query2 = "SELECT note FROM *PREFIX*ownnote_parts WHERE id=? order by pid";
$results2 = $this->db->executeQuery($query2, Array($result['id']))->fetchAll();
foreach($results2 as $result2) {
$ret .= $result2['note'];
}
Expand Down Expand Up @@ -391,14 +397,14 @@ public function saveNote($FOLDER, $name, $group, $content, $in_mtime) {
$mtime = $info['mtime'];
}
}
$query = \OCP\DB::prepare("UPDATE *PREFIX*ownnote set note='', mtime=? WHERE uid=? and name=? and grouping=?");
$results = $query->execute(Array($mtime, $uid, $name, $group));
$query = \OCP\DB::prepare("DELETE FROM *PREFIX*ownnote_parts WHERE id=?");
$results = $query->execute(Array($id));
$query = "UPDATE *PREFIX*ownnote set note='', mtime=? WHERE uid=? and name=? and grouping=?";
$results = $this->db->executeQuery($query, Array($mtime, $uid, $name, $group));
$query = "DELETE FROM *PREFIX*ownnote_parts WHERE id=?";
$results = $this->db->executeQuery($query, Array($id));
$contentarr = $this->splitContent($content);
for ($i = 0; $i < count($contentarr); $i++) {
$query = \OCP\DB::prepare("INSERT INTO *PREFIX*ownnote_parts (id, note) values (?,?)");
$results = $query->execute(Array($id, $contentarr[$i]));
$query = "INSERT INTO *PREFIX*ownnote_parts (id, note) values (?,?)";
$results = $this->db->executeQuery($query, Array($id, $contentarr[$i]));
}

}
Expand All @@ -420,8 +426,8 @@ public function renameNote($FOLDER, $name, $group, $in_newname, $in_newgroup) {
public function deleteGroup($FOLDER, $group) {
// We actually need to just rename all the notes
$uid = \OCP\User::getUser();
$query = \OCP\DB::prepare("SELECT id, name, grouping, mtime FROM *PREFIX*ownnote WHERE deleted=0 and uid=? and grouping=?");
$results = $query->execute(Array($uid, $group))->fetchAll();
$query = "SELECT id, name, grouping, mtime FROM *PREFIX*ownnote WHERE deleted=0 and uid=? and grouping=?";
$results = $this->db->executeQuery($query, Array($uid, $group))->fetchAll();
foreach($results as $result) {
$this->renameNote($FOLDER, $result['name'], $group, $result['name'], '');
}
Expand All @@ -430,8 +436,8 @@ public function deleteGroup($FOLDER, $group) {

public function renameGroup($FOLDER, $group, $newgroup) {
$uid = \OCP\User::getUser();
$query = \OCP\DB::prepare("SELECT id, name, grouping, mtime FROM *PREFIX*ownnote WHERE deleted=0 and uid=? and grouping=?");
$results = $query->execute(Array($uid, $group))->fetchAll();
$query = "SELECT id, name, grouping, mtime FROM *PREFIX*ownnote WHERE deleted=0 and uid=? and grouping=?";
$results = $this->db->executeQuery($query, Array($uid, $group))->fetchAll();
foreach($results as $result) {
$this->renameNote($FOLDER, $result['name'], $group, $result['name'], $newgroup);
}
Expand Down

0 comments on commit f8da882

Please sign in to comment.