diff --git a/lib/backend.php b/lib/backend.php index 8ba07dd..bc1e6c3 100644 --- a/lib/backend.php +++ b/lib/backend.php @@ -43,13 +43,10 @@ public function getAnnouncement() { public function checkEvernote($folder, $file) { $html = ""; -error_log("*** 1"); if ($html = \OC\Files\Filesystem::file_get_contents($folder."/".$file)) { $DOM = new DOMDocument; -error_log("*** 2"); $DOM->loadHTML($html); $items = $DOM->getElementsByTagName('meta'); -error_log("*** 3"); $isEvernote = false; for ($i = 0; $i < $items->length; $i++) { $item = $items->item($i); @@ -65,11 +62,9 @@ public function checkEvernote($folder, $file) { } } } -error_log("*** 4"); if ($isEvernote) { $items = $DOM->getElementsByTagName('img'); $isEvernote = false; -error_log("*** 5"); for ($i = 0; $i < $items->length; $i++) { $item = $items->item($i); if ($item->hasAttributes()) { @@ -79,7 +74,6 @@ public function checkEvernote($folder, $file) { $url = $attr->value; if (!$this->startsWith($url, "http") && !$this->startsWith($url, "/") && !$this->startsWith($url,"data")) { if ($data = \OC\Files\Filesystem::file_get_contents($folder."/".$url)) { -error_log("*** 6"); $type = pathinfo($url, PATHINFO_EXTENSION); $base64 = "data:image/".$type.";base64,".base64_encode($data); $html = str_replace($url, $base64, $html); @@ -89,13 +83,9 @@ public function checkEvernote($folder, $file) { } } } -error_log("*** 7"); \OC\Files\Filesystem::file_put_contents($folder."/".$file, $html); -error_log("*** 8"); } -error_log("*** 9"); } -error_log("*** 10"); } public function getTimeString($filetime, $now) { @@ -139,7 +129,6 @@ public function splitContent($str) { public function getListing($FOLDER, $showdel) { // Get the listing from the database -error_log('Y'); $requery = false; $uid = \OCP\User::getUser(); $query = \OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name"); @@ -178,32 +167,20 @@ public function getListing($FOLDER, $showdel) { } // Synchronize files to the database $filearr = array(); -error_log('Z'); if ($listing = \OC\Files\Filesystem::opendir($FOLDER)) { -error_log('A'); if (!$listing) { echo "ERROR: Error listing directory."; exit; } -error_log('B'); while (($file = readdir($listing)) !== false) { -error_log('C'); $tmpfile = $file; if ($tmpfile == "." || $tmpfile == "..") continue; if (!$this->endsWith($tmpfile, ".htm") && !$this->endsWith($tmpfile, ".html")) continue; -error_log('D'); if ($info = \OC\Files\Filesystem::getFileInfo($FOLDER."/".$tmpfile)) { -error_log('E'); - // Check for EVERNOTE imports and rename them + // Check for EVERNOTE but wait to rename them to get around: + // https://github.com/owncloud/core/issues/16202 if ($this->endsWith($tmpfile, ".html")) { $this->checkEvernote($FOLDER, $tmpfile); - $tmpfile = substr($tmpfile,0,-1); -error_log('F'); - if (!\OC\Files\Filesystem::file_exists($FOLDER."/".$tmpfile)) { -error_log('G'); - \OC\Files\Filesystem::rename($FOLDER."/".$file, $FOLDER."/".$tmpfile); -error_log('H'); - } } // Separate the name and group name $name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $tmpfile); @@ -226,33 +203,32 @@ public function getListing($FOLDER, $showdel) { // If it is in the DB, check if the filesystem file is newer than the DB if ($result['mtime'] < $info['mtime']) { // File is newer, this could happen if a user updates a file - $query = \OCP\DB::prepare('UPDATE *PREFIX*ownnote set mtime=?, note=? WHERE id=?'); $html = ""; -error_log('H1'); -// We have an error here putting the note into the DB. Needs to go in parts $html = \OC\Files\Filesystem::file_get_contents($FOLDER."/".$tmpfile); -error_log('H2'); - $query->execute(Array($info['mtime'],$html,$result['id'])); + $this->saveNote('', $result['name'], $result['grouping'], $html, $info['mtime']); $requery = true; } } if (! $fileindb) { // If it's not in the DB, add it. $html = ""; -error_log('H3'); -// The other error occurs here. The file has been moved, but it doesn't seem to happen in time. if ($html = \OC\Files\Filesystem::file_get_contents($FOLDER."/".$tmpfile)) { -error_log('H4'); } else { $html = ""; } $this->saveNote('', $name, $group, $html, $info['mtime']); $requery = true; } + // We moved the rename down here to overcome the OC issue + if ($this->endsWith($tmpfile, ".html")) { + $tmpfile = substr($tmpfile,0,-1); + if (!\OC\Files\Filesystem::file_exists($FOLDER."/".$tmpfile)) { + \OC\Files\Filesystem::rename($FOLDER."/".$file, $FOLDER."/".$tmpfile); + } + } } } } -error_log('I'); 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(); @@ -297,7 +273,6 @@ public function getListing($FOLDER, $showdel) { $count++; } } -error_log('J'); return $farray; }