scanner.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OCA\Files_Sharing\External;
  9. class Scanner extends \OC\Files\Cache\Scanner {
  10. /**
  11. * @var \OCA\Files_Sharing\External\Storage
  12. */
  13. protected $storage;
  14. public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1) {
  15. $this->scanAll();
  16. }
  17. public function scanAll() {
  18. $data = $this->storage->getShareInfo();
  19. if ($data['status'] === 'success') {
  20. $this->addResult($data['data'], '');
  21. } else {
  22. throw new \Exception('Error while scanning remote share');
  23. }
  24. }
  25. private function addResult($data, $path) {
  26. $id = $this->cache->put($path, $data);
  27. if (isset($data['children'])) {
  28. $children = array();
  29. foreach ($data['children'] as $child) {
  30. $children[$child['name']] = true;
  31. $this->addResult($child, ltrim($path . '/' . $child['name'], '/'));
  32. }
  33. $existingCache = $this->cache->getFolderContentsById($id);
  34. foreach ($existingCache as $existingChild) {
  35. // if an existing child is not in the new data, remove it
  36. if (!isset($children[$existingChild['name']])) {
  37. $this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/'));
  38. }
  39. }
  40. }
  41. }
  42. }