user = $user ?? Helper::getUID(); $this->path = $path ?? $this->getDefaultPath(); $this->realDir = $realDir ?? Helper::getLocalFolder($this->path); } public function getDefaultPath() { $settings = new Settings($this->user); return $settings->get('ncd_downloader_dir') ?? "/Downloads"; } public static function create($path = null, $user = null) { return new static($path, $user); } public function setUser($user) { $this->user = $user; return $this; } public function setPath($path) { $this->path = $path; return $this; } private function update() { if (!(Helper::folderUpdated($this->realDir))) { return ['message' => "no change"]; } $this->scan(); return ['message' => "changed"]; } //force update public function scan() { $this->logger = \OC::$server->getLogger(); $this->scanner = new Scanner($this->user, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), $this->logger); try { $this->scanner->scan($this->path); return ['status' => 'OK', 'path' => $this->path]; } catch (ForbiddenException $e) { $this->logger->warning("Make sure you're running the scan command only as the user the web server runs as"); } catch (\Exception $e) { $this->logger->warning("Exception during scan: " . $e->getMessage() . $e->getTraceAsString()); } return ['status' => $e->getMessage(), 'path' => $this->path]; } //update only folder is modified public static function sync($path = null, $user = null) { return self::create($path, $user)->update(); } }