From c1182832050e1161e555ea6b65455428d0d8c9c1 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Fri, 19 Nov 2021 11:16:15 -0300 Subject: [PATCH] Dirty fix to allow syncing from Wikis that remoteuser has no "[root]" access Please see https://github.com/splitbrain/dokuwiki-plugin-sync/issues/56 --- admin.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/admin.php b/admin.php index 0d3f843..ee7f9cf 100644 --- a/admin.php +++ b/admin.php @@ -653,16 +653,45 @@ function _getSyncList($type='pages'){ array('depth' => (int) $this->profiles[$no]['depth'], 'hash' => true)); }else{ - $ok = $this->client->query('wiki.getAttachments',$ns, + if(!empty($ns)){ + $ok = $this->client->query('wiki.getAttachments',$ns, + array('depth' => (int) $this->profiles[$no]['depth'], + 'hash' => true)); + }else{ + $ok = $this->client->query('dokuwiki.getPagelist',$ns, array('depth' => (int) $this->profiles[$no]['depth'], 'hash' => true)); + if($ok){ + $remotepages = $this->client->getResponse(); + foreach ($remotepages as $item) { + if((int) $this->profiles[$no]['depth'] == 0 && strpos($item['id'],':')) continue; + // echo "Trying to sync: " . $item['id']; + $ok = $this->client->query('wiki.getAttachments',$item['id'], + array('depth' => ((int) $this->profiles[$no]['depth'] > 0 ? 1 : 0), + 'hash' => true)); + if($ok){ + if(!isset($remote)) $remote = array(); + $remote = array_merge($remote, $this->client->getResponse()); + }else{ + if(strpos($this->client->getErrorMessage(), '403')) { + // 'remoteuser' has access to the page, but receives a 403 Forbidden + // Probably Media namespace is empty or doesn't exists + $ok = true; + }else{ + // echo " [FAIL]"; + break; + } + } + } + } + } } if(!$ok){ msg('Failed to fetch remote file list. '. $this->client->getErrorMessage(),-1); return false; } - $remote = $this->client->getResponse(); + if(!isset($remote)) $remote = $this->client->getResponse(); // put into synclist foreach($remote as $item){ $list[$item['id']]['remote'] = $item;