2014-05-19 18:39:57 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Files_Sharing\External;
|
|
|
|
|
|
|
|
class Scanner extends \OC\Files\Cache\Scanner {
|
|
|
|
/**
|
|
|
|
* @var \OCA\Files_Sharing\External\Storage
|
|
|
|
*/
|
|
|
|
protected $storage;
|
|
|
|
|
2014-06-12 19:53:56 +04:00
|
|
|
public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1) {
|
|
|
|
$this->scanAll();
|
|
|
|
}
|
|
|
|
|
2014-05-19 18:39:57 +04:00
|
|
|
public function scanAll() {
|
2014-07-01 16:35:44 +04:00
|
|
|
$data = $this->storage->getShareInfo();
|
2014-05-19 18:39:57 +04:00
|
|
|
if ($data['status'] === 'success') {
|
|
|
|
$this->addResult($data['data'], '');
|
|
|
|
} else {
|
|
|
|
throw new \Exception('Error while scanning remote share');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function addResult($data, $path) {
|
2014-08-14 16:50:52 +04:00
|
|
|
$id = $this->cache->put($path, $data);
|
2014-06-16 18:12:32 +04:00
|
|
|
if (isset($data['children'])) {
|
2014-08-14 16:50:52 +04:00
|
|
|
$children = array();
|
2014-05-19 18:39:57 +04:00
|
|
|
foreach ($data['children'] as $child) {
|
2014-08-14 16:50:52 +04:00
|
|
|
$children[$child['name']] = true;
|
2014-05-19 18:39:57 +04:00
|
|
|
$this->addResult($child, ltrim($path . '/' . $child['name'], '/'));
|
|
|
|
}
|
2014-08-14 16:50:52 +04:00
|
|
|
|
|
|
|
$existingCache = $this->cache->getFolderContentsById($id);
|
|
|
|
foreach ($existingCache as $existingChild) {
|
|
|
|
// if an existing child is not in the new data, remove it
|
|
|
|
if (!isset($children[$existingChild['name']])) {
|
|
|
|
$this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/'));
|
|
|
|
}
|
|
|
|
}
|
2014-05-19 18:39:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|