Skip to content

Commit bb4b0e7

Browse files
committed
Merge pull request #126 from Fmstrat/importfix
Importfix
2 parents 50be600 + ddef3ec commit bb4b0e7

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

lib/backend.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
\OCP\App::checkAppEnabled('ownnote');
77

88
use DateTime;
9+
use DOMDocument;
910

1011
class Backend {
1112

1213
public function startsWith($haystack, $needle) {
13-
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
14+
return $needle === "" || strripos($haystack, $needle, -strlen($haystack)) !== FALSE;
1415
}
1516

16-
public function endswith($string, $test) {
17+
public function endsWith($string, $test) {
1718
$strlen = strlen($string);
1819
$testlen = strlen($test);
1920
if ($testlen > $strlen) return false;
20-
return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0;
21+
return substr_compare($string, $test, $strlen - $testlen, $testlen, true) === 0;
2122
}
2223

2324
public function getAnnouncement() {
@@ -53,7 +54,7 @@ public function checkEvernote($folder, $file) {
5354
$attrs = $item->attributes;
5455
foreach ($attrs as $a => $attr) {
5556
if ($attr->name == "name") {
56-
if ($attr->value == "exporter-version") {
57+
if ($attr->value == "exporter-version" || $attr->value == "Generator") {
5758
$isEvernote = true;
5859
continue;
5960
}
@@ -174,14 +175,12 @@ public function getListing($FOLDER, $showdel) {
174175
while (($file = readdir($listing)) !== false) {
175176
$tmpfile = $file;
176177
if ($tmpfile == "." || $tmpfile == "..") continue;
177-
if (!$this->endswith($tmpfile, ".htm") && !$this->endswith($tmpfile, ".html")) continue;
178+
if (!$this->endsWith($tmpfile, ".htm") && !$this->endsWith($tmpfile, ".html")) continue;
178179
if ($info = \OC\Files\Filesystem::getFileInfo($FOLDER."/".$tmpfile)) {
179-
// Check for EVERNOTE imports and rename them
180-
if ($this->endswith($tmpfile, ".html")) {
180+
// Check for EVERNOTE but wait to rename them to get around:
181+
// https://github.com/owncloud/core/issues/16202
182+
if ($this->endsWith($tmpfile, ".html")) {
181183
$this->checkEvernote($FOLDER, $tmpfile);
182-
$tmpfile = substr($tmpfile,0,-1);
183-
if (!\OC\Files\Filesystem::file_exists($FOLDER."/".$tmpfile))
184-
\OC\Files\Filesystem::rename($FOLDER."/".$file, $FOLDER."/".$tmpfile);
185184
}
186185
// Separate the name and group name
187186
$name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $tmpfile);
@@ -204,10 +203,9 @@ public function getListing($FOLDER, $showdel) {
204203
// If it is in the DB, check if the filesystem file is newer than the DB
205204
if ($result['mtime'] < $info['mtime']) {
206205
// File is newer, this could happen if a user updates a file
207-
$query = \OCP\DB::prepare('UPDATE *PREFIX*ownnote set mtime=?, note=? WHERE id=?');
208206
$html = "";
209207
$html = \OC\Files\Filesystem::file_get_contents($FOLDER."/".$tmpfile);
210-
$query->execute(Array($info['mtime'],$html,$result['id']));
208+
$this->saveNote('', $result['name'], $result['grouping'], $html, $info['mtime']);
211209
$requery = true;
212210
}
213211
}
@@ -221,6 +219,13 @@ public function getListing($FOLDER, $showdel) {
221219
$this->saveNote('', $name, $group, $html, $info['mtime']);
222220
$requery = true;
223221
}
222+
// We moved the rename down here to overcome the OC issue
223+
if ($this->endsWith($tmpfile, ".html")) {
224+
$tmpfile = substr($tmpfile,0,-1);
225+
if (!\OC\Files\Filesystem::file_exists($FOLDER."/".$tmpfile)) {
226+
\OC\Files\Filesystem::rename($FOLDER."/".$file, $FOLDER."/".$tmpfile);
227+
}
228+
}
224229
}
225230
}
226231
}

0 commit comments

Comments
 (0)