@@ -108,13 +108,31 @@ function getTimeString($filetime, $now) {
108108
109109function getListing ($ FOLDER , $ showdel ) {
110110 // Get the listing from the database
111+ $ requery = false ;
111112 $ uid = \OCP \User::getUser ();
112113 $ query = OCP \DB ::prepare ("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name " );
113114 $ results = $ query ->execute (Array ($ uid ))->fetchAll ();
115+ $ results2 = $ results ;
116+ if ($ results )
117+ foreach ($ results as $ result )
118+ foreach ($ results2 as $ result2 )
119+ if ($ result ['id ' ] != $ result2 ['id ' ] && $ result ['name ' ] == $ result2 ['name ' ] && $ result ['grouping ' ] == $ result2 ['grouping ' ] && $ result ['mtime ' ] == $ result2 ['mtime ' ]) {
120+ // We have a duplicate that should not exist. Need to remove the offending record first
121+ $ delid = $ result ['id ' ];
122+ if ($ result ['id ' ] > $ result2 ['id ' ])
123+ $ delid = $ result2 ['id ' ];
124+ $ delquery = OCP \DB ::prepare ("DELETE FROM *PREFIX*ownnote WHERE id=? " );
125+ $ delquery ->execute (Array ($ delid ));
126+ $ requery = true ;
127+ }
128+ if ($ requery ) {
129+ $ query = OCP \DB ::prepare ("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name " );
130+ $ results = $ query ->execute (Array ($ uid ))->fetchAll ();
131+ $ requery = false ;
132+ }
114133 // Create directory if it doesn't exist
115134 $ farray = array ();
116135 if ($ FOLDER != '' ) {
117- $ requery = false ;
118136 // Create the folder if it doesn't exist
119137 if (!\OC \Files \Filesystem::is_dir ($ FOLDER )) {
120138 if (!\OC \Files \Filesystem::mkdir ($ FOLDER )) {
@@ -298,6 +316,18 @@ function saveNote($FOLDER, $name, $group, $content) {
298316 $ now = new DateTime ();
299317 $ mtime = $ now ->getTimestamp ();
300318 $ uid = \OCP \User::getUser ();
319+ // First check to see if we're creating a new note, createNote handles all of this
320+ createNote ($ FOLDER , $ name , $ group );
321+ //$query = OCP\DB::prepare("SELECT note FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?");
322+ //$results = $query->execute(Array($uid, $name, $group))->fetchAll();
323+ //$indb = false;
324+ //$deldb = false;
325+ //foreach($results as $result) {
326+ //$indb = true;
327+ //if ($result['deleted'] == 1)
328+ //$deldb = true;
329+ //}AAA
330+ // Then save
301331 if ($ FOLDER != '' ) {
302332 $ tmpfile = $ FOLDER ."/ " .$ name .".htm " ;
303333 if ($ group != '' )
@@ -315,9 +345,9 @@ function saveNote($FOLDER, $name, $group, $content) {
315345function renameNote ($ FOLDER , $ name , $ group , $ newname , $ newgroup ) {
316346 // We actually need to delete and create so that the delete flag exists for syncing clients
317347 $ content = editNote ($ name , $ group );
348+ deleteNote ($ FOLDER , $ name , $ group );
318349 createNote ($ FOLDER , $ newname , $ newgroup );
319350 saveNote ($ FOLDER , $ newname , $ newgroup , $ content );
320- deleteNote ($ FOLDER , $ name , $ group );
321351 return "DONE " ;
322352}
323353
0 commit comments